From 7d8a47a53a46f6e96eaa5b49c0881c31e8157edf Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 12:18:34 +1100 Subject: [PATCH] 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 --- .travis.yml | 2 +- tests_gui_local/GuiBaseTest.py | 7 +++---- tests_gui_local/GuiShareTest.py | 14 ++++++++++++++ ...hare_receive_mode_upload_public_mode_test.py | 10 +++------- .../onionshare_receive_mode_upload_test.py | 10 +++------- ...hare_share_mode_download_public_mode_test.py | 10 +++------- ...nshare_share_mode_download_stay_open_test.py | 10 +++------- .../onionshare_share_mode_download_test.py | 10 +++------- ...nionshare_share_mode_slug_persistent_test.py | 17 +++-------------- .../onionshare_share_mode_timer_test.py | 10 +++------- tests_gui_local/run_unit_tests.sh | 5 ----- 11 files changed, 39 insertions(+), 66 deletions(-) delete mode 100755 tests_gui_local/run_unit_tests.sh diff --git a/.travis.yml b/.travis.yml index e0b5b822..5750536d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,4 +20,4 @@ before_script: # run CLI tests and local GUI tests script: - pytest --cov=onionshare tests/ - - cd tests_gui_local/ && xvfb-run ./run_unit_tests.sh + - xvfb-run pytest tests_gui_local/ diff --git a/tests_gui_local/GuiBaseTest.py b/tests_gui_local/GuiBaseTest.py index 8a8b127e..138a279a 100644 --- a/tests_gui_local/GuiBaseTest.py +++ b/tests_gui_local/GuiBaseTest.py @@ -19,7 +19,7 @@ from onionshare_gui.mode.receive_mode import ReceiveMode class GuiBaseTest(object): @staticmethod - def set_up(test_settings): + def set_up(test_settings, settings_filename): '''Create GUI with given settings''' # Create our test file testfile = open('/tmp/test.txt', 'w') @@ -44,10 +44,9 @@ class GuiBaseTest(object): app = OnionShare(common, testonion, True, 0) web = Web(common, False, True) - settings_filename = '/tmp/testsettings.json' - open(settings_filename, 'w').write(json.dumps(test_settings)) + open('/tmp/{}.json'.format(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 @staticmethod diff --git a/tests_gui_local/GuiShareTest.py b/tests_gui_local/GuiShareTest.py index 8c3ea2b1..11df3167 100644 --- a/tests_gui_local/GuiShareTest.py +++ b/tests_gui_local/GuiShareTest.py @@ -24,6 +24,11 @@ class GuiShareTest(GuiBaseTest): # We should have timed out now 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 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) + 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): """Auto-stop timer tests in share mode""" self.run_all_share_mode_setup_tests() diff --git a/tests_gui_local/onionshare_receive_mode_upload_public_mode_test.py b/tests_gui_local/onionshare_receive_mode_upload_public_mode_test.py index f41a2ce2..5b685ef7 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_public_mode_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_public_mode_test.py @@ -11,19 +11,15 @@ class ReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiReceiveTest.tear_down() + cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModePublicModeTest') @pytest.mark.run(order=1) 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) 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__": unittest.main() diff --git a/tests_gui_local/onionshare_receive_mode_upload_test.py b/tests_gui_local/onionshare_receive_mode_upload_test.py index 8a7661dd..7171eaca 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test.py @@ -10,19 +10,15 @@ class ReceiveModeTest(unittest.TestCase, GuiReceiveTest): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiReceiveTest.tear_down() + cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') @pytest.mark.run(order=1) 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) 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__": unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_download_public_mode_test.py b/tests_gui_local/onionshare_share_mode_download_public_mode_test.py index 53d1fb8c..96cadb90 100644 --- a/tests_gui_local/onionshare_share_mode_download_public_mode_test.py +++ b/tests_gui_local/onionshare_share_mode_download_public_mode_test.py @@ -10,19 +10,15 @@ class ShareModePublicModeTest(unittest.TestCase, GuiShareTest): test_settings = { "public_mode": True, } - cls.gui = GuiShareTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiShareTest.tear_down() + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') @pytest.mark.run(order=1) 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) 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__": unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_download_stay_open_test.py b/tests_gui_local/onionshare_share_mode_download_stay_open_test.py index b398f654..bb9ec2ea 100644 --- a/tests_gui_local/onionshare_share_mode_download_stay_open_test.py +++ b/tests_gui_local/onionshare_share_mode_download_stay_open_test.py @@ -10,19 +10,15 @@ class ShareModeStayOpenTest(unittest.TestCase, GuiShareTest): test_settings = { "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiShareTest.tear_down() + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') @pytest.mark.run(order=1) 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) 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__": unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_download_test.py b/tests_gui_local/onionshare_share_mode_download_test.py index 34532c59..12b914b0 100644 --- a/tests_gui_local/onionshare_share_mode_download_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test.py @@ -9,19 +9,15 @@ class ShareModeTest(unittest.TestCase, GuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiShareTest.tear_down() + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTest') @pytest.mark.run(order=1) 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) 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__": unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_slug_persistent_test.py b/tests_gui_local/onionshare_share_mode_slug_persistent_test.py index b4c92f36..25e4e093 100644 --- a/tests_gui_local/onionshare_share_mode_slug_persistent_test.py +++ b/tests_gui_local/onionshare_share_mode_slug_persistent_test.py @@ -13,26 +13,15 @@ class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): "save_private_key": True, "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiShareTest.tear_down() + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') @pytest.mark.run(order=1) 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) def test_run_all_share_mode_tests(self): - GuiShareTest.run_all_share_mode_tests(self, 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) + self.run_all_share_mode_persistent_tests(False, True) if __name__ == "__main__": unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_timer_test.py b/tests_gui_local/onionshare_share_mode_timer_test.py index 98902428..2e654c9d 100644 --- a/tests_gui_local/onionshare_share_mode_timer_test.py +++ b/tests_gui_local/onionshare_share_mode_timer_test.py @@ -11,19 +11,15 @@ class ShareModeTimerTest(unittest.TestCase, GuiShareTest): "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiShareTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiShareTest.tear_down() + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTimerTest') @pytest.mark.run(order=1) 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) 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__": unittest.main() diff --git a/tests_gui_local/run_unit_tests.sh b/tests_gui_local/run_unit_tests.sh deleted file mode 100755 index 7d207a57..00000000 --- a/tests_gui_local/run_unit_tests.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -for test in `ls -1 | egrep ^onionshare_`; do - pytest $test -vvv || exit 1 -done