mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-27 23:07:14 -05:00
Fix persistence tests, re-introduce separate settings json files, fix call to actual tests to use self. These can now be run with 'xvfb-run pytest tests_gui_local/' instead of via a shell script
This commit is contained in:
parent
297edbe637
commit
7d8a47a53a
@ -20,4 +20,4 @@ before_script:
|
|||||||
# run CLI tests and local GUI tests
|
# run CLI tests and local GUI tests
|
||||||
script:
|
script:
|
||||||
- pytest --cov=onionshare tests/
|
- pytest --cov=onionshare tests/
|
||||||
- cd tests_gui_local/ && xvfb-run ./run_unit_tests.sh
|
- xvfb-run pytest tests_gui_local/
|
||||||
|
@ -19,7 +19,7 @@ from onionshare_gui.mode.receive_mode import ReceiveMode
|
|||||||
|
|
||||||
class GuiBaseTest(object):
|
class GuiBaseTest(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_up(test_settings):
|
def set_up(test_settings, settings_filename):
|
||||||
'''Create GUI with given settings'''
|
'''Create GUI with given settings'''
|
||||||
# Create our test file
|
# Create our test file
|
||||||
testfile = open('/tmp/test.txt', 'w')
|
testfile = open('/tmp/test.txt', 'w')
|
||||||
@ -44,10 +44,9 @@ class GuiBaseTest(object):
|
|||||||
app = OnionShare(common, testonion, True, 0)
|
app = OnionShare(common, testonion, True, 0)
|
||||||
|
|
||||||
web = Web(common, False, True)
|
web = Web(common, False, True)
|
||||||
settings_filename = '/tmp/testsettings.json'
|
open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings))
|
||||||
open(settings_filename, 'w').write(json.dumps(test_settings))
|
|
||||||
|
|
||||||
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True)
|
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], '/tmp/{}.json'.format(settings_filename), True)
|
||||||
return gui
|
return gui
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -24,6 +24,11 @@ class GuiShareTest(GuiBaseTest):
|
|||||||
# We should have timed out now
|
# We should have timed out now
|
||||||
self.assertEqual(mode.server_status.status, 0)
|
self.assertEqual(mode.server_status.status, 0)
|
||||||
|
|
||||||
|
# Persistence tests
|
||||||
|
def have_same_slug(self, slug):
|
||||||
|
'''Test that we have the same slug'''
|
||||||
|
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
|
||||||
|
|
||||||
# Share-specific tests
|
# Share-specific tests
|
||||||
|
|
||||||
def file_selection_widget_has_a_file(self):
|
def file_selection_widget_has_a_file(self):
|
||||||
@ -143,6 +148,15 @@ class GuiShareTest(GuiBaseTest):
|
|||||||
self.run_all_share_mode_download_tests(public_mode, stay_open)
|
self.run_all_share_mode_download_tests(public_mode, stay_open)
|
||||||
|
|
||||||
|
|
||||||
|
def run_all_share_mode_persistent_tests(self, public_mode, stay_open):
|
||||||
|
"""Same as end-to-end share tests but also test the slug is the same on multiple shared"""
|
||||||
|
self.run_all_share_mode_setup_tests()
|
||||||
|
self.run_all_share_mode_started_tests(public_mode)
|
||||||
|
slug = self.gui.share_mode.server_status.web.slug
|
||||||
|
self.run_all_share_mode_download_tests(public_mode, stay_open)
|
||||||
|
self.have_same_slug(slug)
|
||||||
|
|
||||||
|
|
||||||
def run_all_share_mode_timer_tests(self, public_mode):
|
def run_all_share_mode_timer_tests(self, public_mode):
|
||||||
"""Auto-stop timer tests in share mode"""
|
"""Auto-stop timer tests in share mode"""
|
||||||
self.run_all_share_mode_setup_tests()
|
self.run_all_share_mode_setup_tests()
|
||||||
|
@ -11,19 +11,15 @@ class ReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest):
|
|||||||
"public_mode": True,
|
"public_mode": True,
|
||||||
"receive_allow_receiver_shutdown": True
|
"receive_allow_receiver_shutdown": True
|
||||||
}
|
}
|
||||||
cls.gui = GuiReceiveTest.set_up(test_settings)
|
cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModePublicModeTest')
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
GuiReceiveTest.tear_down()
|
|
||||||
|
|
||||||
@pytest.mark.run(order=1)
|
@pytest.mark.run(order=1)
|
||||||
def test_run_all_common_setup_tests(self):
|
def test_run_all_common_setup_tests(self):
|
||||||
GuiReceiveTest.run_all_common_setup_tests(self)
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
@pytest.mark.run(order=2)
|
@pytest.mark.run(order=2)
|
||||||
def test_run_all_receive_mode_tests(self):
|
def test_run_all_receive_mode_tests(self):
|
||||||
GuiReceiveTest.run_all_receive_mode_tests(self, True, True)
|
self.run_all_receive_mode_tests(True, True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -10,19 +10,15 @@ class ReceiveModeTest(unittest.TestCase, GuiReceiveTest):
|
|||||||
test_settings = {
|
test_settings = {
|
||||||
"receive_allow_receiver_shutdown": True
|
"receive_allow_receiver_shutdown": True
|
||||||
}
|
}
|
||||||
cls.gui = GuiReceiveTest.set_up(test_settings)
|
cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModeTest')
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
GuiReceiveTest.tear_down()
|
|
||||||
|
|
||||||
@pytest.mark.run(order=1)
|
@pytest.mark.run(order=1)
|
||||||
def test_run_all_common_setup_tests(self):
|
def test_run_all_common_setup_tests(self):
|
||||||
GuiReceiveTest.run_all_common_setup_tests(self)
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
@pytest.mark.run(order=2)
|
@pytest.mark.run(order=2)
|
||||||
def test_run_all_receive_mode_tests(self):
|
def test_run_all_receive_mode_tests(self):
|
||||||
GuiReceiveTest.run_all_receive_mode_tests(self, False, True)
|
self.run_all_receive_mode_tests(False, True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -10,19 +10,15 @@ class ShareModePublicModeTest(unittest.TestCase, GuiShareTest):
|
|||||||
test_settings = {
|
test_settings = {
|
||||||
"public_mode": True,
|
"public_mode": True,
|
||||||
}
|
}
|
||||||
cls.gui = GuiShareTest.set_up(test_settings)
|
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePublicModeTest')
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
GuiShareTest.tear_down()
|
|
||||||
|
|
||||||
@pytest.mark.run(order=1)
|
@pytest.mark.run(order=1)
|
||||||
def test_run_all_common_setup_tests(self):
|
def test_run_all_common_setup_tests(self):
|
||||||
GuiShareTest.run_all_common_setup_tests(self)
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
@pytest.mark.run(order=2)
|
@pytest.mark.run(order=2)
|
||||||
def test_run_all_share_mode_tests(self):
|
def test_run_all_share_mode_tests(self):
|
||||||
GuiShareTest.run_all_share_mode_tests(self, True, False)
|
self.run_all_share_mode_tests(True, False)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -10,19 +10,15 @@ class ShareModeStayOpenTest(unittest.TestCase, GuiShareTest):
|
|||||||
test_settings = {
|
test_settings = {
|
||||||
"close_after_first_download": False,
|
"close_after_first_download": False,
|
||||||
}
|
}
|
||||||
cls.gui = GuiShareTest.set_up(test_settings)
|
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest')
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
GuiShareTest.tear_down()
|
|
||||||
|
|
||||||
@pytest.mark.run(order=1)
|
@pytest.mark.run(order=1)
|
||||||
def test_run_all_common_setup_tests(self):
|
def test_run_all_common_setup_tests(self):
|
||||||
GuiShareTest.run_all_common_setup_tests(self)
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
@pytest.mark.run(order=2)
|
@pytest.mark.run(order=2)
|
||||||
def test_run_all_share_mode_tests(self):
|
def test_run_all_share_mode_tests(self):
|
||||||
GuiShareTest.run_all_share_mode_tests(self, False, True)
|
self.run_all_share_mode_tests(False, True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -9,19 +9,15 @@ class ShareModeTest(unittest.TestCase, GuiShareTest):
|
|||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
test_settings = {
|
test_settings = {
|
||||||
}
|
}
|
||||||
cls.gui = GuiShareTest.set_up(test_settings)
|
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTest')
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
GuiShareTest.tear_down()
|
|
||||||
|
|
||||||
@pytest.mark.run(order=1)
|
@pytest.mark.run(order=1)
|
||||||
def test_run_all_common_setup_tests(self):
|
def test_run_all_common_setup_tests(self):
|
||||||
GuiShareTest.run_all_common_setup_tests(self)
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
@pytest.mark.run(order=2)
|
@pytest.mark.run(order=2)
|
||||||
def test_run_all_share_mode_tests(self):
|
def test_run_all_share_mode_tests(self):
|
||||||
GuiShareTest.run_all_share_mode_tests(self, False, False)
|
self.run_all_share_mode_tests(False, False)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -13,26 +13,15 @@ class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest):
|
|||||||
"save_private_key": True,
|
"save_private_key": True,
|
||||||
"close_after_first_download": False,
|
"close_after_first_download": False,
|
||||||
}
|
}
|
||||||
cls.gui = GuiShareTest.set_up(test_settings)
|
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest')
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
GuiShareTest.tear_down()
|
|
||||||
|
|
||||||
@pytest.mark.run(order=1)
|
@pytest.mark.run(order=1)
|
||||||
def test_run_all_common_setup_tests(self):
|
def test_run_all_common_setup_tests(self):
|
||||||
GuiShareTest.run_all_common_setup_tests(self)
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
@pytest.mark.run(order=2)
|
@pytest.mark.run(order=2)
|
||||||
def test_run_all_share_mode_tests(self):
|
def test_run_all_share_mode_tests(self):
|
||||||
GuiShareTest.run_all_share_mode_tests(self, False, True)
|
self.run_all_share_mode_persistent_tests(False, True)
|
||||||
global slug
|
|
||||||
slug = self.gui.share_mode.server_status.web.slug
|
|
||||||
|
|
||||||
@pytest.mark.run(order=3)
|
|
||||||
def test_have_same_slug(self):
|
|
||||||
'''Test that we have the same slug'''
|
|
||||||
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -11,19 +11,15 @@ class ShareModeTimerTest(unittest.TestCase, GuiShareTest):
|
|||||||
"public_mode": False,
|
"public_mode": False,
|
||||||
"shutdown_timeout": True,
|
"shutdown_timeout": True,
|
||||||
}
|
}
|
||||||
cls.gui = GuiShareTest.set_up(test_settings)
|
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTimerTest')
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
GuiShareTest.tear_down()
|
|
||||||
|
|
||||||
@pytest.mark.run(order=1)
|
@pytest.mark.run(order=1)
|
||||||
def test_run_all_common_setup_tests(self):
|
def test_run_all_common_setup_tests(self):
|
||||||
GuiShareTest.run_all_common_setup_tests(self)
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
@pytest.mark.run(order=2)
|
@pytest.mark.run(order=2)
|
||||||
def test_run_all_share_mode_timer_tests(self):
|
def test_run_all_share_mode_timer_tests(self):
|
||||||
GuiShareTest.run_all_share_mode_timer_tests(self, False)
|
self.run_all_share_mode_timer_tests(False)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
for test in `ls -1 | egrep ^onionshare_`; do
|
|
||||||
pytest $test -vvv || exit 1
|
|
||||||
done
|
|
Loading…
x
Reference in New Issue
Block a user