From af97c131bdc042180c88b82ccda245787de760ed Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 11 Oct 2018 15:09:27 +1100 Subject: [PATCH 01/72] Refactor local tests to reuse most of their code --- .../{commontests.py => GuiBaseTest.py} | 93 +++++++++++- tests_gui_local/__init__.py | 2 +- .../onionshare_receive_mode_upload_test.py | 117 +-------------- ...re_receive_mode_upload_test_public_mode.py | 117 +-------------- .../onionshare_share_mode_download_test.py | 129 +--------------- ...re_share_mode_download_test_public_mode.py | 129 ++-------------- ...hare_share_mode_download_test_stay_open.py | 142 ++---------------- .../onionshare_slug_persistent_test.py | 99 ++---------- tests_gui_local/onionshare_timer_test.py | 66 ++------ 9 files changed, 154 insertions(+), 740 deletions(-) rename tests_gui_local/{commontests.py => GuiBaseTest.py} (72%) diff --git a/tests_gui_local/commontests.py b/tests_gui_local/GuiBaseTest.py similarity index 72% rename from tests_gui_local/commontests.py rename to tests_gui_local/GuiBaseTest.py index 27e406c1..e7d25031 100644 --- a/tests_gui_local/commontests.py +++ b/tests_gui_local/GuiBaseTest.py @@ -18,7 +18,7 @@ from onionshare_gui.mode.share_mode import ShareMode from onionshare_gui.mode.receive_mode import ReceiveMode -class CommonTests(object): +class GuiBaseTest(object): @staticmethod def set_up(test_settings): '''Create GUI with given settings''' @@ -59,6 +59,7 @@ class CommonTests(object): except: pass + def test_gui_loaded(self): '''Test that the GUI actually is shown''' self.assertTrue(self.gui.show) @@ -168,7 +169,6 @@ class CommonTests(object): else: self.assertIsNone(mode.server_status.web.slug, r'(\w+)-(\w+)') - def test_url_description_shown(self, mode): '''Test that the URL label is showing''' self.assertTrue(mode.server_status.url_description.isVisible()) @@ -337,3 +337,92 @@ class CommonTests(object): def test_add_button_visible(self): '''Test that the add button should be visible''' self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) + + + # The following are 'groupings' of tests used by other objects that inherit GuiBaseTest + + def run_all_common_setup_tests(self): + GuiBaseTest.test_gui_loaded(self) + GuiBaseTest.test_windowTitle_seen(self) + GuiBaseTest.test_settings_button_is_visible(self) + GuiBaseTest.test_server_status_bar_is_visible(self) + + def run_all_share_mode_setup_tests(self): + """Tests in share mode prior to starting a share""" + GuiBaseTest.test_click_mode(self, self.gui.share_mode) + GuiBaseTest.test_file_selection_widget_has_a_file(self) + GuiBaseTest.test_history_is_not_visible(self, self.gui.share_mode) + GuiBaseTest.test_click_toggle_history(self, self.gui.share_mode) + GuiBaseTest.test_history_is_visible(self, self.gui.share_mode) + GuiBaseTest.test_deleting_only_file_hides_delete_button(self) + GuiBaseTest.test_add_a_file_and_delete_using_its_delete_widget(self) + GuiBaseTest.test_file_selection_widget_readd_files(self) + + def run_all_share_mode_started_tests(self, public_mode): + """Tests in share mode after starting a share""" + GuiBaseTest.test_server_working_on_start_button_pressed(self, self.gui.share_mode) + GuiBaseTest.test_server_status_indicator_says_starting(self, self.gui.share_mode) + GuiBaseTest.test_add_delete_buttons_hidden(self) + GuiBaseTest.test_settings_button_is_hidden(self) + GuiBaseTest.test_a_server_is_started(self, self.gui.share_mode) + GuiBaseTest.test_a_web_server_is_running(self) + GuiBaseTest.test_have_a_slug(self, self.gui.share_mode, public_mode) + GuiBaseTest.test_url_description_shown(self, self.gui.share_mode) + GuiBaseTest.test_have_copy_url_button(self, self.gui.share_mode) + GuiBaseTest.test_server_status_indicator_says_started(self, self.gui.share_mode) + GuiBaseTest.test_web_page(self, self.gui.share_mode, 'Total size', public_mode) + + def run_all_share_mode_download_tests(self, public_mode, stay_open): + """Tests in share mode after downloading a share""" + GuiBaseTest.test_download_share(self, public_mode) + GuiBaseTest.test_history_widgets_present(self, self.gui.share_mode) + GuiBaseTest.test_server_is_stopped(self, self.gui.share_mode, stay_open) + GuiBaseTest.test_web_service_is_stopped(self) + GuiBaseTest.test_server_status_indicator_says_closed(self, self.gui.share_mode, stay_open) + GuiBaseTest.test_add_button_visible(self) + GuiBaseTest.test_server_working_on_start_button_pressed(self, self.gui.share_mode) + GuiBaseTest.test_a_server_is_started(self, self.gui.share_mode) + GuiBaseTest.test_history_indicator(self, self.gui.share_mode, public_mode) + + def run_all_share_mode_tests(self, public_mode, stay_open): + """End-to-end share tests""" + GuiBaseTest.run_all_share_mode_setup_tests(self) + GuiBaseTest.run_all_share_mode_started_tests(self, public_mode) + GuiBaseTest.run_all_share_mode_download_tests(self, public_mode, stay_open) + + def run_all_share_mode_timer_tests(self, public_mode): + """Auto-stop timer tests in share mode""" + GuiBaseTest.run_all_share_mode_setup_tests(self) + GuiBaseTest.test_set_timeout(self, self.gui.share_mode, 5) + GuiBaseTest.run_all_share_mode_started_tests(self, public_mode) + GuiBaseTest.test_timeout_widget_hidden(self, self.gui.share_mode) + GuiBaseTest.test_server_timed_out(self, self.gui.share_mode, 10000) + GuiBaseTest.test_web_service_is_stopped(self) + + def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): + GuiBaseTest.test_click_mode(self, self.gui.receive_mode) + GuiBaseTest.test_history_is_not_visible(self, self.gui.receive_mode) + GuiBaseTest.test_click_toggle_history(self, self.gui.receive_mode) + GuiBaseTest.test_history_is_visible(self, self.gui.receive_mode) + GuiBaseTest.test_server_working_on_start_button_pressed(self, self.gui.receive_mode) + GuiBaseTest.test_server_status_indicator_says_starting(self, self.gui.receive_mode) + GuiBaseTest.test_settings_button_is_hidden(self) + GuiBaseTest.test_a_server_is_started(self, self.gui.receive_mode) + GuiBaseTest.test_a_web_server_is_running(self) + GuiBaseTest.test_have_a_slug(self, self.gui.receive_mode, public_mode) + GuiBaseTest.test_url_description_shown(self, self.gui.receive_mode) + GuiBaseTest.test_have_copy_url_button(self, self.gui.receive_mode) + GuiBaseTest.test_server_status_indicator_says_started(self, self.gui.receive_mode) + GuiBaseTest.test_web_page(self, self.gui.receive_mode, 'Select the files you want to send, then click', public_mode) + GuiBaseTest.test_upload_file(self, public_mode, '/tmp/OnionShare/test.txt') + GuiBaseTest.test_history_widgets_present(self, self.gui.receive_mode) + GuiBaseTest.test_counter_incremented(self, self.gui.receive_mode, 1) + GuiBaseTest.test_upload_file(self, public_mode, '/tmp/OnionShare/test-2.txt') + GuiBaseTest.test_counter_incremented(self, self.gui.receive_mode, 2) + GuiBaseTest.test_history_indicator(self, self.gui.receive_mode, public_mode) + GuiBaseTest.test_server_is_stopped(self, self.gui.receive_mode, False) + GuiBaseTest.test_web_service_is_stopped(self) + GuiBaseTest.test_server_status_indicator_says_closed(self, self.gui.receive_mode, False) + GuiBaseTest.test_server_working_on_start_button_pressed(self, self.gui.receive_mode) + GuiBaseTest.test_a_server_is_started(self, self.gui.receive_mode) + GuiBaseTest.test_history_indicator(self, self.gui.receive_mode, public_mode) diff --git a/tests_gui_local/__init__.py b/tests_gui_local/__init__.py index bb2b2182..7cf168eb 100644 --- a/tests_gui_local/__init__.py +++ b/tests_gui_local/__init__.py @@ -1 +1 @@ -from .commontests import CommonTests +from .GuiBaseTest import GuiBaseTest diff --git a/tests_gui_local/onionshare_receive_mode_upload_test.py b/tests_gui_local/onionshare_receive_mode_upload_test.py index 91013d92..262c7aba 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test.py @@ -12,128 +12,27 @@ from onionshare.web import Web from onionshare import onion, strings from onionshare_gui import * -from .commontests import CommonTests +from .GuiBaseTest import GuiBaseTest -class OnionShareGuiTest(unittest.TestCase): +class ReceiveModeTest(unittest.TestCase): @classmethod def setUpClass(cls): test_settings = { - "public_mode": False, "receive_allow_receiver_shutdown": True } - cls.gui = CommonTests.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): - CommonTests.tear_down() + GuiBaseTest.tear_down() @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) + def test_run_all_common_setup_tests(self): + GuiBaseTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=6) - def test_click_mode(self): - CommonTests.test_click_mode(self, self.gui.receive_mode) - - @pytest.mark.run(order=6) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, self.gui.receive_mode) - - @pytest.mark.run(order=7) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, self.gui.receive_mode) - - @pytest.mark.run(order=8) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, self.gui.receive_mode) - - @pytest.mark.run(order=8) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.receive_mode) - - @pytest.mark.run(order=9) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, self.gui.receive_mode) - - @pytest.mark.run(order=10) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=11) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, self.gui.receive_mode) - - @pytest.mark.run(order=12) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=14) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, self.gui.receive_mode, False) - - @pytest.mark.run(order=15) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, self.gui.receive_mode) - - @pytest.mark.run(order=16) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, self.gui.receive_mode) - - @pytest.mark.run(order=17) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, self.gui.receive_mode) - - @pytest.mark.run(order=18) - def test_web_page(self): - CommonTests.test_web_page(self, self.gui.receive_mode, 'Select the files you want to send, then click', False) - - @pytest.mark.run(order=19) - def test_upload_file(self): - CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test.txt') - - @pytest.mark.run(order=20) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, self.gui.receive_mode) - - @pytest.mark.run(order=21) - def test_counter_incremented(self): - CommonTests.test_counter_incremented(self, self.gui.receive_mode, 1) - - @pytest.mark.run(order=22) - def test_upload_same_file_is_renamed(self): - CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test-2.txt') - - @pytest.mark.run(order=23) - def test_upload_count_incremented_again(self): - CommonTests.test_counter_incremented(self, self.gui.receive_mode, 2) - - @pytest.mark.run(order=24) - def test_history_indicator(self): - CommonTests.test_history_indicator(self, self.gui.receive_mode, False) - - @pytest.mark.run(order=25) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, self.gui.receive_mode, False) - - @pytest.mark.run(order=26) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=27) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, self.gui.receive_mode, False) + def test_run_all_share_mode_tests(self): + GuiBaseTest.run_all_receive_mode_tests(self, False, True) if __name__ == "__main__": unittest.main() diff --git a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py index 42f237c9..201402c2 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py @@ -8,133 +8,32 @@ import json from PyQt5 import QtWidgets from onionshare.common import Common -from onionshare.settings import Settings from onionshare.web import Web from onionshare import onion, strings from onionshare_gui import * -from .commontests import CommonTests +from .GuiBaseTest import GuiBaseTest -class OnionShareGuiTest(unittest.TestCase): +class ReceiveModePublicModeTest(unittest.TestCase): @classmethod def setUpClass(cls): test_settings = { "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = CommonTests.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): - CommonTests.tear_down() + GuiBaseTest.tear_down() @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) + def test_run_all_common_setup_tests(self): + GuiBaseTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_click_mode(self): - CommonTests.test_click_mode(self, self.gui.receive_mode) - - @pytest.mark.run(order=6) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, self.gui.receive_mode) - - @pytest.mark.run(order=7) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, self.gui.receive_mode) - - @pytest.mark.run(order=8) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, self.gui.receive_mode) - - @pytest.mark.run(order=9) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.receive_mode) - - @pytest.mark.run(order=10) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, self.gui.receive_mode) - - @pytest.mark.run(order=11) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=12) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, self.gui.receive_mode) - - @pytest.mark.run(order=13) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=14) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, self.gui.receive_mode, True) - - @pytest.mark.run(order=15) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, self.gui.receive_mode) - - @pytest.mark.run(order=16) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, self.gui.receive_mode) - - @pytest.mark.run(order=17) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, self.gui.receive_mode) - - @pytest.mark.run(order=18) - def test_web_page(self): - CommonTests.test_web_page(self, self.gui.receive_mode, 'Select the files you want to send, then click', True) - - @pytest.mark.run(order=19) - def test_upload_file(self): - CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test.txt') - - @pytest.mark.run(order=20) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, self.gui.receive_mode) - - @pytest.mark.run(order=21) - def test_counter_incremented(self): - CommonTests.test_counter_incremented(self, self.gui.receive_mode, 1) - - @pytest.mark.run(order=22) - def test_upload_same_file_is_renamed(self): - CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test-2.txt') - - @pytest.mark.run(order=23) - def test_upload_count_incremented_again(self): - CommonTests.test_counter_incremented(self, self.gui.receive_mode, 2) - - @pytest.mark.run(order=24) - def test_history_indicator(self): - CommonTests.test_history_indicator(self, self.gui.receive_mode, True) - - @pytest.mark.run(order=25) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, self.gui.receive_mode, False) - - @pytest.mark.run(order=26) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=27) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, self.gui.receive_mode, False) + def test_run_all_share_mode_tests(self): + GuiBaseTest.run_all_receive_mode_tests(self, True, 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 9caad8b1..b24a3a78 100644 --- a/tests_gui_local/onionshare_share_mode_download_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test.py @@ -12,139 +12,26 @@ from onionshare.web import Web from onionshare import onion, strings from onionshare_gui import * -from .commontests import CommonTests +from .GuiBaseTest import GuiBaseTest -class OnionShareGuiTest(unittest.TestCase): +class ShareModeTest(unittest.TestCase): @classmethod def setUpClass(cls): test_settings = { - "public_mode": False, - "close_after_first_download": True } - cls.gui = CommonTests.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): - CommonTests.tear_down() + GuiBaseTest.tear_down() @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) + def test_run_all_common_setup_tests(self): + GuiBaseTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, self.gui.share_mode) - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=10) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=11) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=12) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=13) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - - @pytest.mark.run(order=14) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode) - - @pytest.mark.run(order=15) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=16) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=17) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - - @pytest.mark.run(order=18) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=19) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, self.gui.share_mode, False) - - @pytest.mark.run(order=20) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, self.gui.share_mode) - - @pytest.mark.run(order=21) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, self.gui.share_mode) - - @pytest.mark.run(order=22) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, self.gui.share_mode) - - @pytest.mark.run(order=23) - def test_web_page(self): - CommonTests.test_web_page(self, self.gui.share_mode, 'Total size', False) - - @pytest.mark.run(order=24) - def test_download_share(self): - CommonTests.test_download_share(self, False) - - @pytest.mark.run(order=25) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, self.gui.share_mode) - - @pytest.mark.run(order=26) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, self.gui.share_mode, False) - - @pytest.mark.run(order=27) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=28) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, self.gui.share_mode, False) - - @pytest.mark.run(order=29) - def test_add_button_visible(self): - CommonTests.test_add_button_visible(self) - - @pytest.mark.run(order=30) - def test_history_indicator(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - CommonTests.test_history_indicator(self, self.gui.share_mode, False) - + def test_run_all_share_mode_tests(self): + GuiBaseTest.run_all_share_mode_tests(self, False, False) if __name__ == "__main__": unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_download_test_public_mode.py b/tests_gui_local/onionshare_share_mode_download_test_public_mode.py index c7b05543..e59b53f4 100644 --- a/tests_gui_local/onionshare_share_mode_download_test_public_mode.py +++ b/tests_gui_local/onionshare_share_mode_download_test_public_mode.py @@ -12,138 +12,27 @@ from onionshare.web import Web from onionshare import onion, strings from onionshare_gui import * -from .commontests import CommonTests +from .GuiBaseTest import GuiBaseTest -class OnionShareGuiTest(unittest.TestCase): +class ShareModePublicModeTest(unittest.TestCase): @classmethod def setUpClass(cls): test_settings = { - "public_mode": True + "public_mode": True, } - cls.gui = CommonTests.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): - CommonTests.tear_down() + GuiBaseTest.tear_down() @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) + def test_run_all_common_setup_tests(self): + GuiBaseTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, self.gui.share_mode) - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=10) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=11) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=12) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=13) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - - @pytest.mark.run(order=14) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode) - - @pytest.mark.run(order=15) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=16) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=17) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - - @pytest.mark.run(order=18) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=19) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, self.gui.share_mode, True) - - @pytest.mark.run(order=20) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, self.gui.share_mode) - - @pytest.mark.run(order=21) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, self.gui.share_mode) - - @pytest.mark.run(order=22) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, self.gui.share_mode) - - @pytest.mark.run(order=23) - def test_web_page(self): - CommonTests.test_web_page(self, self.gui.share_mode, 'Total size', True) - - @pytest.mark.run(order=24) - def test_download_share(self): - CommonTests.test_download_share(self, True) - - @pytest.mark.run(order=25) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, self.gui.share_mode) - - @pytest.mark.run(order=26) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, self.gui.share_mode, False) - - @pytest.mark.run(order=27) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=28) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, self.gui.share_mode, False) - - @pytest.mark.run(order=29) - def test_add_button_visible(self): - CommonTests.test_add_button_visible(self) - - @pytest.mark.run(order=30) - def test_history_indicator(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - CommonTests.test_history_indicator(self, self.gui.share_mode, True) - + def test_run_all_share_mode_tests(self): + GuiBaseTest.run_all_share_mode_tests(self, True, False) if __name__ == "__main__": unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_download_test_stay_open.py b/tests_gui_local/onionshare_share_mode_download_test_stay_open.py index 478177c0..9394c34a 100644 --- a/tests_gui_local/onionshare_share_mode_download_test_stay_open.py +++ b/tests_gui_local/onionshare_share_mode_download_test_stay_open.py @@ -12,151 +12,27 @@ from onionshare.web import Web from onionshare import onion, strings from onionshare_gui import * -from .commontests import CommonTests +from .GuiBaseTest import GuiBaseTest -class OnionShareGuiTest(unittest.TestCase): +class ShareModeStayOpenTest(unittest.TestCase): @classmethod def setUpClass(cls): test_settings = { - "public_mode": True, - "close_after_first_download": False + "close_after_first_download": False, } - cls.gui = CommonTests.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): - CommonTests.tear_down() + GuiBaseTest.tear_down() @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) + def test_run_all_common_setup_tests(self): + GuiBaseTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, self.gui.share_mode) - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=10) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=11) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=12) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=13) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - - @pytest.mark.run(order=14) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode) - - @pytest.mark.run(order=15) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=16) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=17) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - - @pytest.mark.run(order=18) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=19) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, self.gui.share_mode, True) - - @pytest.mark.run(order=20) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, self.gui.share_mode) - - @pytest.mark.run(order=21) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, self.gui.share_mode) - - @pytest.mark.run(order=22) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, self.gui.share_mode) - - @pytest.mark.run(order=23) - def test_web_page(self): - CommonTests.test_web_page(self, self.gui.share_mode, 'Total size', True) - - @pytest.mark.run(order=24) - def test_download_share(self): - CommonTests.test_download_share(self, True) - - @pytest.mark.run(order=25) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, self.gui.share_mode) - - @pytest.mark.run(order=26) - def test_counter_incremented(self): - CommonTests.test_counter_incremented(self, self.gui.share_mode, 1) - - @pytest.mark.run(order=27) - def test_download_share_again(self): - CommonTests.test_download_share(self, True) - - @pytest.mark.run(order=28) - def test_counter_incremented_again(self): - CommonTests.test_counter_incremented(self, self.gui.share_mode, 2) - - @pytest.mark.run(order=29) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, self.gui.share_mode, True) - - @pytest.mark.run(order=30) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=31) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, self.gui.share_mode, True) - - @pytest.mark.run(order=32) - def test_add_button_visible(self): - CommonTests.test_add_button_visible(self) - - @pytest.mark.run(order=33) - def test_history_indicator(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - CommonTests.test_history_indicator(self, self.gui.share_mode, True) - + def test_run_all_share_mode_tests(self): + GuiBaseTest.run_all_share_mode_tests(self, False, True) if __name__ == "__main__": unittest.main() diff --git a/tests_gui_local/onionshare_slug_persistent_test.py b/tests_gui_local/onionshare_slug_persistent_test.py index f4139afb..ab845f8e 100644 --- a/tests_gui_local/onionshare_slug_persistent_test.py +++ b/tests_gui_local/onionshare_slug_persistent_test.py @@ -12,114 +12,37 @@ from onionshare.web import Web from onionshare import onion, strings from onionshare_gui import * -from .commontests import CommonTests +from .GuiBaseTest import GuiBaseTest -class OnionShareGuiTest(unittest.TestCase): +class ShareModePersistentSlugTest(unittest.TestCase): @classmethod def setUpClass(cls): test_settings = { "public_mode": False, "slug": "", - "save_private_key": True + "save_private_key": True, + "close_after_first_download": False, } - cls.gui = CommonTests.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): - CommonTests.tear_down() + GuiBaseTest.tear_down() @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) + def test_run_all_common_setup_tests(self): + GuiBaseTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, self.gui.share_mode) - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=10) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - - @pytest.mark.run(order=11) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode) - - @pytest.mark.run(order=12) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=13) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - - @pytest.mark.run(order=14) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=15) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, self.gui.share_mode, False) + def test_run_all_share_mode_tests(self): + GuiBaseTest.run_all_share_mode_tests(self, False, True) global slug slug = self.gui.share_mode.server_status.web.slug - @pytest.mark.run(order=16) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, self.gui.share_mode) - - @pytest.mark.run(order=17) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, self.gui.share_mode, True) - - @pytest.mark.run(order=18) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=19) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, self.gui.share_mode, True) - - @pytest.mark.run(order=20) - def test_server_started_again(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode) - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - - @pytest.mark.run(order=21) + @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) - @pytest.mark.run(order=22) - def test_server_is_stopped_again(self): - CommonTests.test_server_is_stopped(self, self.gui.share_mode, True) - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=23) - def test_history_indicator(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - CommonTests.test_history_indicator(self, self.gui.share_mode, False) - - if __name__ == "__main__": unittest.main() diff --git a/tests_gui_local/onionshare_timer_test.py b/tests_gui_local/onionshare_timer_test.py index ef55886e..60c616cc 100644 --- a/tests_gui_local/onionshare_timer_test.py +++ b/tests_gui_local/onionshare_timer_test.py @@ -12,76 +12,28 @@ from onionshare.web import Web from onionshare import onion, strings from onionshare_gui import * -from .commontests import CommonTests +from .GuiBaseTest import GuiBaseTest -class OnionShareGuiTest(unittest.TestCase): +class ShareModeTimerTest(unittest.TestCase): @classmethod def setUpClass(cls): test_settings = { "public_mode": False, - "shutdown_timeout": True + "shutdown_timeout": True, } - cls.gui = CommonTests.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): - CommonTests.tear_down() + GuiBaseTest.tear_down() @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) + def test_run_all_common_setup_tests(self): + GuiBaseTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, self.gui.share_mode) - - @pytest.mark.run(order=8) - def test_set_timeout(self): - CommonTests.test_set_timeout(self, self.gui.share_mode, 5) - - @pytest.mark.run(order=9) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - - @pytest.mark.run(order=10) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, self.gui.share_mode) - - @pytest.mark.run(order=11) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, self.gui.share_mode) - - @pytest.mark.run(order=12) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=13) - def test_timeout_widget_hidden(self): - CommonTests.test_timeout_widget_hidden(self, self.gui.share_mode) - - @pytest.mark.run(order=14) - def test_timeout(self): - CommonTests.test_server_timed_out(self, self.gui.share_mode, 10000) - - @pytest.mark.run(order=15) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) + def test_run_all_share_mode_timer_tests(self): + GuiBaseTest.run_all_share_mode_timer_tests(self, False) if __name__ == "__main__": unittest.main() From cd6931ec8c6f2010b7c39ce117211f274987a7a6 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 11 Oct 2018 16:04:37 +1100 Subject: [PATCH 02/72] Try and move local tests into main tests dir. Rename local tests. Save test settings to unique json files to avoid race conditions --- .travis.yml | 3 +- {tests_gui_local => tests}/GuiBaseTest.py | 3 +- tests/__init__.py | 1 + .../local_receive_mode_public_mode_test.py | 2 +- .../local_receive_mode_test.py | 2 +- .../local_share_mode_persistent_slug_test.py | 10 +- .../local_share_mode_public_mode_test.py | 2 +- .../local_share_mode_stay_open_test.py | 2 +- .../local_share_mode_test.py | 2 +- .../local_share_mode_timer_test.py | 2 +- tests_gui_local/__init__.py | 1 - tests_gui_local/conftest.py | 160 ------------------ tests_gui_local/run_unit_tests.sh | 5 - 13 files changed, 14 insertions(+), 181 deletions(-) rename {tests_gui_local => tests}/GuiBaseTest.py (99%) rename tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py => tests/local_receive_mode_public_mode_test.py (90%) rename tests_gui_local/onionshare_receive_mode_upload_test.py => tests/local_receive_mode_test.py (91%) rename tests_gui_local/onionshare_slug_persistent_test.py => tests/local_share_mode_persistent_slug_test.py (81%) rename tests_gui_local/onionshare_share_mode_download_test_public_mode.py => tests/local_share_mode_public_mode_test.py (90%) rename tests_gui_local/onionshare_share_mode_download_test_stay_open.py => tests/local_share_mode_stay_open_test.py (90%) rename tests_gui_local/onionshare_share_mode_download_test.py => tests/local_share_mode_test.py (91%) rename tests_gui_local/onionshare_timer_test.py => tests/local_share_mode_timer_test.py (91%) delete mode 100644 tests_gui_local/__init__.py delete mode 100644 tests_gui_local/conftest.py delete mode 100755 tests_gui_local/run_unit_tests.sh diff --git a/.travis.yml b/.travis.yml index e0b5b822..24255416 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,5 +19,4 @@ before_script: - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics # 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 --cov=onionshare tests/ diff --git a/tests_gui_local/GuiBaseTest.py b/tests/GuiBaseTest.py similarity index 99% rename from tests_gui_local/GuiBaseTest.py rename to tests/GuiBaseTest.py index e7d25031..7aec97f7 100644 --- a/tests_gui_local/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -20,7 +20,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='/tmp/testsettings.json'): '''Create GUI with given settings''' # Create our test file testfile = open('/tmp/test.txt', 'w') @@ -45,7 +45,6 @@ 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)) gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True) diff --git a/tests/__init__.py b/tests/__init__.py index e69de29b..1def7f5e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1 @@ +from .GuiBaseTest import GuiBaseTest diff --git a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py b/tests/local_receive_mode_public_mode_test.py similarity index 90% rename from tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py rename to tests/local_receive_mode_public_mode_test.py index 201402c2..0bc00833 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py +++ b/tests/local_receive_mode_public_mode_test.py @@ -21,7 +21,7 @@ class ReceiveModePublicModeTest(unittest.TestCase): "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ReceiveModePublicModeTest.json') @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_receive_mode_upload_test.py b/tests/local_receive_mode_test.py similarity index 91% rename from tests_gui_local/onionshare_receive_mode_upload_test.py rename to tests/local_receive_mode_test.py index 262c7aba..82d7529a 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test.py +++ b/tests/local_receive_mode_test.py @@ -20,7 +20,7 @@ class ReceiveModeTest(unittest.TestCase): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ReceiveModeTest.json') @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_slug_persistent_test.py b/tests/local_share_mode_persistent_slug_test.py similarity index 81% rename from tests_gui_local/onionshare_slug_persistent_test.py rename to tests/local_share_mode_persistent_slug_test.py index ab845f8e..cad01ed9 100644 --- a/tests_gui_local/onionshare_slug_persistent_test.py +++ b/tests/local_share_mode_persistent_slug_test.py @@ -23,23 +23,23 @@ class ShareModePersistentSlugTest(unittest.TestCase): "save_private_key": True, "close_after_first_download": False, } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModePersistentSlugTest.json') @classmethod def tearDownClass(cls): GuiBaseTest.tear_down() - @pytest.mark.run(order=1) + @pytest.mark.run(order=1000) def test_run_all_common_setup_tests(self): GuiBaseTest.run_all_common_setup_tests(self) - @pytest.mark.run(order=2) - def test_run_all_share_mode_tests(self): + @pytest.mark.run(order=1001) + def test_run_all_persistent_share_mode_tests(self): GuiBaseTest.run_all_share_mode_tests(self, False, True) global slug slug = self.gui.share_mode.server_status.web.slug - @pytest.mark.run(order=3) + @pytest.mark.run(order=1002) def test_have_same_slug(self): '''Test that we have the same slug''' self.assertEqual(self.gui.share_mode.server_status.web.slug, slug) diff --git a/tests_gui_local/onionshare_share_mode_download_test_public_mode.py b/tests/local_share_mode_public_mode_test.py similarity index 90% rename from tests_gui_local/onionshare_share_mode_download_test_public_mode.py rename to tests/local_share_mode_public_mode_test.py index e59b53f4..2aa3caea 100644 --- a/tests_gui_local/onionshare_share_mode_download_test_public_mode.py +++ b/tests/local_share_mode_public_mode_test.py @@ -20,7 +20,7 @@ class ShareModePublicModeTest(unittest.TestCase): test_settings = { "public_mode": True, } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModePublicModeTest.json') @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_share_mode_download_test_stay_open.py b/tests/local_share_mode_stay_open_test.py similarity index 90% rename from tests_gui_local/onionshare_share_mode_download_test_stay_open.py rename to tests/local_share_mode_stay_open_test.py index 9394c34a..0a2db984 100644 --- a/tests_gui_local/onionshare_share_mode_download_test_stay_open.py +++ b/tests/local_share_mode_stay_open_test.py @@ -20,7 +20,7 @@ class ShareModeStayOpenTest(unittest.TestCase): test_settings = { "close_after_first_download": False, } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeStayOpenTest.json') @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_share_mode_download_test.py b/tests/local_share_mode_test.py similarity index 91% rename from tests_gui_local/onionshare_share_mode_download_test.py rename to tests/local_share_mode_test.py index b24a3a78..ca1bed2c 100644 --- a/tests_gui_local/onionshare_share_mode_download_test.py +++ b/tests/local_share_mode_test.py @@ -19,7 +19,7 @@ class ShareModeTest(unittest.TestCase): def setUpClass(cls): test_settings = { } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeTest.json') @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_timer_test.py b/tests/local_share_mode_timer_test.py similarity index 91% rename from tests_gui_local/onionshare_timer_test.py rename to tests/local_share_mode_timer_test.py index 60c616cc..ffa138a6 100644 --- a/tests_gui_local/onionshare_timer_test.py +++ b/tests/local_share_mode_timer_test.py @@ -21,7 +21,7 @@ class ShareModeTimerTest(unittest.TestCase): "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeTimerTest.json') @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/__init__.py b/tests_gui_local/__init__.py deleted file mode 100644 index 7cf168eb..00000000 --- a/tests_gui_local/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .GuiBaseTest import GuiBaseTest diff --git a/tests_gui_local/conftest.py b/tests_gui_local/conftest.py deleted file mode 100644 index 8ac7efb8..00000000 --- a/tests_gui_local/conftest.py +++ /dev/null @@ -1,160 +0,0 @@ -import sys -# Force tests to look for resources in the source code tree -sys.onionshare_dev_mode = True - -import os -import shutil -import tempfile - -import pytest - -from onionshare import common, web, settings - -@pytest.fixture -def temp_dir_1024(): - """ Create a temporary directory that has a single file of a - particular size (1024 bytes). - """ - - tmp_dir = tempfile.mkdtemp() - tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir) - with open(tmp_file, 'wb') as f: - f.write(b'*' * 1024) - return tmp_dir - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture -def temp_dir_1024_delete(): - """ Create a temporary directory that has a single file of a - particular size (1024 bytes). The temporary directory (including - the file inside) will be deleted after fixture usage. - """ - - with tempfile.TemporaryDirectory() as tmp_dir: - tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir) - with open(tmp_file, 'wb') as f: - f.write(b'*' * 1024) - yield tmp_dir - - -@pytest.fixture -def temp_file_1024(): - """ Create a temporary file of a particular size (1024 bytes). """ - - with tempfile.NamedTemporaryFile(delete=False) as tmp_file: - tmp_file.write(b'*' * 1024) - return tmp_file.name - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture -def temp_file_1024_delete(): - """ - Create a temporary file of a particular size (1024 bytes). - The temporary file will be deleted after fixture usage. - """ - - with tempfile.NamedTemporaryFile() as tmp_file: - tmp_file.write(b'*' * 1024) - tmp_file.flush() - yield tmp_file.name - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture(scope='session') -def custom_zw(): - zw = web.share_mode.ZipWriter( - common.Common(), - zip_filename=common.Common.random_string(4, 6), - processed_size_callback=lambda _: 'custom_callback' - ) - yield zw - zw.close() - os.remove(zw.zip_filename) - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture(scope='session') -def default_zw(): - zw = web.share_mode.ZipWriter(common.Common()) - yield zw - zw.close() - tmp_dir = os.path.dirname(zw.zip_filename) - shutil.rmtree(tmp_dir) - - -@pytest.fixture -def locale_en(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8')) - - -@pytest.fixture -def locale_fr(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8')) - - -@pytest.fixture -def locale_invalid(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8')) - - -@pytest.fixture -def locale_ru(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8')) - - -@pytest.fixture -def platform_darwin(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Darwin') - - -@pytest.fixture # (scope="session") -def platform_linux(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Linux') - - -@pytest.fixture -def platform_windows(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Windows') - - -@pytest.fixture -def sys_argv_sys_prefix(monkeypatch): - monkeypatch.setattr('sys.argv', [sys.prefix]) - - -@pytest.fixture -def sys_frozen(monkeypatch): - monkeypatch.setattr('sys.frozen', True, raising=False) - - -@pytest.fixture -def sys_meipass(monkeypatch): - monkeypatch.setattr( - 'sys._MEIPASS', os.path.expanduser('~'), raising=False) - - -@pytest.fixture # (scope="session") -def sys_onionshare_dev_mode(monkeypatch): - monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False) - - -@pytest.fixture -def time_time_100(monkeypatch): - monkeypatch.setattr('time.time', lambda: 100) - - -@pytest.fixture -def time_strftime(monkeypatch): - monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00') - -@pytest.fixture -def common_obj(): - return common.Common() - -@pytest.fixture -def settings_obj(sys_onionshare_dev_mode, platform_linux): - _common = common.Common() - _common.version = 'DUMMY_VERSION_1.2.3' - return settings.Settings(_common) 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 From bc90b7de93407166a8d90d3b71e05880fe6193d4 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 11 Oct 2018 16:07:16 +1100 Subject: [PATCH 03/72] Revert "Try and move local tests into main tests dir. Rename local tests. Save test settings to unique json files to avoid race conditions" This reverts commit cd6931ec8c6f2010b7c39ce117211f274987a7a6. --- .travis.yml | 3 +- tests/__init__.py | 1 - {tests => tests_gui_local}/GuiBaseTest.py | 3 +- tests_gui_local/__init__.py | 1 + tests_gui_local/conftest.py | 160 ++++++++++++++++++ .../onionshare_receive_mode_upload_test.py | 2 +- ...re_receive_mode_upload_test_public_mode.py | 2 +- .../onionshare_share_mode_download_test.py | 2 +- ...re_share_mode_download_test_public_mode.py | 2 +- ...hare_share_mode_download_test_stay_open.py | 2 +- .../onionshare_slug_persistent_test.py | 10 +- .../onionshare_timer_test.py | 2 +- tests_gui_local/run_unit_tests.sh | 5 + 13 files changed, 181 insertions(+), 14 deletions(-) rename {tests => tests_gui_local}/GuiBaseTest.py (99%) create mode 100644 tests_gui_local/__init__.py create mode 100644 tests_gui_local/conftest.py rename tests/local_receive_mode_test.py => tests_gui_local/onionshare_receive_mode_upload_test.py (91%) rename tests/local_receive_mode_public_mode_test.py => tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py (90%) rename tests/local_share_mode_test.py => tests_gui_local/onionshare_share_mode_download_test.py (91%) rename tests/local_share_mode_public_mode_test.py => tests_gui_local/onionshare_share_mode_download_test_public_mode.py (90%) rename tests/local_share_mode_stay_open_test.py => tests_gui_local/onionshare_share_mode_download_test_stay_open.py (90%) rename tests/local_share_mode_persistent_slug_test.py => tests_gui_local/onionshare_slug_persistent_test.py (81%) rename tests/local_share_mode_timer_test.py => tests_gui_local/onionshare_timer_test.py (91%) create mode 100755 tests_gui_local/run_unit_tests.sh diff --git a/.travis.yml b/.travis.yml index 24255416..e0b5b822 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,4 +19,5 @@ before_script: - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics # run CLI tests and local GUI tests script: - - xvfb-run pytest --cov=onionshare tests/ + - pytest --cov=onionshare tests/ + - cd tests_gui_local/ && xvfb-run ./run_unit_tests.sh diff --git a/tests/__init__.py b/tests/__init__.py index 1def7f5e..e69de29b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +0,0 @@ -from .GuiBaseTest import GuiBaseTest diff --git a/tests/GuiBaseTest.py b/tests_gui_local/GuiBaseTest.py similarity index 99% rename from tests/GuiBaseTest.py rename to tests_gui_local/GuiBaseTest.py index 7aec97f7..e7d25031 100644 --- a/tests/GuiBaseTest.py +++ b/tests_gui_local/GuiBaseTest.py @@ -20,7 +20,7 @@ from onionshare_gui.mode.receive_mode import ReceiveMode class GuiBaseTest(object): @staticmethod - def set_up(test_settings, settings_filename='/tmp/testsettings.json'): + def set_up(test_settings): '''Create GUI with given settings''' # Create our test file testfile = open('/tmp/test.txt', 'w') @@ -45,6 +45,7 @@ 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)) gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True) diff --git a/tests_gui_local/__init__.py b/tests_gui_local/__init__.py new file mode 100644 index 00000000..7cf168eb --- /dev/null +++ b/tests_gui_local/__init__.py @@ -0,0 +1 @@ +from .GuiBaseTest import GuiBaseTest diff --git a/tests_gui_local/conftest.py b/tests_gui_local/conftest.py new file mode 100644 index 00000000..8ac7efb8 --- /dev/null +++ b/tests_gui_local/conftest.py @@ -0,0 +1,160 @@ +import sys +# Force tests to look for resources in the source code tree +sys.onionshare_dev_mode = True + +import os +import shutil +import tempfile + +import pytest + +from onionshare import common, web, settings + +@pytest.fixture +def temp_dir_1024(): + """ Create a temporary directory that has a single file of a + particular size (1024 bytes). + """ + + tmp_dir = tempfile.mkdtemp() + tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir) + with open(tmp_file, 'wb') as f: + f.write(b'*' * 1024) + return tmp_dir + + +# pytest > 2.9 only needs @pytest.fixture +@pytest.yield_fixture +def temp_dir_1024_delete(): + """ Create a temporary directory that has a single file of a + particular size (1024 bytes). The temporary directory (including + the file inside) will be deleted after fixture usage. + """ + + with tempfile.TemporaryDirectory() as tmp_dir: + tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir) + with open(tmp_file, 'wb') as f: + f.write(b'*' * 1024) + yield tmp_dir + + +@pytest.fixture +def temp_file_1024(): + """ Create a temporary file of a particular size (1024 bytes). """ + + with tempfile.NamedTemporaryFile(delete=False) as tmp_file: + tmp_file.write(b'*' * 1024) + return tmp_file.name + + +# pytest > 2.9 only needs @pytest.fixture +@pytest.yield_fixture +def temp_file_1024_delete(): + """ + Create a temporary file of a particular size (1024 bytes). + The temporary file will be deleted after fixture usage. + """ + + with tempfile.NamedTemporaryFile() as tmp_file: + tmp_file.write(b'*' * 1024) + tmp_file.flush() + yield tmp_file.name + + +# pytest > 2.9 only needs @pytest.fixture +@pytest.yield_fixture(scope='session') +def custom_zw(): + zw = web.share_mode.ZipWriter( + common.Common(), + zip_filename=common.Common.random_string(4, 6), + processed_size_callback=lambda _: 'custom_callback' + ) + yield zw + zw.close() + os.remove(zw.zip_filename) + + +# pytest > 2.9 only needs @pytest.fixture +@pytest.yield_fixture(scope='session') +def default_zw(): + zw = web.share_mode.ZipWriter(common.Common()) + yield zw + zw.close() + tmp_dir = os.path.dirname(zw.zip_filename) + shutil.rmtree(tmp_dir) + + +@pytest.fixture +def locale_en(monkeypatch): + monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8')) + + +@pytest.fixture +def locale_fr(monkeypatch): + monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8')) + + +@pytest.fixture +def locale_invalid(monkeypatch): + monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8')) + + +@pytest.fixture +def locale_ru(monkeypatch): + monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8')) + + +@pytest.fixture +def platform_darwin(monkeypatch): + monkeypatch.setattr('platform.system', lambda: 'Darwin') + + +@pytest.fixture # (scope="session") +def platform_linux(monkeypatch): + monkeypatch.setattr('platform.system', lambda: 'Linux') + + +@pytest.fixture +def platform_windows(monkeypatch): + monkeypatch.setattr('platform.system', lambda: 'Windows') + + +@pytest.fixture +def sys_argv_sys_prefix(monkeypatch): + monkeypatch.setattr('sys.argv', [sys.prefix]) + + +@pytest.fixture +def sys_frozen(monkeypatch): + monkeypatch.setattr('sys.frozen', True, raising=False) + + +@pytest.fixture +def sys_meipass(monkeypatch): + monkeypatch.setattr( + 'sys._MEIPASS', os.path.expanduser('~'), raising=False) + + +@pytest.fixture # (scope="session") +def sys_onionshare_dev_mode(monkeypatch): + monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False) + + +@pytest.fixture +def time_time_100(monkeypatch): + monkeypatch.setattr('time.time', lambda: 100) + + +@pytest.fixture +def time_strftime(monkeypatch): + monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00') + +@pytest.fixture +def common_obj(): + return common.Common() + +@pytest.fixture +def settings_obj(sys_onionshare_dev_mode, platform_linux): + _common = common.Common() + _common.version = 'DUMMY_VERSION_1.2.3' + return settings.Settings(_common) diff --git a/tests/local_receive_mode_test.py b/tests_gui_local/onionshare_receive_mode_upload_test.py similarity index 91% rename from tests/local_receive_mode_test.py rename to tests_gui_local/onionshare_receive_mode_upload_test.py index 82d7529a..262c7aba 100644 --- a/tests/local_receive_mode_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test.py @@ -20,7 +20,7 @@ class ReceiveModeTest(unittest.TestCase): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ReceiveModeTest.json') + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_receive_mode_public_mode_test.py b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py similarity index 90% rename from tests/local_receive_mode_public_mode_test.py rename to tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py index 0bc00833..201402c2 100644 --- a/tests/local_receive_mode_public_mode_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py @@ -21,7 +21,7 @@ class ReceiveModePublicModeTest(unittest.TestCase): "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ReceiveModePublicModeTest.json') + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_share_mode_test.py b/tests_gui_local/onionshare_share_mode_download_test.py similarity index 91% rename from tests/local_share_mode_test.py rename to tests_gui_local/onionshare_share_mode_download_test.py index ca1bed2c..b24a3a78 100644 --- a/tests/local_share_mode_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test.py @@ -19,7 +19,7 @@ class ShareModeTest(unittest.TestCase): def setUpClass(cls): test_settings = { } - cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeTest.json') + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_share_mode_public_mode_test.py b/tests_gui_local/onionshare_share_mode_download_test_public_mode.py similarity index 90% rename from tests/local_share_mode_public_mode_test.py rename to tests_gui_local/onionshare_share_mode_download_test_public_mode.py index 2aa3caea..e59b53f4 100644 --- a/tests/local_share_mode_public_mode_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test_public_mode.py @@ -20,7 +20,7 @@ class ShareModePublicModeTest(unittest.TestCase): test_settings = { "public_mode": True, } - cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModePublicModeTest.json') + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_share_mode_stay_open_test.py b/tests_gui_local/onionshare_share_mode_download_test_stay_open.py similarity index 90% rename from tests/local_share_mode_stay_open_test.py rename to tests_gui_local/onionshare_share_mode_download_test_stay_open.py index 0a2db984..9394c34a 100644 --- a/tests/local_share_mode_stay_open_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test_stay_open.py @@ -20,7 +20,7 @@ class ShareModeStayOpenTest(unittest.TestCase): test_settings = { "close_after_first_download": False, } - cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeStayOpenTest.json') + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_share_mode_persistent_slug_test.py b/tests_gui_local/onionshare_slug_persistent_test.py similarity index 81% rename from tests/local_share_mode_persistent_slug_test.py rename to tests_gui_local/onionshare_slug_persistent_test.py index cad01ed9..ab845f8e 100644 --- a/tests/local_share_mode_persistent_slug_test.py +++ b/tests_gui_local/onionshare_slug_persistent_test.py @@ -23,23 +23,23 @@ class ShareModePersistentSlugTest(unittest.TestCase): "save_private_key": True, "close_after_first_download": False, } - cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModePersistentSlugTest.json') + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): GuiBaseTest.tear_down() - @pytest.mark.run(order=1000) + @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): GuiBaseTest.run_all_common_setup_tests(self) - @pytest.mark.run(order=1001) - def test_run_all_persistent_share_mode_tests(self): + @pytest.mark.run(order=2) + def test_run_all_share_mode_tests(self): GuiBaseTest.run_all_share_mode_tests(self, False, True) global slug slug = self.gui.share_mode.server_status.web.slug - @pytest.mark.run(order=1002) + @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) diff --git a/tests/local_share_mode_timer_test.py b/tests_gui_local/onionshare_timer_test.py similarity index 91% rename from tests/local_share_mode_timer_test.py rename to tests_gui_local/onionshare_timer_test.py index ffa138a6..60c616cc 100644 --- a/tests/local_share_mode_timer_test.py +++ b/tests_gui_local/onionshare_timer_test.py @@ -21,7 +21,7 @@ class ShareModeTimerTest(unittest.TestCase): "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeTimerTest.json') + cls.gui = GuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/run_unit_tests.sh b/tests_gui_local/run_unit_tests.sh new file mode 100755 index 00000000..7d207a57 --- /dev/null +++ b/tests_gui_local/run_unit_tests.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +for test in `ls -1 | egrep ^onionshare_`; do + pytest $test -vvv || exit 1 +done From 70b50827c2cbfd548221a1296e242a60e6958854 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 11:28:47 +1100 Subject: [PATCH 04/72] Refactor tests to use proper inheritance of GuiReceiveTest/GuiShareTest (which inherit from GuiBaseTest). Prevent tests from auto-firing in these base objects. Clean up imported modules, rename files to end in _test.py --- tests_gui_local/GuiBaseTest.py | 260 ++++-------------- tests_gui_local/GuiReceiveTest.py | 45 +++ tests_gui_local/GuiShareTest.py | 154 +++++++++++ tests_gui_local/__init__.py | 1 - ...re_receive_mode_upload_public_mode_test.py | 29 ++ .../onionshare_receive_mode_upload_test.py | 26 +- ...re_receive_mode_upload_test_public_mode.py | 39 --- ...re_share_mode_download_public_mode_test.py | 28 ++ ...hare_share_mode_download_stay_open_test.py | 28 ++ .../onionshare_share_mode_download_test.py | 24 +- ...re_share_mode_download_test_public_mode.py | 38 --- ...hare_share_mode_download_test_stay_open.py | 38 --- ...nshare_share_mode_slug_persistent_test.py} | 24 +- .../onionshare_share_mode_timer_test.py | 29 ++ tests_gui_local/onionshare_timer_test.py | 39 --- 15 files changed, 389 insertions(+), 413 deletions(-) create mode 100644 tests_gui_local/GuiReceiveTest.py create mode 100644 tests_gui_local/GuiShareTest.py create mode 100644 tests_gui_local/onionshare_receive_mode_upload_public_mode_test.py delete mode 100644 tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py create mode 100644 tests_gui_local/onionshare_share_mode_download_public_mode_test.py create mode 100644 tests_gui_local/onionshare_share_mode_download_stay_open_test.py delete mode 100644 tests_gui_local/onionshare_share_mode_download_test_public_mode.py delete mode 100644 tests_gui_local/onionshare_share_mode_download_test_stay_open.py rename tests_gui_local/{onionshare_slug_persistent_test.py => onionshare_share_mode_slug_persistent_test.py} (61%) create mode 100644 tests_gui_local/onionshare_share_mode_timer_test.py delete mode 100644 tests_gui_local/onionshare_timer_test.py diff --git a/tests_gui_local/GuiBaseTest.py b/tests_gui_local/GuiBaseTest.py index e7d25031..8a8b127e 100644 --- a/tests_gui_local/GuiBaseTest.py +++ b/tests_gui_local/GuiBaseTest.py @@ -1,10 +1,9 @@ +import json import os import requests +import shutil import socket import socks -import zipfile -import json -import shutil from PyQt5 import QtCore, QtTest @@ -59,24 +58,28 @@ class GuiBaseTest(object): except: pass - - def test_gui_loaded(self): + + def gui_loaded(self): '''Test that the GUI actually is shown''' self.assertTrue(self.gui.show) - def test_windowTitle_seen(self): + + def windowTitle_seen(self): '''Test that the window title is OnionShare''' self.assertEqual(self.gui.windowTitle(), 'OnionShare') - def test_settings_button_is_visible(self): + + def settings_button_is_visible(self): '''Test that the settings button is visible''' self.assertTrue(self.gui.settings_button.isVisible()) - def test_server_status_bar_is_visible(self): + + def server_status_bar_is_visible(self): '''Test that the status bar is visible''' self.assertTrue(self.gui.status_bar.isVisible()) - def test_click_mode(self, mode): + + def click_mode(self, mode): '''Test that we can switch Mode by clicking the button''' if type(mode) == ReceiveMode: QtTest.QTest.mouseClick(self.gui.receive_mode_button, QtCore.Qt.LeftButton) @@ -85,13 +88,15 @@ class GuiBaseTest(object): QtTest.QTest.mouseClick(self.gui.share_mode_button, QtCore.Qt.LeftButton) self.assertTrue(self.gui.mode, self.gui.MODE_SHARE) - def test_click_toggle_history(self, mode): + + def click_toggle_history(self, mode): '''Test that we can toggle Download or Upload history by clicking the toggle button''' currently_visible = mode.history.isVisible() QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton) self.assertEqual(mode.history.isVisible(), not currently_visible) - def test_history_indicator(self, mode, public_mode): + + def history_indicator(self, mode, public_mode): '''Test that we can make sure the history is toggled off, do an action, and the indiciator works''' # Make sure history is toggled off if mode.history.isVisible(): @@ -128,63 +133,75 @@ class GuiBaseTest(object): QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton) self.assertFalse(mode.toggle_history.indicator_label.isVisible()) - def test_history_is_not_visible(self, mode): + + def history_is_not_visible(self, mode): '''Test that the History section is not visible''' self.assertFalse(mode.history.isVisible()) - def test_history_is_visible(self, mode): + + def history_is_visible(self, mode): '''Test that the History section is visible''' self.assertTrue(mode.history.isVisible()) - def test_server_working_on_start_button_pressed(self, mode): + + def server_working_on_start_button_pressed(self, mode): '''Test we can start the service''' # Should be in SERVER_WORKING state QtTest.QTest.mouseClick(mode.server_status.server_button, QtCore.Qt.LeftButton) self.assertEqual(mode.server_status.status, 1) - def test_server_status_indicator_says_starting(self, mode): + + def server_status_indicator_says_starting(self, mode): '''Test that the Server Status indicator shows we are Starting''' self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) - def test_settings_button_is_hidden(self): + + def settings_button_is_hidden(self): '''Test that the settings button is hidden when the server starts''' self.assertFalse(self.gui.settings_button.isVisible()) - def test_a_server_is_started(self, mode): + + def a_server_is_started(self, mode): '''Test that the server has started''' QtTest.QTest.qWait(2000) # Should now be in SERVER_STARTED state self.assertEqual(mode.server_status.status, 2) - def test_a_web_server_is_running(self): + + def a_web_server_is_running(self): '''Test that the web server has started''' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.assertEqual(sock.connect_ex(('127.0.0.1',self.gui.app.port)), 0) - def test_have_a_slug(self, mode, public_mode): + + def have_a_slug(self, mode, public_mode): '''Test that we have a valid slug''' if not public_mode: self.assertRegex(mode.server_status.web.slug, r'(\w+)-(\w+)') else: self.assertIsNone(mode.server_status.web.slug, r'(\w+)-(\w+)') - def test_url_description_shown(self, mode): + + def url_description_shown(self, mode): '''Test that the URL label is showing''' self.assertTrue(mode.server_status.url_description.isVisible()) - def test_have_copy_url_button(self, mode): + + def have_copy_url_button(self, mode): '''Test that the Copy URL button is shown''' self.assertTrue(mode.server_status.copy_url_button.isVisible()) - def test_server_status_indicator_says_started(self, mode): + + def server_status_indicator_says_started(self, mode): '''Test that the Server Status indicator shows we are started''' if type(mode) == ReceiveMode: self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_receive_started')) if type(mode) == ShareMode: self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_share_started')) - def test_web_page(self, mode, string, public_mode): + + def web_page(self, mode, string, public_mode): '''Test that the web page contains a string''' s = socks.socksocket() s.settimeout(60) @@ -212,22 +229,26 @@ class GuiBaseTest(object): self.assertTrue(string in f.read()) f.close() - def test_history_widgets_present(self, mode): + + def history_widgets_present(self, mode): '''Test that the relevant widgets are present in the history view after activity has taken place''' self.assertFalse(mode.history.empty.isVisible()) self.assertTrue(mode.history.not_empty.isVisible()) - def test_counter_incremented(self, mode, count): + + def counter_incremented(self, mode, count): '''Test that the counter has incremented''' self.assertEquals(mode.history.completed_count, count) - def test_server_is_stopped(self, mode, stay_open): + + def server_is_stopped(self, mode, stay_open): '''Test that the server stops when we click Stop''' if type(mode) == ReceiveMode or (type(mode) == ShareMode and stay_open): QtTest.QTest.mouseClick(mode.server_status.server_button, QtCore.Qt.LeftButton) self.assertEquals(mode.server_status.status, 0) - def test_web_service_is_stopped(self): + + def web_service_is_stopped(self): '''Test that the web server also stopped''' QtTest.QTest.qWait(2000) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -235,7 +256,8 @@ class GuiBaseTest(object): # We should be closed by now. Fail if not! self.assertNotEqual(sock.connect_ex(('127.0.0.1',self.gui.app.port)), 0) - def test_server_status_indicator_says_closed(self, mode, stay_open): + + def server_status_indicator_says_closed(self, mode, stay_open): '''Test that the Server Status indicator shows we closed''' if type(mode) == ReceiveMode: self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped')) @@ -245,184 +267,10 @@ class GuiBaseTest(object): else: self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically')) - # Auto-stop timer tests - def test_set_timeout(self, mode, timeout): - '''Test that the timeout can be set''' - timer = QtCore.QDateTime.currentDateTime().addSecs(timeout) - mode.server_status.shutdown_timeout.setDateTime(timer) - self.assertTrue(mode.server_status.shutdown_timeout.dateTime(), timer) - - def test_timeout_widget_hidden(self, mode): - '''Test that the timeout widget is hidden when share has started''' - self.assertFalse(mode.server_status.shutdown_timeout_container.isVisible()) - - def test_server_timed_out(self, mode, wait): - '''Test that the server has timed out after the timer ran out''' - QtTest.QTest.qWait(wait) - # We should have timed out now - self.assertEqual(mode.server_status.status, 0) - - # Receive-specific tests - def test_upload_file(self, public_mode, expected_file): - '''Test that we can upload the file''' - files = {'file[]': open('/tmp/test.txt', 'rb')} - if not public_mode: - path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug) - else: - path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port) - response = requests.post(path, files=files) - QtTest.QTest.qWait(2000) - self.assertTrue(os.path.isfile(expected_file)) - - # Share-specific tests - def test_file_selection_widget_has_a_file(self): - '''Test that the number of files in the list is 1''' - self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 1) - - def test_deleting_only_file_hides_delete_button(self): - '''Test that clicking on the file item shows the delete button. Test that deleting the only item in the list hides the delete button''' - rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0)) - QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center()) - # Delete button should be visible - self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) - # Click delete, and since there's no more files, the delete button should be hidden - QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton) - self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) - - def test_add_a_file_and_delete_using_its_delete_widget(self): - '''Test that we can also delete a file by clicking on its [X] widget''' - self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts') - QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.item(0).item_button, QtCore.Qt.LeftButton) - self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 0) - - def test_file_selection_widget_readd_files(self): - '''Re-add some files to the list so we can share''' - self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts') - self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/test.txt') - self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2) - - def test_add_delete_buttons_hidden(self): - '''Test that the add and delete buttons are hidden when the server starts''' - self.assertFalse(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) - self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) - - def test_download_share(self, public_mode): - '''Test that we can download the share''' - s = socks.socksocket() - s.settimeout(60) - s.connect(('127.0.0.1', self.gui.app.port)) - - if public_mode: - path = '/download' - else: - path = '{}/download'.format(self.gui.share_mode.web.slug) - - http_request = 'GET {} HTTP/1.0\r\n'.format(path) - http_request += 'Host: 127.0.0.1\r\n' - http_request += '\r\n' - s.sendall(http_request.encode('utf-8')) - - with open('/tmp/download.zip', 'wb') as file_to_write: - while True: - data = s.recv(1024) - if not data: - break - file_to_write.write(data) - file_to_write.close() - - zip = zipfile.ZipFile('/tmp/download.zip') - QtTest.QTest.qWait(2000) - self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8')) - - def test_add_button_visible(self): - '''Test that the add button should be visible''' - self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) - - - # The following are 'groupings' of tests used by other objects that inherit GuiBaseTest - def run_all_common_setup_tests(self): - GuiBaseTest.test_gui_loaded(self) - GuiBaseTest.test_windowTitle_seen(self) - GuiBaseTest.test_settings_button_is_visible(self) - GuiBaseTest.test_server_status_bar_is_visible(self) + self.gui_loaded() + self.windowTitle_seen() + self.settings_button_is_visible() + self.server_status_bar_is_visible() - def run_all_share_mode_setup_tests(self): - """Tests in share mode prior to starting a share""" - GuiBaseTest.test_click_mode(self, self.gui.share_mode) - GuiBaseTest.test_file_selection_widget_has_a_file(self) - GuiBaseTest.test_history_is_not_visible(self, self.gui.share_mode) - GuiBaseTest.test_click_toggle_history(self, self.gui.share_mode) - GuiBaseTest.test_history_is_visible(self, self.gui.share_mode) - GuiBaseTest.test_deleting_only_file_hides_delete_button(self) - GuiBaseTest.test_add_a_file_and_delete_using_its_delete_widget(self) - GuiBaseTest.test_file_selection_widget_readd_files(self) - def run_all_share_mode_started_tests(self, public_mode): - """Tests in share mode after starting a share""" - GuiBaseTest.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - GuiBaseTest.test_server_status_indicator_says_starting(self, self.gui.share_mode) - GuiBaseTest.test_add_delete_buttons_hidden(self) - GuiBaseTest.test_settings_button_is_hidden(self) - GuiBaseTest.test_a_server_is_started(self, self.gui.share_mode) - GuiBaseTest.test_a_web_server_is_running(self) - GuiBaseTest.test_have_a_slug(self, self.gui.share_mode, public_mode) - GuiBaseTest.test_url_description_shown(self, self.gui.share_mode) - GuiBaseTest.test_have_copy_url_button(self, self.gui.share_mode) - GuiBaseTest.test_server_status_indicator_says_started(self, self.gui.share_mode) - GuiBaseTest.test_web_page(self, self.gui.share_mode, 'Total size', public_mode) - - def run_all_share_mode_download_tests(self, public_mode, stay_open): - """Tests in share mode after downloading a share""" - GuiBaseTest.test_download_share(self, public_mode) - GuiBaseTest.test_history_widgets_present(self, self.gui.share_mode) - GuiBaseTest.test_server_is_stopped(self, self.gui.share_mode, stay_open) - GuiBaseTest.test_web_service_is_stopped(self) - GuiBaseTest.test_server_status_indicator_says_closed(self, self.gui.share_mode, stay_open) - GuiBaseTest.test_add_button_visible(self) - GuiBaseTest.test_server_working_on_start_button_pressed(self, self.gui.share_mode) - GuiBaseTest.test_a_server_is_started(self, self.gui.share_mode) - GuiBaseTest.test_history_indicator(self, self.gui.share_mode, public_mode) - - def run_all_share_mode_tests(self, public_mode, stay_open): - """End-to-end share tests""" - GuiBaseTest.run_all_share_mode_setup_tests(self) - GuiBaseTest.run_all_share_mode_started_tests(self, public_mode) - GuiBaseTest.run_all_share_mode_download_tests(self, public_mode, stay_open) - - def run_all_share_mode_timer_tests(self, public_mode): - """Auto-stop timer tests in share mode""" - GuiBaseTest.run_all_share_mode_setup_tests(self) - GuiBaseTest.test_set_timeout(self, self.gui.share_mode, 5) - GuiBaseTest.run_all_share_mode_started_tests(self, public_mode) - GuiBaseTest.test_timeout_widget_hidden(self, self.gui.share_mode) - GuiBaseTest.test_server_timed_out(self, self.gui.share_mode, 10000) - GuiBaseTest.test_web_service_is_stopped(self) - - def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): - GuiBaseTest.test_click_mode(self, self.gui.receive_mode) - GuiBaseTest.test_history_is_not_visible(self, self.gui.receive_mode) - GuiBaseTest.test_click_toggle_history(self, self.gui.receive_mode) - GuiBaseTest.test_history_is_visible(self, self.gui.receive_mode) - GuiBaseTest.test_server_working_on_start_button_pressed(self, self.gui.receive_mode) - GuiBaseTest.test_server_status_indicator_says_starting(self, self.gui.receive_mode) - GuiBaseTest.test_settings_button_is_hidden(self) - GuiBaseTest.test_a_server_is_started(self, self.gui.receive_mode) - GuiBaseTest.test_a_web_server_is_running(self) - GuiBaseTest.test_have_a_slug(self, self.gui.receive_mode, public_mode) - GuiBaseTest.test_url_description_shown(self, self.gui.receive_mode) - GuiBaseTest.test_have_copy_url_button(self, self.gui.receive_mode) - GuiBaseTest.test_server_status_indicator_says_started(self, self.gui.receive_mode) - GuiBaseTest.test_web_page(self, self.gui.receive_mode, 'Select the files you want to send, then click', public_mode) - GuiBaseTest.test_upload_file(self, public_mode, '/tmp/OnionShare/test.txt') - GuiBaseTest.test_history_widgets_present(self, self.gui.receive_mode) - GuiBaseTest.test_counter_incremented(self, self.gui.receive_mode, 1) - GuiBaseTest.test_upload_file(self, public_mode, '/tmp/OnionShare/test-2.txt') - GuiBaseTest.test_counter_incremented(self, self.gui.receive_mode, 2) - GuiBaseTest.test_history_indicator(self, self.gui.receive_mode, public_mode) - GuiBaseTest.test_server_is_stopped(self, self.gui.receive_mode, False) - GuiBaseTest.test_web_service_is_stopped(self) - GuiBaseTest.test_server_status_indicator_says_closed(self, self.gui.receive_mode, False) - GuiBaseTest.test_server_working_on_start_button_pressed(self, self.gui.receive_mode) - GuiBaseTest.test_a_server_is_started(self, self.gui.receive_mode) - GuiBaseTest.test_history_indicator(self, self.gui.receive_mode, public_mode) diff --git a/tests_gui_local/GuiReceiveTest.py b/tests_gui_local/GuiReceiveTest.py new file mode 100644 index 00000000..1fa5c4dc --- /dev/null +++ b/tests_gui_local/GuiReceiveTest.py @@ -0,0 +1,45 @@ +import os +import requests +from PyQt5 import QtTest +from .GuiBaseTest import GuiBaseTest + +class GuiReceiveTest(GuiBaseTest): + def upload_file(self, public_mode, expected_file): + '''Test that we can upload the file''' + files = {'file[]': open('/tmp/test.txt', 'rb')} + if not public_mode: + path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug) + else: + path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port) + response = requests.post(path, files=files) + QtTest.QTest.qWait(2000) + self.assertTrue(os.path.isfile(expected_file)) + + def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): + self.click_mode(self.gui.receive_mode) + self.history_is_not_visible(self.gui.receive_mode) + self.click_toggle_history(self.gui.receive_mode) + self.history_is_visible(self.gui.receive_mode) + self.server_working_on_start_button_pressed(self.gui.receive_mode) + self.server_status_indicator_says_starting(self.gui.receive_mode) + self.settings_button_is_hidden() + self.a_server_is_started(self.gui.receive_mode) + self.a_web_server_is_running() + self.have_a_slug(self.gui.receive_mode, public_mode) + self.url_description_shown(self.gui.receive_mode) + self.have_copy_url_button(self.gui.receive_mode) + self.server_status_indicator_says_started(self.gui.receive_mode) + self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode) + self.upload_file(public_mode, '/tmp/OnionShare/test.txt') + self.history_widgets_present(self.gui.receive_mode) + self.counter_incremented(self.gui.receive_mode, 1) + self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt') + self.counter_incremented(self.gui.receive_mode, 2) + self.history_indicator(self.gui.receive_mode, public_mode) + self.server_is_stopped(self.gui.receive_mode, False) + self.web_service_is_stopped() + self.server_status_indicator_says_closed(self.gui.receive_mode, False) + self.server_working_on_start_button_pressed(self.gui.receive_mode) + self.a_server_is_started(self.gui.receive_mode) + self.history_indicator(self.gui.receive_mode, public_mode) + diff --git a/tests_gui_local/GuiShareTest.py b/tests_gui_local/GuiShareTest.py new file mode 100644 index 00000000..8c3ea2b1 --- /dev/null +++ b/tests_gui_local/GuiShareTest.py @@ -0,0 +1,154 @@ +import socks +import zipfile +from PyQt5 import QtCore, QtTest +from .GuiBaseTest import GuiBaseTest + +class GuiShareTest(GuiBaseTest): + # Auto-stop timer tests + + def set_timeout(self, mode, timeout): + '''Test that the timeout can be set''' + timer = QtCore.QDateTime.currentDateTime().addSecs(timeout) + mode.server_status.shutdown_timeout.setDateTime(timer) + self.assertTrue(mode.server_status.shutdown_timeout.dateTime(), timer) + + + def timeout_widget_hidden(self, mode): + '''Test that the timeout widget is hidden when share has started''' + self.assertFalse(mode.server_status.shutdown_timeout_container.isVisible()) + + + def server_timed_out(self, mode, wait): + '''Test that the server has timed out after the timer ran out''' + QtTest.QTest.qWait(wait) + # We should have timed out now + self.assertEqual(mode.server_status.status, 0) + + # Share-specific tests + + def file_selection_widget_has_a_file(self): + '''Test that the number of files in the list is 1''' + self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 1) + + + def deleting_only_file_hides_delete_button(self): + '''Test that clicking on the file item shows the delete button. Test that deleting the only item in the list hides the delete button''' + rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0)) + QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center()) + # Delete button should be visible + self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) + # Click delete, and since there's no more files, the delete button should be hidden + QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton) + self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) + + + def add_a_file_and_delete_using_its_delete_widget(self): + '''Test that we can also delete a file by clicking on its [X] widget''' + self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts') + QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.item(0).item_button, QtCore.Qt.LeftButton) + self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 0) + + + def file_selection_widget_readd_files(self): + '''Re-add some files to the list so we can share''' + self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts') + self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/test.txt') + self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2) + + + def add_delete_buttons_hidden(self): + '''Test that the add and delete buttons are hidden when the server starts''' + self.assertFalse(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) + self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) + + + def download_share(self, public_mode): + '''Test that we can download the share''' + s = socks.socksocket() + s.settimeout(60) + s.connect(('127.0.0.1', self.gui.app.port)) + + if public_mode: + path = '/download' + else: + path = '{}/download'.format(self.gui.share_mode.web.slug) + + http_request = 'GET {} HTTP/1.0\r\n'.format(path) + http_request += 'Host: 127.0.0.1\r\n' + http_request += '\r\n' + s.sendall(http_request.encode('utf-8')) + + with open('/tmp/download.zip', 'wb') as file_to_write: + while True: + data = s.recv(1024) + if not data: + break + file_to_write.write(data) + file_to_write.close() + + zip = zipfile.ZipFile('/tmp/download.zip') + QtTest.QTest.qWait(2000) + self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8')) + + + def add_button_visible(self): + '''Test that the add button should be visible''' + self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) + + + def run_all_share_mode_setup_tests(self): + """Tests in share mode prior to starting a share""" + self.click_mode(self.gui.share_mode) + self.file_selection_widget_has_a_file() + self.history_is_not_visible(self.gui.share_mode) + self.click_toggle_history(self.gui.share_mode) + self.history_is_visible(self.gui.share_mode) + self.deleting_only_file_hides_delete_button() + self.add_a_file_and_delete_using_its_delete_widget() + self.file_selection_widget_readd_files() + + + def run_all_share_mode_started_tests(self, public_mode): + """Tests in share mode after starting a share""" + self.server_working_on_start_button_pressed(self.gui.share_mode) + self.server_status_indicator_says_starting(self.gui.share_mode) + self.add_delete_buttons_hidden() + self.settings_button_is_hidden() + self.a_server_is_started(self.gui.share_mode) + self.a_web_server_is_running() + self.have_a_slug(self.gui.share_mode, public_mode) + self.url_description_shown(self.gui.share_mode) + self.have_copy_url_button(self.gui.share_mode) + self.server_status_indicator_says_started(self.gui.share_mode) + self.web_page(self.gui.share_mode, 'Total size', public_mode) + + + def run_all_share_mode_download_tests(self, public_mode, stay_open): + """Tests in share mode after downloading a share""" + self.download_share(public_mode) + self.history_widgets_present(self.gui.share_mode) + self.server_is_stopped(self.gui.share_mode, stay_open) + self.web_service_is_stopped() + self.server_status_indicator_says_closed(self.gui.share_mode, stay_open) + self.add_button_visible() + self.server_working_on_start_button_pressed(self.gui.share_mode) + self.a_server_is_started(self.gui.share_mode) + self.history_indicator(self.gui.share_mode, public_mode) + + + def run_all_share_mode_tests(self, public_mode, stay_open): + """End-to-end share tests""" + self.run_all_share_mode_setup_tests() + self.run_all_share_mode_started_tests(public_mode) + self.run_all_share_mode_download_tests(public_mode, stay_open) + + + def run_all_share_mode_timer_tests(self, public_mode): + """Auto-stop timer tests in share mode""" + self.run_all_share_mode_setup_tests() + self.set_timeout(self.gui.share_mode, 5) + self.run_all_share_mode_started_tests(public_mode) + self.timeout_widget_hidden(self.gui.share_mode) + self.server_timed_out(self.gui.share_mode, 10000) + self.web_service_is_stopped() + diff --git a/tests_gui_local/__init__.py b/tests_gui_local/__init__.py index 7cf168eb..e69de29b 100644 --- a/tests_gui_local/__init__.py +++ b/tests_gui_local/__init__.py @@ -1 +0,0 @@ -from .GuiBaseTest import GuiBaseTest 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 new file mode 100644 index 00000000..f41a2ce2 --- /dev/null +++ b/tests_gui_local/onionshare_receive_mode_upload_public_mode_test.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .GuiReceiveTest import GuiReceiveTest + +class ReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": True, + "receive_allow_receiver_shutdown": True + } + cls.gui = GuiReceiveTest.set_up(test_settings) + + @classmethod + def tearDownClass(cls): + GuiReceiveTest.tear_down() + + @pytest.mark.run(order=1) + def test_run_all_common_setup_tests(self): + GuiReceiveTest.run_all_common_setup_tests(self) + + @pytest.mark.run(order=2) + def test_run_all_receive_mode_tests(self): + GuiReceiveTest.run_all_receive_mode_tests(self, 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 262c7aba..8a7661dd 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test.py @@ -1,38 +1,28 @@ #!/usr/bin/env python3 -import os -import sys -import unittest import pytest -import json +import unittest -from PyQt5 import QtWidgets +from .GuiReceiveTest import GuiReceiveTest -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .GuiBaseTest import GuiBaseTest - -class ReceiveModeTest(unittest.TestCase): +class ReceiveModeTest(unittest.TestCase, GuiReceiveTest): @classmethod def setUpClass(cls): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): - GuiBaseTest.tear_down() + GuiReceiveTest.tear_down() @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): - GuiBaseTest.run_all_common_setup_tests(self) + GuiReceiveTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) - def test_run_all_share_mode_tests(self): - GuiBaseTest.run_all_receive_mode_tests(self, False, True) + def test_run_all_receive_mode_tests(self): + GuiReceiveTest.run_all_receive_mode_tests(self, False, True) if __name__ == "__main__": unittest.main() diff --git a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py b/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py deleted file mode 100644 index 201402c2..00000000 --- a/tests_gui_local/onionshare_receive_mode_upload_test_public_mode.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .GuiBaseTest import GuiBaseTest - -class ReceiveModePublicModeTest(unittest.TestCase): - @classmethod - def setUpClass(cls): - test_settings = { - "public_mode": True, - "receive_allow_receiver_shutdown": True - } - cls.gui = GuiBaseTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiBaseTest.tear_down() - - @pytest.mark.run(order=1) - def test_run_all_common_setup_tests(self): - GuiBaseTest.run_all_common_setup_tests(self) - - @pytest.mark.run(order=2) - def test_run_all_share_mode_tests(self): - GuiBaseTest.run_all_receive_mode_tests(self, True, 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 new file mode 100644 index 00000000..53d1fb8c --- /dev/null +++ b/tests_gui_local/onionshare_share_mode_download_public_mode_test.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .GuiShareTest import GuiShareTest + +class ShareModePublicModeTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": True, + } + cls.gui = GuiShareTest.set_up(test_settings) + + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + + @pytest.mark.run(order=1) + def test_run_all_common_setup_tests(self): + GuiShareTest.run_all_common_setup_tests(self) + + @pytest.mark.run(order=2) + def test_run_all_share_mode_tests(self): + GuiShareTest.run_all_share_mode_tests(self, 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 new file mode 100644 index 00000000..b398f654 --- /dev/null +++ b/tests_gui_local/onionshare_share_mode_download_stay_open_test.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .GuiShareTest import GuiShareTest + +class ShareModeStayOpenTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "close_after_first_download": False, + } + cls.gui = GuiShareTest.set_up(test_settings) + + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + + @pytest.mark.run(order=1) + def test_run_all_common_setup_tests(self): + GuiShareTest.run_all_common_setup_tests(self) + + @pytest.mark.run(order=2) + def test_run_all_share_mode_tests(self): + GuiShareTest.run_all_share_mode_tests(self, 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 b24a3a78..34532c59 100644 --- a/tests_gui_local/onionshare_share_mode_download_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test.py @@ -1,37 +1,27 @@ #!/usr/bin/env python3 -import os -import sys -import unittest import pytest -import json +import unittest -from PyQt5 import QtWidgets +from .GuiShareTest import GuiShareTest -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .GuiBaseTest import GuiBaseTest - -class ShareModeTest(unittest.TestCase): +class ShareModeTest(unittest.TestCase, GuiShareTest): @classmethod def setUpClass(cls): test_settings = { } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): - GuiBaseTest.tear_down() + GuiShareTest.tear_down() @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): - GuiBaseTest.run_all_common_setup_tests(self) + GuiShareTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) def test_run_all_share_mode_tests(self): - GuiBaseTest.run_all_share_mode_tests(self, False, False) + GuiShareTest.run_all_share_mode_tests(self, False, False) if __name__ == "__main__": unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_download_test_public_mode.py b/tests_gui_local/onionshare_share_mode_download_test_public_mode.py deleted file mode 100644 index e59b53f4..00000000 --- a/tests_gui_local/onionshare_share_mode_download_test_public_mode.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .GuiBaseTest import GuiBaseTest - -class ShareModePublicModeTest(unittest.TestCase): - @classmethod - def setUpClass(cls): - test_settings = { - "public_mode": True, - } - cls.gui = GuiBaseTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiBaseTest.tear_down() - - @pytest.mark.run(order=1) - def test_run_all_common_setup_tests(self): - GuiBaseTest.run_all_common_setup_tests(self) - - @pytest.mark.run(order=2) - def test_run_all_share_mode_tests(self): - GuiBaseTest.run_all_share_mode_tests(self, True, False) - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_local/onionshare_share_mode_download_test_stay_open.py b/tests_gui_local/onionshare_share_mode_download_test_stay_open.py deleted file mode 100644 index 9394c34a..00000000 --- a/tests_gui_local/onionshare_share_mode_download_test_stay_open.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .GuiBaseTest import GuiBaseTest - -class ShareModeStayOpenTest(unittest.TestCase): - @classmethod - def setUpClass(cls): - test_settings = { - "close_after_first_download": False, - } - cls.gui = GuiBaseTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiBaseTest.tear_down() - - @pytest.mark.run(order=1) - def test_run_all_common_setup_tests(self): - GuiBaseTest.run_all_common_setup_tests(self) - - @pytest.mark.run(order=2) - def test_run_all_share_mode_tests(self): - GuiBaseTest.run_all_share_mode_tests(self, False, True) - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_local/onionshare_slug_persistent_test.py b/tests_gui_local/onionshare_share_mode_slug_persistent_test.py similarity index 61% rename from tests_gui_local/onionshare_slug_persistent_test.py rename to tests_gui_local/onionshare_share_mode_slug_persistent_test.py index ab845f8e..b4c92f36 100644 --- a/tests_gui_local/onionshare_slug_persistent_test.py +++ b/tests_gui_local/onionshare_share_mode_slug_persistent_test.py @@ -1,20 +1,10 @@ #!/usr/bin/env python3 -import os -import sys -import unittest import pytest -import json +import unittest -from PyQt5 import QtWidgets +from .GuiShareTest import GuiShareTest -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .GuiBaseTest import GuiBaseTest - -class ShareModePersistentSlugTest(unittest.TestCase): +class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): @classmethod def setUpClass(cls): test_settings = { @@ -23,19 +13,19 @@ class ShareModePersistentSlugTest(unittest.TestCase): "save_private_key": True, "close_after_first_download": False, } - cls.gui = GuiBaseTest.set_up(test_settings) + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): - GuiBaseTest.tear_down() + GuiShareTest.tear_down() @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): - GuiBaseTest.run_all_common_setup_tests(self) + GuiShareTest.run_all_common_setup_tests(self) @pytest.mark.run(order=2) def test_run_all_share_mode_tests(self): - GuiBaseTest.run_all_share_mode_tests(self, False, True) + GuiShareTest.run_all_share_mode_tests(self, False, True) global slug slug = self.gui.share_mode.server_status.web.slug diff --git a/tests_gui_local/onionshare_share_mode_timer_test.py b/tests_gui_local/onionshare_share_mode_timer_test.py new file mode 100644 index 00000000..98902428 --- /dev/null +++ b/tests_gui_local/onionshare_share_mode_timer_test.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .GuiShareTest import GuiShareTest + +class ShareModeTimerTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": False, + "shutdown_timeout": True, + } + cls.gui = GuiShareTest.set_up(test_settings) + + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + + @pytest.mark.run(order=1) + def test_run_all_common_setup_tests(self): + GuiShareTest.run_all_common_setup_tests(self) + + @pytest.mark.run(order=2) + def test_run_all_share_mode_timer_tests(self): + GuiShareTest.run_all_share_mode_timer_tests(self, False) + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui_local/onionshare_timer_test.py b/tests_gui_local/onionshare_timer_test.py deleted file mode 100644 index 60c616cc..00000000 --- a/tests_gui_local/onionshare_timer_test.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .GuiBaseTest import GuiBaseTest - -class ShareModeTimerTest(unittest.TestCase): - @classmethod - def setUpClass(cls): - test_settings = { - "public_mode": False, - "shutdown_timeout": True, - } - cls.gui = GuiBaseTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiBaseTest.tear_down() - - @pytest.mark.run(order=1) - def test_run_all_common_setup_tests(self): - GuiBaseTest.run_all_common_setup_tests(self) - - @pytest.mark.run(order=2) - def test_run_all_share_mode_timer_tests(self): - GuiBaseTest.run_all_share_mode_timer_tests(self, False) - -if __name__ == "__main__": - unittest.main() From 72d0c20aada8ed6d7976f7987511ff3500bbd3e0 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 11:42:40 +1100 Subject: [PATCH 05/72] Write settings json files out to unique files per test --- tests_gui_local/GuiBaseTest.py | 6 +++--- .../onionshare_receive_mode_upload_public_mode_test.py | 2 +- tests_gui_local/onionshare_receive_mode_upload_test.py | 2 +- .../onionshare_share_mode_download_public_mode_test.py | 2 +- .../onionshare_share_mode_download_stay_open_test.py | 2 +- tests_gui_local/onionshare_share_mode_download_test.py | 2 +- .../onionshare_share_mode_slug_persistent_test.py | 2 +- tests_gui_local/onionshare_share_mode_timer_test.py | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests_gui_local/GuiBaseTest.py b/tests_gui_local/GuiBaseTest.py index 8a8b127e..449a5b7e 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,8 +44,7 @@ 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) return gui @@ -54,6 +53,7 @@ class GuiBaseTest(object): def tear_down(): try: os.remove('/tmp/test.txt') + os.remove('/tmp/download.zip') shutil.rmtree('/tmp/OnionShare') except: pass 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..32ea8656 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,7 +11,7 @@ class ReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): "public_mode": 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): diff --git a/tests_gui_local/onionshare_receive_mode_upload_test.py b/tests_gui_local/onionshare_receive_mode_upload_test.py index 8a7661dd..c59ac9c0 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test.py @@ -10,7 +10,7 @@ class ReceiveModeTest(unittest.TestCase, GuiReceiveTest): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings) + cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') @classmethod def tearDownClass(cls): 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..b6ce3a3c 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,7 +10,7 @@ class ShareModePublicModeTest(unittest.TestCase, GuiShareTest): test_settings = { "public_mode": True, } - cls.gui = GuiShareTest.set_up(test_settings) + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') @classmethod def tearDownClass(cls): 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..7ff9aaf2 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,7 +10,7 @@ class ShareModeStayOpenTest(unittest.TestCase, GuiShareTest): test_settings = { "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings) + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_share_mode_download_test.py b/tests_gui_local/onionshare_share_mode_download_test.py index 34532c59..9de0a767 100644 --- a/tests_gui_local/onionshare_share_mode_download_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test.py @@ -9,7 +9,7 @@ class ShareModeTest(unittest.TestCase, GuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings) + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTest') @classmethod def tearDownClass(cls): 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..02cbdd27 100644 --- a/tests_gui_local/onionshare_share_mode_slug_persistent_test.py +++ b/tests_gui_local/onionshare_share_mode_slug_persistent_test.py @@ -13,7 +13,7 @@ class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): "save_private_key": True, "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings) + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_share_mode_timer_test.py b/tests_gui_local/onionshare_share_mode_timer_test.py index 98902428..96c48443 100644 --- a/tests_gui_local/onionshare_share_mode_timer_test.py +++ b/tests_gui_local/onionshare_share_mode_timer_test.py @@ -11,7 +11,7 @@ class ShareModeTimerTest(unittest.TestCase, GuiShareTest): "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiShareTest.set_up(test_settings) + cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTimerTest') @classmethod def tearDownClass(cls): From 26cd930ecc89c883d693664d9c019584d16d6dfa Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 11:50:12 +1100 Subject: [PATCH 06/72] Revert "Write settings json files out to unique files per test" This reverts commit 72d0c20aada8ed6d7976f7987511ff3500bbd3e0. --- tests_gui_local/GuiBaseTest.py | 6 +++--- .../onionshare_receive_mode_upload_public_mode_test.py | 2 +- tests_gui_local/onionshare_receive_mode_upload_test.py | 2 +- .../onionshare_share_mode_download_public_mode_test.py | 2 +- .../onionshare_share_mode_download_stay_open_test.py | 2 +- tests_gui_local/onionshare_share_mode_download_test.py | 2 +- .../onionshare_share_mode_slug_persistent_test.py | 2 +- tests_gui_local/onionshare_share_mode_timer_test.py | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests_gui_local/GuiBaseTest.py b/tests_gui_local/GuiBaseTest.py index 449a5b7e..8a8b127e 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, settings_filename): + def set_up(test_settings): '''Create GUI with given settings''' # Create our test file testfile = open('/tmp/test.txt', 'w') @@ -44,7 +44,8 @@ class GuiBaseTest(object): app = OnionShare(common, testonion, True, 0) web = Web(common, False, True) - open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) + settings_filename = '/tmp/testsettings.json' + open(settings_filename, 'w').write(json.dumps(test_settings)) gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True) return gui @@ -53,7 +54,6 @@ class GuiBaseTest(object): def tear_down(): try: os.remove('/tmp/test.txt') - os.remove('/tmp/download.zip') shutil.rmtree('/tmp/OnionShare') except: pass 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 32ea8656..f41a2ce2 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,7 +11,7 @@ class ReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModePublicModeTest') + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_receive_mode_upload_test.py b/tests_gui_local/onionshare_receive_mode_upload_test.py index c59ac9c0..8a7661dd 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test.py +++ b/tests_gui_local/onionshare_receive_mode_upload_test.py @@ -10,7 +10,7 @@ class ReceiveModeTest(unittest.TestCase, GuiReceiveTest): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): 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 b6ce3a3c..53d1fb8c 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,7 +10,7 @@ class ShareModePublicModeTest(unittest.TestCase, GuiShareTest): test_settings = { "public_mode": True, } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): 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 7ff9aaf2..b398f654 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,7 +10,7 @@ class ShareModeStayOpenTest(unittest.TestCase, GuiShareTest): test_settings = { "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_share_mode_download_test.py b/tests_gui_local/onionshare_share_mode_download_test.py index 9de0a767..34532c59 100644 --- a/tests_gui_local/onionshare_share_mode_download_test.py +++ b/tests_gui_local/onionshare_share_mode_download_test.py @@ -9,7 +9,7 @@ class ShareModeTest(unittest.TestCase, GuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): 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 02cbdd27..b4c92f36 100644 --- a/tests_gui_local/onionshare_share_mode_slug_persistent_test.py +++ b/tests_gui_local/onionshare_share_mode_slug_persistent_test.py @@ -13,7 +13,7 @@ class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): "save_private_key": True, "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests_gui_local/onionshare_share_mode_timer_test.py b/tests_gui_local/onionshare_share_mode_timer_test.py index 96c48443..98902428 100644 --- a/tests_gui_local/onionshare_share_mode_timer_test.py +++ b/tests_gui_local/onionshare_share_mode_timer_test.py @@ -11,7 +11,7 @@ class ShareModeTimerTest(unittest.TestCase, GuiShareTest): "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTimerTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): From 48a5d45baf62b32961a585125ab08bc655edc771 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 12:18:34 +1100 Subject: [PATCH 07/72] 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 From 910bf7e8be4fd7e34878c745eda705879e8c78dc Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 18:53:03 +1100 Subject: [PATCH 08/72] Beginning to move the Tor tests into tests_gui and inheriting what we can from the local tests to avoid code reuse. Add --runtor flag in pytest to run these --- .travis.yml | 2 +- {tests_gui_local => tests_gui}/GuiBaseTest.py | 2 +- .../GuiReceiveTest.py | 0 .../GuiShareTest.py | 2 +- tests_gui/TorGuiBaseTest.py | 154 +++++++++++++ tests_gui/TorGuiReceiveTest.py | 51 +++++ tests_gui/TorGuiShareTest.py | 70 ++++++ {tests_gui_local => tests_gui}/__init__.py | 0 {tests_gui_local => tests_gui}/conftest.py | 16 ++ ...re_receive_mode_upload_public_mode_test.py | 4 +- ...cal_onionshare_receive_mode_upload_test.py | 4 +- ...re_share_mode_download_public_mode_test.py | 4 +- ...hare_share_mode_download_stay_open_test.py | 4 +- ...cal_onionshare_share_mode_download_test.py | 4 +- ...onshare_share_mode_slug_persistent_test.py | 4 +- .../local_onionshare_share_mode_timer_test.py | 4 +- ...re_receive_mode_upload_public_mode_test.py | 27 +++ .../onionshare_receive_mode_upload_test.py | 26 +++ ...re_share_mode_download_public_mode_test.py | 26 +++ ...hare_share_mode_download_stay_open_test.py | 26 +++ .../onionshare_share_mode_download_test.py | 25 ++ .../onionshare_share_mode_persistent_test.py | 30 +++ .../onionshare_share_mode_stealth_test.py | 34 +++ ...e_share_mode_tor_connection_killed_test.py | 42 ++++ tests_gui_tor/__init__.py | 0 tests_gui_tor/commontests.py | 61 ----- tests_gui_tor/conftest.py | 163 -------------- .../onionshare_receive_mode_upload_test.py | 190 ---------------- ...re_receive_mode_upload_test_public_mode.py | 190 ---------------- .../onionshare_share_mode_download_test.py | 193 ---------------- ...re_share_mode_download_test_public_mode.py | 201 ----------------- ...hare_share_mode_download_test_stay_open.py | 213 ------------------ .../onionshare_share_mode_persistent_test.py | 185 --------------- .../onionshare_share_mode_stealth_test.py | 180 --------------- ...e_share_mode_tor_connection_killed_test.py | 185 --------------- .../onionshare_tor_connection_killed_test.py | 185 --------------- tests_gui_tor/run_unit_tests.sh | 5 - 37 files changed, 544 insertions(+), 1968 deletions(-) rename {tests_gui_local => tests_gui}/GuiBaseTest.py (99%) rename {tests_gui_local => tests_gui}/GuiReceiveTest.py (100%) rename {tests_gui_local => tests_gui}/GuiShareTest.py (100%) create mode 100644 tests_gui/TorGuiBaseTest.py create mode 100644 tests_gui/TorGuiReceiveTest.py create mode 100644 tests_gui/TorGuiShareTest.py rename {tests_gui_local => tests_gui}/__init__.py (100%) rename {tests_gui_local => tests_gui}/conftest.py (89%) rename tests_gui_local/onionshare_receive_mode_upload_public_mode_test.py => tests_gui/local_onionshare_receive_mode_upload_public_mode_test.py (77%) rename tests_gui_local/onionshare_receive_mode_upload_test.py => tests_gui/local_onionshare_receive_mode_upload_test.py (78%) rename tests_gui_local/onionshare_share_mode_download_public_mode_test.py => tests_gui/local_onionshare_share_mode_download_public_mode_test.py (76%) rename tests_gui_local/onionshare_share_mode_download_stay_open_test.py => tests_gui/local_onionshare_share_mode_download_stay_open_test.py (77%) rename tests_gui_local/onionshare_share_mode_download_test.py => tests_gui/local_onionshare_share_mode_download_test.py (77%) rename tests_gui_local/onionshare_share_mode_slug_persistent_test.py => tests_gui/local_onionshare_share_mode_slug_persistent_test.py (79%) rename tests_gui_local/onionshare_share_mode_timer_test.py => tests_gui/local_onionshare_share_mode_timer_test.py (79%) create mode 100644 tests_gui/onionshare_receive_mode_upload_public_mode_test.py create mode 100644 tests_gui/onionshare_receive_mode_upload_test.py create mode 100644 tests_gui/onionshare_share_mode_download_public_mode_test.py create mode 100644 tests_gui/onionshare_share_mode_download_stay_open_test.py create mode 100644 tests_gui/onionshare_share_mode_download_test.py create mode 100644 tests_gui/onionshare_share_mode_persistent_test.py create mode 100644 tests_gui/onionshare_share_mode_stealth_test.py create mode 100644 tests_gui/onionshare_share_mode_tor_connection_killed_test.py delete mode 100644 tests_gui_tor/__init__.py delete mode 100644 tests_gui_tor/commontests.py delete mode 100644 tests_gui_tor/conftest.py delete mode 100644 tests_gui_tor/onionshare_receive_mode_upload_test.py delete mode 100644 tests_gui_tor/onionshare_receive_mode_upload_test_public_mode.py delete mode 100644 tests_gui_tor/onionshare_share_mode_download_test.py delete mode 100644 tests_gui_tor/onionshare_share_mode_download_test_public_mode.py delete mode 100644 tests_gui_tor/onionshare_share_mode_download_test_stay_open.py delete mode 100644 tests_gui_tor/onionshare_share_mode_persistent_test.py delete mode 100644 tests_gui_tor/onionshare_share_mode_stealth_test.py delete mode 100644 tests_gui_tor/onionshare_share_mode_tor_connection_killed_test.py delete mode 100644 tests_gui_tor/onionshare_tor_connection_killed_test.py delete mode 100755 tests_gui_tor/run_unit_tests.sh diff --git a/.travis.yml b/.travis.yml index 5750536d..c54c205d 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/ - - xvfb-run pytest tests_gui_local/ + - xvfb-run pytest tests_gui/ -vvv diff --git a/tests_gui_local/GuiBaseTest.py b/tests_gui/GuiBaseTest.py similarity index 99% rename from tests_gui_local/GuiBaseTest.py rename to tests_gui/GuiBaseTest.py index 138a279a..79543468 100644 --- a/tests_gui_local/GuiBaseTest.py +++ b/tests_gui/GuiBaseTest.py @@ -120,7 +120,7 @@ class GuiBaseTest(object): if public_mode: url = "http://127.0.0.1:{}/download".format(self.gui.app.port) else: - url = "http://127.0.0.1:{}/{}/download".format(self.gui.app.port, self.gui.share_mode.web.slug) + url = "http://127.0.0.1:{}/{}/download".format(self.gui.app.port, mode.web.slug) r = requests.get(url) QtTest.QTest.qWait(2000) diff --git a/tests_gui_local/GuiReceiveTest.py b/tests_gui/GuiReceiveTest.py similarity index 100% rename from tests_gui_local/GuiReceiveTest.py rename to tests_gui/GuiReceiveTest.py diff --git a/tests_gui_local/GuiShareTest.py b/tests_gui/GuiShareTest.py similarity index 100% rename from tests_gui_local/GuiShareTest.py rename to tests_gui/GuiShareTest.py index 11df3167..34149dec 100644 --- a/tests_gui_local/GuiShareTest.py +++ b/tests_gui/GuiShareTest.py @@ -125,11 +125,11 @@ class GuiShareTest(GuiBaseTest): self.url_description_shown(self.gui.share_mode) self.have_copy_url_button(self.gui.share_mode) self.server_status_indicator_says_started(self.gui.share_mode) - self.web_page(self.gui.share_mode, 'Total size', public_mode) def run_all_share_mode_download_tests(self, public_mode, stay_open): """Tests in share mode after downloading a share""" + self.web_page(self.gui.share_mode, 'Total size', public_mode) self.download_share(public_mode) self.history_widgets_present(self.gui.share_mode) self.server_is_stopped(self.gui.share_mode, stay_open) diff --git a/tests_gui/TorGuiBaseTest.py b/tests_gui/TorGuiBaseTest.py new file mode 100644 index 00000000..1c313726 --- /dev/null +++ b/tests_gui/TorGuiBaseTest.py @@ -0,0 +1,154 @@ +import json +import os +import requests +import shutil +import socket +import socks + +from PyQt5 import QtCore, QtTest + +from onionshare import strings +from onionshare.common import Common +from onionshare.settings import Settings +from onionshare.onion import Onion +from onionshare.web import Web +from onionshare_gui import Application, OnionShare, OnionShareGui +from onionshare_gui.mode.share_mode import ShareMode +from onionshare_gui.mode.receive_mode import ReceiveMode + +from .GuiBaseTest import GuiBaseTest + +class TorGuiBaseTest(GuiBaseTest): + @staticmethod + def set_up(test_settings, settings_filename): + '''Create GUI with given settings''' + # Create our test file + testfile = open('/tmp/test.txt', 'w') + testfile.write('onionshare') + testfile.close() + + common = Common() + common.settings = Settings(common) + common.define_css() + strings.load_strings(common) + + # Get all of the settings in test_settings + test_settings['connection_type'] = 'automatic' + test_settings['downloads_dir'] = '/tmp/OnionShare' + for key, val in common.settings.default_settings.items(): + if key not in test_settings: + test_settings[key] = val + + # Start the Onion + testonion = Onion(common) + global qtapp + qtapp = Application(common) + app = OnionShare(common, testonion, False, 0) + + web = Web(common, False, False) + open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) + + gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], '/tmp/{}.json'.format(settings_filename), False) + return gui + + def history_indicator(self, mode, public_mode): + '''Test that we can make sure the history is toggled off, do an action, and the indiciator works''' + # Make sure history is toggled off + if mode.history.isVisible(): + QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton) + self.assertFalse(mode.history.isVisible()) + + # Indicator should not be visible yet + self.assertFalse(mode.toggle_history.indicator_label.isVisible()) + + # Set up connecting to the onion + (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port() + session = requests.session() + session.proxies = {} + session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port) + + if type(mode) == ReceiveMode: + # Upload a file + files = {'file[]': open('/tmp/test.txt', 'rb')} + if not public_mode: + path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, mode.web.slug) + else: + path = 'http://{}/upload'.format(self.gui.app.onion_host) + response = session.post(path, files=files) + QtTest.QTest.qWait(4000) + + if type(mode) == ShareMode: + # Download files + if public_mode: + path = "http://{}/download".format(self.gui.app.onion_host) + else: + path = "http://{}/{}/download".format(self.gui.app.onion_host, mode.web.slug) + response = session.get(path) + QtTest.QTest.qWait(4000) + + # Indicator should be visible, have a value of "1" + self.assertTrue(mode.toggle_history.indicator_label.isVisible()) + self.assertEqual(mode.toggle_history.indicator_label.text(), "1") + + # Toggle history back on, indicator should be hidden again + QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton) + self.assertFalse(mode.toggle_history.indicator_label.isVisible()) + + def a_server_is_started(self, mode): + '''Test that the server has started (overriding from local tests to wait for longer)''' + QtTest.QTest.qWait(45000) + # Should now be in SERVER_STARTED state + self.assertEqual(mode.server_status.status, 2) + + def have_an_onion_service(self): + '''Test that we have a valid Onion URL''' + self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion') + + def web_page(self, mode, string, public_mode): + '''Test that the web page contains a string''' + (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port() + socks.set_default_proxy(socks.SOCKS5, socks_address, socks_port) + s = socks.socksocket() + s.settimeout(60) + s.connect((self.gui.app.onion_host, 80)) + if not public_mode: + path = '/{}'.format(mode.server_status.web.slug) + else: + path = '/' + http_request = 'GET {} HTTP/1.0\r\n'.format(path) + http_request += 'Host: {}\r\n'.format(self.gui.app.onion_host) + http_request += '\r\n' + s.sendall(http_request.encode('utf-8')) + with open('/tmp/webpage', 'wb') as file_to_write: + while True: + data = s.recv(1024) + if not data: + break + file_to_write.write(data) + file_to_write.close() + f = open('/tmp/webpage') + self.assertTrue(string in f.read()) + f.close() + + def cancel_the_share(self, mode): + '''Test that we can cancel this share before it's started up ''' + QtTest.QTest.mousePress(self.gui.mode.server_status.server_button, QtCore.Qt.LeftButton) + QtTest.QTest.qWait(1000) + QtTest.QTest.mouseRelease(self.gui.mode.server_status.server_button, QtCore.Qt.LeftButton) + self.assertEqual(self.gui.mode.server_status.status, 0) + + # Stealth tests + def copy_have_hidserv_auth_button(self, mode): + '''Test that the Copy HidservAuth button is shown''' + self.assertTrue(mode.server_status.copy_hidservauth_button.isVisible()) + + def hidserv_auth_string(self): + '''Test the validity of the HidservAuth string''' + self.assertRegex(self.gui.app.auth_string, r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host) + + # Miscellaneous tests + def tor_killed_statusbar_message_shown(self, mode): + '''Test that the status bar message shows Tor was disconnected''' + self.gui.app.onion.cleanup(stop_tor=True) + QtTest.QTest.qWait(2500) + self.assertTrue(mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost')) diff --git a/tests_gui/TorGuiReceiveTest.py b/tests_gui/TorGuiReceiveTest.py new file mode 100644 index 00000000..67b6a811 --- /dev/null +++ b/tests_gui/TorGuiReceiveTest.py @@ -0,0 +1,51 @@ +import os +import requests +from PyQt5 import QtTest +from .TorGuiBaseTest import TorGuiBaseTest + +class TorGuiReceiveTest(TorGuiBaseTest): + + def upload_file(self, public_mode, expected_file): + '''Test that we can upload the file''' + (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port() + session = requests.session() + session.proxies = {} + session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port) + files = {'file[]': open('/tmp/test.txt', 'rb')} + if not public_mode: + path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, self.gui.receive_mode.web.slug) + else: + path = 'http://{}/upload'.format(self.gui.app.onion_host) + response = session.post(path, files=files) + QtTest.QTest.qWait(4000) + self.assertTrue(os.path.isfile(expected_file)) + + def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): + self.click_mode(self.gui.receive_mode) + self.history_is_not_visible(self.gui.receive_mode) + self.click_toggle_history(self.gui.receive_mode) + self.history_is_visible(self.gui.receive_mode) + self.server_working_on_start_button_pressed(self.gui.receive_mode) + self.server_status_indicator_says_starting(self.gui.receive_mode) + self.settings_button_is_hidden() + self.a_server_is_started(self.gui.receive_mode) + self.a_web_server_is_running() + self.have_an_onion_service() + self.have_a_slug(self.gui.receive_mode, public_mode) + self.url_description_shown(self.gui.receive_mode) + self.have_copy_url_button(self.gui.receive_mode) + self.server_status_indicator_says_started(self.gui.receive_mode) + self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode) + self.upload_file(public_mode, '/tmp/OnionShare/test.txt') + self.history_widgets_present(self.gui.receive_mode) + self.counter_incremented(self.gui.receive_mode, 1) + self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt') + self.counter_incremented(self.gui.receive_mode, 2) + self.history_indicator(self.gui.receive_mode, public_mode) + self.server_is_stopped(self.gui.receive_mode, False) + self.web_service_is_stopped() + self.server_status_indicator_says_closed(self.gui.receive_mode, False) + self.server_working_on_start_button_pressed(self.gui.receive_mode) + self.a_server_is_started(self.gui.receive_mode) + self.history_indicator(self.gui.receive_mode, public_mode) + diff --git a/tests_gui/TorGuiShareTest.py b/tests_gui/TorGuiShareTest.py new file mode 100644 index 00000000..8d6358c3 --- /dev/null +++ b/tests_gui/TorGuiShareTest.py @@ -0,0 +1,70 @@ +import requests +import socks +import zipfile +from PyQt5 import QtCore, QtTest +from .TorGuiBaseTest import TorGuiBaseTest +from .GuiShareTest import GuiShareTest + +class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): + def download_share(self, public_mode): + # Set up connecting to the onion + (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port() + session = requests.session() + session.proxies = {} + session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port) + + # Download files + if public_mode: + path = "http://{}/download".format(self.gui.app.onion_host) + else: + path = "http://{}/{}/download".format(self.gui.app.onion_host, self.gui.share_mode.web.slug) + response = session.get(path, stream=True) + QtTest.QTest.qWait(4000) + + if response.status_code == 200: + with open('/tmp/download.zip', 'wb') as file_to_write: + for chunk in response.iter_content(chunk_size=128): + file_to_write.write(chunk) + file_to_write.close() + zip = zipfile.ZipFile('/tmp/download.zip') + QtTest.QTest.qWait(4000) + self.assertEquals('onionshare', zip.read('test.txt').decode('utf-8')) + + # Persistence tests + def have_same_onion(self, onion): + '''Test that we have the same onion''' + self.assertEqual(self.gui.app.onion_host, onion) + + def run_all_share_mode_started_tests(self, public_mode): + """Tests in share mode after starting a share""" + self.server_working_on_start_button_pressed(self.gui.share_mode) + self.server_status_indicator_says_starting(self.gui.share_mode) + self.add_delete_buttons_hidden() + self.settings_button_is_hidden() + self.a_server_is_started(self.gui.share_mode) + self.a_web_server_is_running() + self.have_an_onion_service() + self.have_a_slug(self.gui.share_mode, public_mode) + self.url_description_shown(self.gui.share_mode) + self.have_copy_url_button(self.gui.share_mode) + self.server_status_indicator_says_started(self.gui.share_mode) + + 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 + onion = self.gui.app.onion_host + self.run_all_share_mode_download_tests(public_mode, stay_open) + self.have_same_onion(onion) + 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() + self.set_timeout(self.gui.share_mode, 5) + self.run_all_share_mode_started_tests(public_mode) + self.timeout_widget_hidden(self.gui.share_mode) + self.server_timed_out(self.gui.share_mode, 10000) + self.web_service_is_stopped() + diff --git a/tests_gui_local/__init__.py b/tests_gui/__init__.py similarity index 100% rename from tests_gui_local/__init__.py rename to tests_gui/__init__.py diff --git a/tests_gui_local/conftest.py b/tests_gui/conftest.py similarity index 89% rename from tests_gui_local/conftest.py rename to tests_gui/conftest.py index 8ac7efb8..62108e05 100644 --- a/tests_gui_local/conftest.py +++ b/tests_gui/conftest.py @@ -10,6 +10,22 @@ import pytest from onionshare import common, web, settings +def pytest_addoption(parser): + parser.addoption( + "--runtor", action="store_true", default=False, help="run tor tests" + ) + + +def pytest_collection_modifyitems(config, items): + if config.getoption("--runtor"): + # --runtor given in cli: do not skip tor tests + return + skip_tor = pytest.mark.skip(reason="need --runtor option to run") + for item in items: + if "tor" in item.keywords: + item.add_marker(skip_tor) + + @pytest.fixture def temp_dir_1024(): """ Create a temporary directory that has a single file of a 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 similarity index 77% rename from tests_gui_local/onionshare_receive_mode_upload_public_mode_test.py rename to tests_gui/local_onionshare_receive_mode_upload_public_mode_test.py index 5b685ef7..1b5722c7 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 @@ -4,14 +4,14 @@ import unittest from .GuiReceiveTest import GuiReceiveTest -class ReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): +class LocalReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): @classmethod def setUpClass(cls): test_settings = { "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModePublicModeTest') + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModePublicModeTest') @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): diff --git a/tests_gui_local/onionshare_receive_mode_upload_test.py b/tests_gui/local_onionshare_receive_mode_upload_test.py similarity index 78% rename from tests_gui_local/onionshare_receive_mode_upload_test.py rename to tests_gui/local_onionshare_receive_mode_upload_test.py index 7171eaca..14a0377d 100644 --- a/tests_gui_local/onionshare_receive_mode_upload_test.py +++ b/tests_gui/local_onionshare_receive_mode_upload_test.py @@ -4,13 +4,13 @@ import unittest from .GuiReceiveTest import GuiReceiveTest -class ReceiveModeTest(unittest.TestCase, GuiReceiveTest): +class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): @classmethod def setUpClass(cls): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): 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 similarity index 76% rename from tests_gui_local/onionshare_share_mode_download_public_mode_test.py rename to tests_gui/local_onionshare_share_mode_download_public_mode_test.py index 96cadb90..6dcb94df 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 @@ -4,13 +4,13 @@ import unittest from .GuiShareTest import GuiShareTest -class ShareModePublicModeTest(unittest.TestCase, GuiShareTest): +class LocalShareModePublicModeTest(unittest.TestCase, GuiShareTest): @classmethod def setUpClass(cls): test_settings = { "public_mode": True, } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePublicModeTest') @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): 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 similarity index 77% rename from tests_gui_local/onionshare_share_mode_download_stay_open_test.py rename to tests_gui/local_onionshare_share_mode_download_stay_open_test.py index bb9ec2ea..62eafff7 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 @@ -4,13 +4,13 @@ import unittest from .GuiShareTest import GuiShareTest -class ShareModeStayOpenTest(unittest.TestCase, GuiShareTest): +class LocalShareModeStayOpenTest(unittest.TestCase, GuiShareTest): @classmethod def setUpClass(cls): test_settings = { "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeStayOpenTest') @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): diff --git a/tests_gui_local/onionshare_share_mode_download_test.py b/tests_gui/local_onionshare_share_mode_download_test.py similarity index 77% rename from tests_gui_local/onionshare_share_mode_download_test.py rename to tests_gui/local_onionshare_share_mode_download_test.py index 12b914b0..98270523 100644 --- a/tests_gui_local/onionshare_share_mode_download_test.py +++ b/tests_gui/local_onionshare_share_mode_download_test.py @@ -4,12 +4,12 @@ import unittest from .GuiShareTest import GuiShareTest -class ShareModeTest(unittest.TestCase, GuiShareTest): +class LocalShareModeTest(unittest.TestCase, GuiShareTest): @classmethod def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTest') + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): diff --git a/tests_gui_local/onionshare_share_mode_slug_persistent_test.py b/tests_gui/local_onionshare_share_mode_slug_persistent_test.py similarity index 79% rename from tests_gui_local/onionshare_share_mode_slug_persistent_test.py rename to tests_gui/local_onionshare_share_mode_slug_persistent_test.py index 25e4e093..9e171ba4 100644 --- a/tests_gui_local/onionshare_share_mode_slug_persistent_test.py +++ b/tests_gui/local_onionshare_share_mode_slug_persistent_test.py @@ -4,7 +4,7 @@ import unittest from .GuiShareTest import GuiShareTest -class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): +class LocalShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): @classmethod def setUpClass(cls): test_settings = { @@ -13,7 +13,7 @@ class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): "save_private_key": True, "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePersistentSlugTest') @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): diff --git a/tests_gui_local/onionshare_share_mode_timer_test.py b/tests_gui/local_onionshare_share_mode_timer_test.py similarity index 79% rename from tests_gui_local/onionshare_share_mode_timer_test.py rename to tests_gui/local_onionshare_share_mode_timer_test.py index 2e654c9d..b13971b0 100644 --- a/tests_gui_local/onionshare_share_mode_timer_test.py +++ b/tests_gui/local_onionshare_share_mode_timer_test.py @@ -4,14 +4,14 @@ import unittest from .GuiShareTest import GuiShareTest -class ShareModeTimerTest(unittest.TestCase, GuiShareTest): +class LocalShareModeTimerTest(unittest.TestCase, GuiShareTest): @classmethod def setUpClass(cls): test_settings = { "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTimerTest') + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTest') @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): diff --git a/tests_gui/onionshare_receive_mode_upload_public_mode_test.py b/tests_gui/onionshare_receive_mode_upload_public_mode_test.py new file mode 100644 index 00000000..8561cbce --- /dev/null +++ b/tests_gui/onionshare_receive_mode_upload_public_mode_test.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiReceiveTest import TorGuiReceiveTest + +class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": True, + "receive_allow_receiver_shutdown": True + } + cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_all_receive_mode_tests(self): + self.run_all_receive_mode_tests(True, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/onionshare_receive_mode_upload_test.py b/tests_gui/onionshare_receive_mode_upload_test.py new file mode 100644 index 00000000..6dac4bc8 --- /dev/null +++ b/tests_gui/onionshare_receive_mode_upload_test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiReceiveTest import TorGuiReceiveTest + +class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "receive_allow_receiver_shutdown": True + } + cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_all_receive_mode_tests(self): + self.run_all_receive_mode_tests(False, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/onionshare_share_mode_download_public_mode_test.py b/tests_gui/onionshare_share_mode_download_public_mode_test.py new file mode 100644 index 00000000..3a17b47e --- /dev/null +++ b/tests_gui/onionshare_share_mode_download_public_mode_test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModePublicModeTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": True, + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_all_share_mode_tests(self): + self.run_all_share_mode_tests(True, False) + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/onionshare_share_mode_download_stay_open_test.py b/tests_gui/onionshare_share_mode_download_stay_open_test.py new file mode 100644 index 00000000..ddb513dd --- /dev/null +++ b/tests_gui/onionshare_share_mode_download_stay_open_test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModeStayOpenTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "close_after_first_download": False, + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_all_share_mode_tests(self): + self.run_all_share_mode_tests(False, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/onionshare_share_mode_download_test.py b/tests_gui/onionshare_share_mode_download_test.py new file mode 100644 index 00000000..17c94215 --- /dev/null +++ b/tests_gui/onionshare_share_mode_download_test.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModeTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_all_share_mode_tests(self): + self.run_all_share_mode_tests(False, False) + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/onionshare_share_mode_persistent_test.py b/tests_gui/onionshare_share_mode_persistent_test.py new file mode 100644 index 00000000..415ce42e --- /dev/null +++ b/tests_gui/onionshare_share_mode_persistent_test.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class LocalShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "use_legacy_v2_onions": True, + "public_mode": False, + "slug": "", + "save_private_key": True, + "close_after_first_download": False, + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_all_share_mode_tests(self): + self.run_all_share_mode_persistent_tests(False, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/onionshare_share_mode_stealth_test.py b/tests_gui/onionshare_share_mode_stealth_test.py new file mode 100644 index 00000000..56303226 --- /dev/null +++ b/tests_gui/onionshare_share_mode_stealth_test.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "use_legacy_v2_onions": True, + "use_stealth": True, + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStealthTest') + + @pytest.mark.run(order=1) + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + def test_run_share_mode_setup_tests(self): + self.run_all_share_mode_setup_tests() + self.run_all_share_mode_started_tests(False) + + @pytest.mark.run(order=3) + def test_copy_have_hidserv_auth_button(self): + self.copy_have_hidserv_auth_button(self.gui.share_mode) + + @pytest.mark.run(order=4) + def test_hidserv_auth_string(self): + self.hidserv_auth_string() + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/onionshare_share_mode_tor_connection_killed_test.py b/tests_gui/onionshare_share_mode_tor_connection_killed_test.py new file mode 100644 index 00000000..6ebdec97 --- /dev/null +++ b/tests_gui/onionshare_share_mode_tor_connection_killed_test.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModeTorConnectionKilledTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTorConnectionKilledTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_share_mode_setup_tests(self): + self.run_all_share_mode_setup_tests() + self.run_all_share_mode_started_tests(False) + + @pytest.mark.run(order=3) + @pytest.mark.tor + def test_tor_killed_statusbar_message_shown(self): + self.tor_killed_statusbar_message_shown(self.gui.share_mode) + + @pytest.mark.run(order=4) + @pytest.mark.tor + def test_server_is_stopped(self): + self.server_is_stopped(self.gui.share_mode, False) + + @pytest.mark.run(order=5) + @pytest.mark.tor + def test_web_service_is_stopped(self): + self.web_service_is_stopped() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui_tor/__init__.py b/tests_gui_tor/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests_gui_tor/commontests.py b/tests_gui_tor/commontests.py deleted file mode 100644 index 89ebf669..00000000 --- a/tests_gui_tor/commontests.py +++ /dev/null @@ -1,61 +0,0 @@ -import os -import requests -import socket -import socks -import zipfile - -from PyQt5 import QtCore, QtTest -from onionshare import strings - -from tests_gui_local import CommonTests as LocalCommonTests - -class CommonTests(LocalCommonTests): - def test_a_server_is_started(self, mode): - '''Test that the server has started (overriding from local tests to wait for longer)''' - QtTest.QTest.qWait(45000) - # Should now be in SERVER_STARTED state - if mode == 'receive': - self.assertEqual(self.gui.receive_mode.server_status.status, 2) - if mode == 'share': - self.assertEqual(self.gui.share_mode.server_status.status, 2) - - def test_have_an_onion_service(self): - '''Test that we have a valid Onion URL''' - self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion') - - def test_cancel_the_share(self, mode): - '''Test that we can cancel this share before it's started up ''' - if mode == 'share': - QtTest.QTest.mousePress(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton) - QtTest.QTest.qWait(1000) - QtTest.QTest.mouseRelease(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton) - self.assertEqual(self.gui.share_mode.server_status.status, 0) - - if mode == 'receive': - QtTest.QTest.mousePress(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton) - QtTest.QTest.qWait(1000) - QtTest.QTest.mouseRelease(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton) - self.assertEqual(self.gui.receive_mode.server_status.status, 0) - - # Stealth tests - def test_copy_have_hidserv_auth_button(self, mode): - '''Test that the Copy HidservAuth button is shown''' - if mode == 'share': - self.assertTrue(self.gui.share_mode.server_status.copy_hidservauth_button.isVisible()) - if mode == 'receive': - self.assertTrue(self.gui.receive_mode.server_status.copy_hidservauth_button.isVisible()) - - def test_hidserv_auth_string(self): - '''Test the validity of the HidservAuth string''' - self.assertRegex(self.gui.app.auth_string, r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host) - - - # Miscellaneous tests - def test_tor_killed_statusbar_message_shown(self, mode): - '''Test that the status bar message shows Tor was disconnected''' - self.gui.app.onion.cleanup(stop_tor=True) - QtTest.QTest.qWait(2500) - if mode == 'share': - self.assertTrue(self.gui.share_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost')) - if mode == 'receive': - self.assertTrue(self.gui.receive_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost')) diff --git a/tests_gui_tor/conftest.py b/tests_gui_tor/conftest.py deleted file mode 100644 index 3ae6fd52..00000000 --- a/tests_gui_tor/conftest.py +++ /dev/null @@ -1,163 +0,0 @@ -import sys -# Force tests to look for resources in the source code tree -sys.onionshare_dev_mode = True - -import os -import shutil -import tempfile - -import pytest - -from onionshare import common, web, settings, strings - -@pytest.fixture -def temp_dir_1024(): - """ Create a temporary directory that has a single file of a - particular size (1024 bytes). - """ - - tmp_dir = tempfile.mkdtemp() - tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir) - with open(tmp_file, 'wb') as f: - f.write(b'*' * 1024) - return tmp_dir - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture -def temp_dir_1024_delete(): - """ Create a temporary directory that has a single file of a - particular size (1024 bytes). The temporary directory (including - the file inside) will be deleted after fixture usage. - """ - - with tempfile.TemporaryDirectory() as tmp_dir: - tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir) - with open(tmp_file, 'wb') as f: - f.write(b'*' * 1024) - yield tmp_dir - - -@pytest.fixture -def temp_file_1024(): - """ Create a temporary file of a particular size (1024 bytes). """ - - with tempfile.NamedTemporaryFile(delete=False) as tmp_file: - tmp_file.write(b'*' * 1024) - return tmp_file.name - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture -def temp_file_1024_delete(): - """ - Create a temporary file of a particular size (1024 bytes). - The temporary file will be deleted after fixture usage. - """ - - with tempfile.NamedTemporaryFile() as tmp_file: - tmp_file.write(b'*' * 1024) - tmp_file.flush() - yield tmp_file.name - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture(scope='session') -def custom_zw(): - zw = web.share_mode.ZipWriter( - common.Common(), - zip_filename=common.Common.random_string(4, 6), - processed_size_callback=lambda _: 'custom_callback' - ) - yield zw - zw.close() - os.remove(zw.zip_filename) - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture(scope='session') -def default_zw(): - zw = web.share_mode.ZipWriter(common.Common()) - yield zw - zw.close() - tmp_dir = os.path.dirname(zw.zip_filename) - shutil.rmtree(tmp_dir) - - -@pytest.fixture -def locale_en(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8')) - - -@pytest.fixture -def locale_fr(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8')) - - -@pytest.fixture -def locale_invalid(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8')) - - -@pytest.fixture -def locale_ru(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8')) - - -@pytest.fixture -def platform_darwin(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Darwin') - - -@pytest.fixture # (scope="session") -def platform_linux(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Linux') - - -@pytest.fixture -def platform_windows(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Windows') - - -@pytest.fixture -def sys_argv_sys_prefix(monkeypatch): - monkeypatch.setattr('sys.argv', [sys.prefix]) - - -@pytest.fixture -def sys_frozen(monkeypatch): - monkeypatch.setattr('sys.frozen', True, raising=False) - - -@pytest.fixture -def sys_meipass(monkeypatch): - monkeypatch.setattr( - 'sys._MEIPASS', os.path.expanduser('~'), raising=False) - - -@pytest.fixture # (scope="session") -def sys_onionshare_dev_mode(monkeypatch): - monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False) - - -@pytest.fixture -def time_time_100(monkeypatch): - monkeypatch.setattr('time.time', lambda: 100) - - -@pytest.fixture -def time_strftime(monkeypatch): - monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00') - -@pytest.fixture -def common_obj(): - _common = common.Common() - _common.settings = settings.Settings(_common) - strings.load_strings(_common) - return _common - -@pytest.fixture -def settings_obj(sys_onionshare_dev_mode, platform_linux): - _common = common.Common() - _common.version = 'DUMMY_VERSION_1.2.3' - return settings.Settings(_common) diff --git a/tests_gui_tor/onionshare_receive_mode_upload_test.py b/tests_gui_tor/onionshare_receive_mode_upload_test.py deleted file mode 100644 index 7c340037..00000000 --- a/tests_gui_tor/onionshare_receive_mode_upload_test.py +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - os.remove('/tmp/OnionShare/test.txt') - os.remove('/tmp/OnionShare/test-2.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=6) - def test_click_mode(self): - CommonTests.test_click_mode(self, 'receive') - - @pytest.mark.run(order=6) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'receive') - - @pytest.mark.run(order=7) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'receive') - - @pytest.mark.run(order=8) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'receive') - - @pytest.mark.run(order=8) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'receive') - - @pytest.mark.run(order=9) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'receive') - - @pytest.mark.run(order=10) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=11) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'receive') - - @pytest.mark.run(order=12) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=14) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'receive', False) - - @pytest.mark.run(order=15) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=20) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'receive') - - @pytest.mark.run(order=21) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'receive') - - @pytest.mark.run(order=22) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'receive') - - @pytest.mark.run(order=23) - def test_web_page(self): - CommonTests.test_web_page(self, 'receive', 'Select the files you want to send, then click', False) - - @pytest.mark.run(order=24) - def test_upload_file(self): - CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test.txt') - - @pytest.mark.run(order=25) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, 'receive') - - @pytest.mark.run(order=26) - def test_counter_incremented(self): - CommonTests.test_counter_incremented(self, 'receive', 1) - - @pytest.mark.run(order=27) - def test_upload_same_file_is_renamed(self): - CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test-2.txt') - - @pytest.mark.run(order=28) - def test_upload_count_incremented_again(self): - CommonTests.test_counter_incremented(self, 'receive', 2) - - @pytest.mark.run(order=29) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'receive', False) - - @pytest.mark.run(order=30) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=31) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, 'receive', False) - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_receive_mode_upload_test_public_mode.py b/tests_gui_tor/onionshare_receive_mode_upload_test_public_mode.py deleted file mode 100644 index 65bf5c89..00000000 --- a/tests_gui_tor/onionshare_receive_mode_upload_test_public_mode.py +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": True, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - os.remove('/tmp/OnionShare/test.txt') - os.remove('/tmp/OnionShare/test-2.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_click_mode(self): - CommonTests.test_click_mode(self, 'receive') - - @pytest.mark.run(order=6) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'receive') - - @pytest.mark.run(order=7) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'receive') - - @pytest.mark.run(order=8) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'receive') - - @pytest.mark.run(order=9) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'receive') - - @pytest.mark.run(order=10) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'receive') - - @pytest.mark.run(order=11) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=12) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'receive') - - @pytest.mark.run(order=13) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=14) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'receive', True) - - @pytest.mark.run(order=15) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=20) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'receive') - - @pytest.mark.run(order=21) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'receive') - - @pytest.mark.run(order=22) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'receive') - - @pytest.mark.run(order=23) - def test_web_page(self): - CommonTests.test_web_page(self, 'receive', 'Select the files you want to send, then click', True) - - @pytest.mark.run(order=24) - def test_upload_file(self): - CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test.txt') - - @pytest.mark.run(order=25) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, 'receive') - - @pytest.mark.run(order=26) - def test_counter_incremented(self): - CommonTests.test_counter_incremented(self, 'receive', 1) - - @pytest.mark.run(order=27) - def test_upload_same_file_is_renamed(self): - CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test-2.txt') - - @pytest.mark.run(order=28) - def test_upload_count_incremented_again(self): - CommonTests.test_counter_incremented(self, 'receive', 2) - - @pytest.mark.run(order=29) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'receive', False) - - @pytest.mark.run(order=30) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=31) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, 'receive', False) - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_share_mode_download_test.py b/tests_gui_tor/onionshare_share_mode_download_test.py deleted file mode 100644 index 2bf26690..00000000 --- a/tests_gui_tor/onionshare_share_mode_download_test.py +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=6) - def test_info_widget_shows_less(self): - CommonTests.test_info_widget_shows_less(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'share') - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=10) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=11) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=12) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=13) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=14) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=15) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=16) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=17) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'share', False) - - @pytest.mark.run(order=18) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=19) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'share') - - @pytest.mark.run(order=20) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'share') - - @pytest.mark.run(order=21) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'share') - - @pytest.mark.run(order=22) - def test_web_page(self): - CommonTests.test_web_page(self, 'share', 'Total size', False) - - @pytest.mark.run(order=23) - def test_download_share(self): - CommonTests.test_download_share(self, False) - - @pytest.mark.run(order=24) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, 'share') - - @pytest.mark.run(order=25) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'share', False) - - @pytest.mark.run(order=26) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=27) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, 'share', False) - - @pytest.mark.run(order=28) - def test_add_button_visible(self): - CommonTests.test_add_button_visible(self) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_share_mode_download_test_public_mode.py b/tests_gui_tor/onionshare_share_mode_download_test_public_mode.py deleted file mode 100644 index 4792994d..00000000 --- a/tests_gui_tor/onionshare_share_mode_download_test_public_mode.py +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": True, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=6) - def test_info_widget_shows_less(self): - CommonTests.test_info_widget_shows_less(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'share') - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=10) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=11) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=12) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=13) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=14) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=15) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=16) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=17) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=18) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=19) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'share', True) - - @pytest.mark.run(order=20) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=21) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'share') - - @pytest.mark.run(order=22) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'share') - - @pytest.mark.run(order=23) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'share') - - @pytest.mark.run(order=24) - def test_web_page(self): - CommonTests.test_web_page(self, 'share', 'Total size', True) - - @pytest.mark.run(order=25) - def test_download_share(self): - CommonTests.test_download_share(self, True) - - @pytest.mark.run(order=26) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, 'share') - - @pytest.mark.run(order=27) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'share', False) - - @pytest.mark.run(order=28) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=29) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, 'share', False) - - @pytest.mark.run(order=30) - def test_add_button_visible(self): - CommonTests.test_add_button_visible(self) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_share_mode_download_test_stay_open.py b/tests_gui_tor/onionshare_share_mode_download_test_stay_open.py deleted file mode 100644 index 92d52169..00000000 --- a/tests_gui_tor/onionshare_share_mode_download_test_stay_open.py +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": False, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": True, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=6) - def test_info_widget_shows_less(self): - CommonTests.test_info_widget_shows_less(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'share') - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=10) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=11) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=12) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=13) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=14) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=15) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=16) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=17) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=18) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=19) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'share', True) - - @pytest.mark.run(order=20) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=21) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'share') - - @pytest.mark.run(order=22) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'share') - - @pytest.mark.run(order=23) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'share') - - @pytest.mark.run(order=24) - def test_web_page(self): - CommonTests.test_web_page(self, 'share', 'Total size', True) - - @pytest.mark.run(order=25) - def test_download_share(self): - CommonTests.test_download_share(self, True) - - @pytest.mark.run(order=26) - def test_history_widgets_present(self): - CommonTests.test_history_widgets_present(self, 'share') - - @pytest.mark.run(order=27) - def test_counter_incremented(self): - CommonTests.test_counter_incremented(self, 'share', 1) - - @pytest.mark.run(order=28) - def test_download_share_again(self): - CommonTests.test_download_share(self, True) - - @pytest.mark.run(order=29) - def test_counter_incremented_again(self): - CommonTests.test_counter_incremented(self, 'share', 2) - - @pytest.mark.run(order=30) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'share', True) - - @pytest.mark.run(order=31) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=32) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, 'share', True) - - @pytest.mark.run(order=33) - def test_add_button_visible(self): - CommonTests.test_add_button_visible(self) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_share_mode_persistent_test.py b/tests_gui_tor/onionshare_share_mode_persistent_test.py deleted file mode 100644 index 6b9fbe16..00000000 --- a/tests_gui_tor/onionshare_share_mode_persistent_test.py +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - slug = '' - onion_host = '' - - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": True, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=6) - def test_info_widget_shows_less(self): - CommonTests.test_info_widget_shows_less(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'share') - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=10) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=11) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=12) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=13) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=14) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=15) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'share', False) - global slug - slug = self.gui.share_mode.server_status.web.slug - - @pytest.mark.run(order=16) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - global onion_host - onion_host = self.gui.app.onion_host - - @pytest.mark.run(order=17) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'share') - - @pytest.mark.run(order=18) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'share', True) - - @pytest.mark.run(order=19) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=20) - def test_server_status_indicator_says_closed(self): - CommonTests.test_server_status_indicator_says_closed(self, 'share', True) - - @pytest.mark.run(order=21) - def test_server_started_again(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - CommonTests.test_server_status_indicator_says_starting(self, 'share') - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=22) - def test_have_same_slug(self): - '''Test that we have the same slug''' - self.assertEqual(self.gui.share_mode.server_status.web.slug, slug) - - @pytest.mark.run(order=23) - def test_have_same_onion(self): - '''Test that we have the same onion''' - self.assertEqual(self.gui.app.onion_host, onion_host) - - @pytest.mark.run(order=24) - def test_server_is_stopped_again(self): - CommonTests.test_server_is_stopped(self, 'share', True) - CommonTests.test_web_service_is_stopped(self) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_share_mode_stealth_test.py b/tests_gui_tor/onionshare_share_mode_stealth_test.py deleted file mode 100644 index 876efde2..00000000 --- a/tests_gui_tor/onionshare_share_mode_stealth_test.py +++ /dev/null @@ -1,180 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": True, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=6) - def test_info_widget_shows_less(self): - CommonTests.test_info_widget_shows_less(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'share') - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=10) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=11) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=12) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=13) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=14) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=15) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=16) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=17) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=18) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=19) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'share', False) - - @pytest.mark.run(order=20) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=21) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'share') - - @pytest.mark.run(order=22) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'share') - - @pytest.mark.run(order=23) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'share') - - @pytest.mark.run(order=24) - def test_copy_have_hidserv_auth_button(self): - CommonTests.test_copy_have_hidserv_auth_button(self, 'share') - - @pytest.mark.run(order=25) - def test_hidserv_auth_string(self): - CommonTests.test_hidserv_auth_string(self) - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_share_mode_tor_connection_killed_test.py b/tests_gui_tor/onionshare_share_mode_tor_connection_killed_test.py deleted file mode 100644 index 37abc825..00000000 --- a/tests_gui_tor/onionshare_share_mode_tor_connection_killed_test.py +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=6) - def test_info_widget_shows_less(self): - CommonTests.test_info_widget_shows_less(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'share') - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=10) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=11) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=12) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=13) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=14) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=15) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=16) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=17) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=18) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=19) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'share', False) - - @pytest.mark.run(order=20) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=21) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'share') - - @pytest.mark.run(order=22) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'share') - - @pytest.mark.run(order=23) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'share') - - @pytest.mark.run(order=24) - def test_tor_killed_statusbar_message_shown(self): - CommonTests.test_tor_killed_statusbar_message_shown(self, 'share') - - @pytest.mark.run(order=25) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'share', False) - - @pytest.mark.run(order=26) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_tor_connection_killed_test.py b/tests_gui_tor/onionshare_tor_connection_killed_test.py deleted file mode 100644 index 37abc825..00000000 --- a/tests_gui_tor/onionshare_tor_connection_killed_test.py +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=6) - def test_info_widget_shows_less(self): - CommonTests.test_info_widget_shows_less(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'share') - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=10) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=11) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=12) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=13) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=14) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=15) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=16) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=17) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=18) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=19) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'share', False) - - @pytest.mark.run(order=20) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=21) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'share') - - @pytest.mark.run(order=22) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'share') - - @pytest.mark.run(order=23) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'share') - - @pytest.mark.run(order=24) - def test_tor_killed_statusbar_message_shown(self): - CommonTests.test_tor_killed_statusbar_message_shown(self, 'share') - - @pytest.mark.run(order=25) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'share', False) - - @pytest.mark.run(order=26) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/run_unit_tests.sh b/tests_gui_tor/run_unit_tests.sh deleted file mode 100755 index 7d207a57..00000000 --- a/tests_gui_tor/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 From 5a4222517961c1d2f06e421e40b61d035d4b8d39 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 18:56:30 +1100 Subject: [PATCH 09/72] add tor marker on the stealth test --- tests_gui/onionshare_share_mode_stealth_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests_gui/onionshare_share_mode_stealth_test.py b/tests_gui/onionshare_share_mode_stealth_test.py index 56303226..9e4ffa1f 100644 --- a/tests_gui/onionshare_share_mode_stealth_test.py +++ b/tests_gui/onionshare_share_mode_stealth_test.py @@ -14,19 +14,23 @@ class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStealthTest') @pytest.mark.run(order=1) + @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() @pytest.mark.run(order=2) + @pytest.mark.tor def test_run_share_mode_setup_tests(self): self.run_all_share_mode_setup_tests() self.run_all_share_mode_started_tests(False) @pytest.mark.run(order=3) + @pytest.mark.tor def test_copy_have_hidserv_auth_button(self): self.copy_have_hidserv_auth_button(self.gui.share_mode) @pytest.mark.run(order=4) + @pytest.mark.tor def test_hidserv_auth_string(self): self.hidserv_auth_string() From bea0aaf6fcff0f3bfb4432f3495fbb9ea6da6cb4 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 19:01:50 +1100 Subject: [PATCH 10/72] cancel share test in Tor --- ...onionshare_share_mode_cancel_share_test.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests_gui/onionshare_share_mode_cancel_share_test.py diff --git a/tests_gui/onionshare_share_mode_cancel_share_test.py b/tests_gui/onionshare_share_mode_cancel_share_test.py new file mode 100644 index 00000000..62dbc8ad --- /dev/null +++ b/tests_gui/onionshare_share_mode_cancel_share_test.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_share_mode_setup_tests(self): + self.run_all_share_mode_setup_tests() + + @pytest.mark.run(order=3) + @pytest.mark.tor + def test_cancel_the_share(self): + self.cancel_the_share(self.gui.share_mode) + +if __name__ == "__main__": + unittest.main() From 37e77b832489913bcc3d0e4c527c33cd5acd9335 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 12 Oct 2018 20:44:10 +1100 Subject: [PATCH 11/72] Commit missing test changes for canceling a share --- tests_gui/TorGuiBaseTest.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests_gui/TorGuiBaseTest.py b/tests_gui/TorGuiBaseTest.py index 1c313726..b182b1d4 100644 --- a/tests_gui/TorGuiBaseTest.py +++ b/tests_gui/TorGuiBaseTest.py @@ -132,10 +132,17 @@ class TorGuiBaseTest(GuiBaseTest): def cancel_the_share(self, mode): '''Test that we can cancel this share before it's started up ''' - QtTest.QTest.mousePress(self.gui.mode.server_status.server_button, QtCore.Qt.LeftButton) + self.server_working_on_start_button_pressed(self.gui.share_mode) + self.server_status_indicator_says_starting(self.gui.share_mode) + self.add_delete_buttons_hidden() + self.settings_button_is_hidden() + QtTest.QTest.mousePress(mode.server_status.server_button, QtCore.Qt.LeftButton) QtTest.QTest.qWait(1000) - QtTest.QTest.mouseRelease(self.gui.mode.server_status.server_button, QtCore.Qt.LeftButton) - self.assertEqual(self.gui.mode.server_status.status, 0) + QtTest.QTest.mouseRelease(mode.server_status.server_button, QtCore.Qt.LeftButton) + self.assertEqual(mode.server_status.status, 0) + self.server_is_stopped(self.gui.share_mode, False) + self.web_service_is_stopped() + # Stealth tests def copy_have_hidserv_auth_button(self, mode): From 966ade5dda3dfc33a46e1862c87b9162a8210fb0 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 13 Oct 2018 09:49:05 +1100 Subject: [PATCH 12/72] add the other Tor tests into tests_gui and refactor them. Reinstate the shell script for the sake of Travis --- .travis.yml | 2 +- tests_gui/TorGuiShareTest.py | 4 +- ...onshare_790_cancel_on_second_share_test.py | 49 +++++ tests_gui/onionshare_share_mode_timer_test.py | 27 +++ tests_gui/run_unit_tests.sh | 5 + ...onshare_790_cancel_on_second_share_test.py | 197 ------------------ ...onionshare_share_mode_cancel_share_test.py | 149 ------------- tests_gui_tor/onionshare_timer_test.py | 148 ------------- 8 files changed, 84 insertions(+), 497 deletions(-) create mode 100644 tests_gui/onionshare_790_cancel_on_second_share_test.py create mode 100644 tests_gui/onionshare_share_mode_timer_test.py create mode 100755 tests_gui/run_unit_tests.sh delete mode 100644 tests_gui_tor/onionshare_790_cancel_on_second_share_test.py delete mode 100644 tests_gui_tor/onionshare_share_mode_cancel_share_test.py delete mode 100644 tests_gui_tor/onionshare_timer_test.py diff --git a/.travis.yml b/.travis.yml index c54c205d..c9bc90ae 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/ - - xvfb-run pytest tests_gui/ -vvv + - cd tests_gui && xvfb-run ./run_unit_tests.sh diff --git a/tests_gui/TorGuiShareTest.py b/tests_gui/TorGuiShareTest.py index 8d6358c3..8e17abad 100644 --- a/tests_gui/TorGuiShareTest.py +++ b/tests_gui/TorGuiShareTest.py @@ -62,9 +62,9 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): def run_all_share_mode_timer_tests(self, public_mode): """Auto-stop timer tests in share mode""" self.run_all_share_mode_setup_tests() - self.set_timeout(self.gui.share_mode, 5) + self.set_timeout(self.gui.share_mode, 120) self.run_all_share_mode_started_tests(public_mode) self.timeout_widget_hidden(self.gui.share_mode) - self.server_timed_out(self.gui.share_mode, 10000) + self.server_timed_out(self.gui.share_mode, 125000) self.web_service_is_stopped() diff --git a/tests_gui/onionshare_790_cancel_on_second_share_test.py b/tests_gui/onionshare_790_cancel_on_second_share_test.py new file mode 100644 index 00000000..d3a1e797 --- /dev/null +++ b/tests_gui/onionshare_790_cancel_on_second_share_test.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +# Tests #790 regression +class ShareModeCancelSecondShareTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "close_after_first_download": True + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelSecondShareTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_share_mode_tests(self): + self.run_all_share_mode_tests(False, False) + + # Stop the share in order to test canceling the next share + #@pytest.mark.run(order=3) + #@pytest.mark.tor + #def test_stop_share(self): + # self.server_is_stopped(self.gui.share_mode, True) + # self.web_service_is_stopped() + + @pytest.mark.run(order=4) + @pytest.mark.tor + def test_cancel_the_share(self): + self.cancel_the_share(self.gui.share_mode) + + @pytest.mark.run(order=5) + @pytest.mark.tor + def test_server_is_stopped_round2(self): + self.server_is_stopped(self.gui.share_mode, False) + + @pytest.mark.run(order=6) + @pytest.mark.tor + def test_web_service_is_stopped_round2(self): + self.web_service_is_stopped() + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/onionshare_share_mode_timer_test.py b/tests_gui/onionshare_share_mode_timer_test.py new file mode 100644 index 00000000..d0b4f4cd --- /dev/null +++ b/tests_gui/onionshare_share_mode_timer_test.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModeTimerTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": False, + "shutdown_timeout": True, + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTimerTest') + + @pytest.mark.run(order=1) + @pytest.mark.tor + def test_run_all_common_setup_tests(self): + self.run_all_common_setup_tests() + + @pytest.mark.run(order=2) + @pytest.mark.tor + def test_run_all_share_mode_timer_tests(self): + self.run_all_share_mode_timer_tests(False) + +if __name__ == "__main__": + unittest.main() diff --git a/tests_gui/run_unit_tests.sh b/tests_gui/run_unit_tests.sh new file mode 100755 index 00000000..81542749 --- /dev/null +++ b/tests_gui/run_unit_tests.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +for test in `ls -1 | egrep ^local_`; do + pytest $test -vvv || exit 1 +done diff --git a/tests_gui_tor/onionshare_790_cancel_on_second_share_test.py b/tests_gui_tor/onionshare_790_cancel_on_second_share_test.py deleted file mode 100644 index 731de4fd..00000000 --- a/tests_gui_tor/onionshare_790_cancel_on_second_share_test.py +++ /dev/null @@ -1,197 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=6) - def test_info_widget_is_visible(self): - CommonTests.test_info_widget_is_visible(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=9) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=10) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=11) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=12) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=13) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=14) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=15) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=16) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=17) - def test_have_a_slug(self): - CommonTests.test_have_a_slug(self, 'share', False) - - @pytest.mark.run(order=18) - def test_have_an_onion(self): - CommonTests.test_have_an_onion_service(self) - - @pytest.mark.run(order=19) - def test_url_description_shown(self): - CommonTests.test_url_description_shown(self, 'share') - - @pytest.mark.run(order=20) - def test_have_copy_url_button(self): - CommonTests.test_have_copy_url_button(self, 'share') - - @pytest.mark.run(order=21) - def test_server_status_indicator_says_started(self): - CommonTests.test_server_status_indicator_says_started(self, 'share') - - @pytest.mark.run(order=22) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'share', True) - - @pytest.mark.run(order=23) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=24) - def test_server_working_on_start_button_pressed_round2(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=25) - def test_server_status_indicator_says_starting_round2(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=26) - def test_cancel_the_share(self): - CommonTests.test_cancel_the_share(self, 'share') - - @pytest.mark.run(order=27) - def test_server_is_stopped_round2(self): - CommonTests.test_server_is_stopped(self, 'share', False) - - @pytest.mark.run(order=28) - def test_web_service_is_stopped_round2(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=29) - def test_add_button_visible(self): - CommonTests.test_add_button_visible(self) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_share_mode_cancel_share_test.py b/tests_gui_tor/onionshare_share_mode_cancel_share_test.py deleted file mode 100644 index cdab8f85..00000000 --- a/tests_gui_tor/onionshare_share_mode_cancel_share_test.py +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": False, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=8) - def test_deleting_only_file_hides_delete_button(self): - CommonTests.test_deleting_only_file_hides_delete_button(self) - - @pytest.mark.run(order=9) - def test_add_a_file_and_delete_using_its_delete_widget(self): - CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self) - - @pytest.mark.run(order=10) - def test_file_selection_widget_readd_files(self): - CommonTests.test_file_selection_widget_readd_files(self) - - @pytest.mark.run(order=11) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=12) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=13) - def test_add_delete_buttons_hidden(self): - CommonTests.test_add_delete_buttons_hidden(self) - - @pytest.mark.run(order=14) - def test_settings_button_is_hidden(self): - CommonTests.test_settings_button_is_hidden(self) - - @pytest.mark.run(order=16) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=17) - def test_cancel_the_share(self): - CommonTests.test_cancel_the_share(self, 'share') - - @pytest.mark.run(order=18) - def test_server_is_stopped(self): - CommonTests.test_server_is_stopped(self, 'share', False) - - @pytest.mark.run(order=19) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - - @pytest.mark.run(order=20) - def test_add_button_visible(self): - CommonTests.test_add_button_visible(self) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests_gui_tor/onionshare_timer_test.py b/tests_gui_tor/onionshare_timer_test.py deleted file mode 100644 index 2b64b998..00000000 --- a/tests_gui_tor/onionshare_timer_test.py +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import unittest -import pytest -import json - -from PyQt5 import QtWidgets - -from onionshare.common import Common -from onionshare.web import Web -from onionshare import onion, strings -from onionshare_gui import * - -from .commontests import CommonTests - -class OnionShareGuiTest(unittest.TestCase): - '''Test the OnionShare GUI''' - @classmethod - def setUpClass(cls): - '''Create the GUI''' - # Create our test file - testfile = open('/tmp/test.txt', 'w') - testfile.write('onionshare') - testfile.close() - common = Common() - common.define_css() - - # Start the Onion - strings.load_strings(common) - - testonion = onion.Onion(common) - global qtapp - qtapp = Application(common) - app = OnionShare(common, testonion, False, 0) - - web = Web(common, False, True) - - test_settings = { - "auth_password": "", - "auth_type": "no_auth", - "autoupdate_timestamp": "", - "close_after_first_download": True, - "connection_type": "bundled", - "control_port_address": "127.0.0.1", - "control_port_port": 9051, - "downloads_dir": "/tmp/OnionShare", - "hidservauth_string": "", - "no_bridges": True, - "private_key": "", - "public_mode": False, - "receive_allow_receiver_shutdown": True, - "save_private_key": False, - "shutdown_timeout": True, - "slug": "", - "socks_address": "127.0.0.1", - "socks_port": 9050, - "socket_file_path": "/var/run/tor/control", - "systray_notifications": True, - "tor_bridges_use_meek_lite_azure": False, - "tor_bridges_use_meek_lite_amazon": False, - "tor_bridges_use_custom_bridges": "", - "tor_bridges_use_obfs4": False, - "use_stealth": False, - "use_legacy_v2_onions": False, - "use_autoupdate": True, - "version": "1.3.1" - } - testsettings = '/tmp/testsettings.json' - open(testsettings, 'w').write(json.dumps(test_settings)) - - cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, False) - - @classmethod - def tearDownClass(cls): - '''Clean up after tests''' - os.remove('/tmp/test.txt') - - @pytest.mark.run(order=1) - def test_gui_loaded(self): - CommonTests.test_gui_loaded(self) - - @pytest.mark.run(order=2) - def test_windowTitle_seen(self): - CommonTests.test_windowTitle_seen(self) - - @pytest.mark.run(order=3) - def test_settings_button_is_visible(self): - CommonTests.test_settings_button_is_visible(self) - - @pytest.mark.run(order=4) - def test_server_status_bar_is_visible(self): - CommonTests.test_server_status_bar_is_visible(self) - - @pytest.mark.run(order=5) - def test_file_selection_widget_has_a_file(self): - CommonTests.test_file_selection_widget_has_a_file(self) - - @pytest.mark.run(order=6) - def test_info_widget_shows_less(self): - CommonTests.test_info_widget_shows_less(self, 'share') - - @pytest.mark.run(order=7) - def test_history_is_not_visible(self): - CommonTests.test_history_is_not_visible(self, 'share') - - @pytest.mark.run(order=8) - def test_click_toggle_history(self): - CommonTests.test_click_toggle_history(self, 'share') - - @pytest.mark.run(order=9) - def test_history_is_visible(self): - CommonTests.test_history_is_visible(self, 'share') - - @pytest.mark.run(order=10) - def test_set_timeout(self): - CommonTests.test_set_timeout(self, 'share', 120) - - @pytest.mark.run(order=11) - def test_server_working_on_start_button_pressed(self): - CommonTests.test_server_working_on_start_button_pressed(self, 'share') - - @pytest.mark.run(order=12) - def test_server_status_indicator_says_starting(self): - CommonTests.test_server_status_indicator_says_starting(self, 'share') - - @pytest.mark.run(order=13) - def test_a_server_is_started(self): - CommonTests.test_a_server_is_started(self, 'share') - - @pytest.mark.run(order=14) - def test_a_web_server_is_running(self): - CommonTests.test_a_web_server_is_running(self) - - @pytest.mark.run(order=15) - def test_timeout_widget_hidden(self): - CommonTests.test_timeout_widget_hidden(self, 'share') - - @pytest.mark.run(order=16) - def test_timeout(self): - CommonTests.test_server_timed_out(self, 'share', 125000) - - @pytest.mark.run(order=17) - def test_web_service_is_stopped(self): - CommonTests.test_web_service_is_stopped(self) - -if __name__ == "__main__": - unittest.main() From 2a00656fd6d46be750888e50c802fd086bee4544 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 13 Oct 2018 10:03:15 +1100 Subject: [PATCH 13/72] Another attempt at changing pytest ordering so that pytest can run without shell script --- .travis.yml | 2 +- ...share_receive_mode_upload_public_mode_test.py | 3 +-- .../local_onionshare_receive_mode_upload_test.py | 3 +-- ...share_share_mode_download_public_mode_test.py | 3 +-- ...onshare_share_mode_download_stay_open_test.py | 3 +-- .../local_onionshare_share_mode_download_test.py | 3 +-- ...onionshare_share_mode_slug_persistent_test.py | 3 +-- .../local_onionshare_share_mode_timer_test.py | 3 +-- ...onionshare_790_cancel_on_second_share_test.py | 16 ++++------------ ...share_receive_mode_upload_public_mode_test.py | 3 +-- tests_gui/onionshare_receive_mode_upload_test.py | 3 +-- .../onionshare_share_mode_cancel_share_test.py | 5 ++--- ...share_share_mode_download_public_mode_test.py | 3 +-- ...onshare_share_mode_download_stay_open_test.py | 3 +-- tests_gui/onionshare_share_mode_download_test.py | 3 +-- .../onionshare_share_mode_persistent_test.py | 3 +-- tests_gui/onionshare_share_mode_stealth_test.py | 7 +++---- tests_gui/onionshare_share_mode_timer_test.py | 3 +-- ...hare_share_mode_tor_connection_killed_test.py | 9 ++++----- 19 files changed, 28 insertions(+), 53 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9bc90ae..118aa147 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 && xvfb-run ./run_unit_tests.sh + - xvfb-run pytest tests_gui/ 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 1b5722c7..27bf9b2c 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 @@ -13,11 +13,10 @@ class LocalReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModePublicModeTest') - @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') def test_run_all_receive_mode_tests(self): self.run_all_receive_mode_tests(True, True) diff --git a/tests_gui/local_onionshare_receive_mode_upload_test.py b/tests_gui/local_onionshare_receive_mode_upload_test.py index 14a0377d..f6594105 100644 --- a/tests_gui/local_onionshare_receive_mode_upload_test.py +++ b/tests_gui/local_onionshare_receive_mode_upload_test.py @@ -12,11 +12,10 @@ class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') - @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') def test_run_all_receive_mode_tests(self): self.run_all_receive_mode_tests(False, True) 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 6dcb94df..2a3f9584 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 @@ -12,11 +12,10 @@ class LocalShareModePublicModeTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePublicModeTest') - @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(True, False) 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 62eafff7..1f734ae7 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 @@ -12,11 +12,10 @@ class LocalShareModeStayOpenTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeStayOpenTest') - @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(False, True) diff --git a/tests_gui/local_onionshare_share_mode_download_test.py b/tests_gui/local_onionshare_share_mode_download_test.py index 98270523..274cc311 100644 --- a/tests_gui/local_onionshare_share_mode_download_test.py +++ b/tests_gui/local_onionshare_share_mode_download_test.py @@ -11,11 +11,10 @@ class LocalShareModeTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') - @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(False, False) 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 9e171ba4..3450ec3f 100644 --- a/tests_gui/local_onionshare_share_mode_slug_persistent_test.py +++ b/tests_gui/local_onionshare_share_mode_slug_persistent_test.py @@ -15,11 +15,10 @@ class LocalShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePersistentSlugTest') - @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') def test_run_all_share_mode_tests(self): self.run_all_share_mode_persistent_tests(False, True) diff --git a/tests_gui/local_onionshare_share_mode_timer_test.py b/tests_gui/local_onionshare_share_mode_timer_test.py index b13971b0..f9f36c48 100644 --- a/tests_gui/local_onionshare_share_mode_timer_test.py +++ b/tests_gui/local_onionshare_share_mode_timer_test.py @@ -13,11 +13,10 @@ class LocalShareModeTimerTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTest') - @pytest.mark.run(order=1) def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') def test_run_all_share_mode_timer_tests(self): self.run_all_share_mode_timer_tests(False) diff --git a/tests_gui/onionshare_790_cancel_on_second_share_test.py b/tests_gui/onionshare_790_cancel_on_second_share_test.py index d3a1e797..36725fb0 100644 --- a/tests_gui/onionshare_790_cancel_on_second_share_test.py +++ b/tests_gui/onionshare_790_cancel_on_second_share_test.py @@ -13,34 +13,26 @@ class ShareModeCancelSecondShareTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelSecondShareTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_share_mode_tests(self): self.run_all_share_mode_tests(False, False) - # Stop the share in order to test canceling the next share - #@pytest.mark.run(order=3) - #@pytest.mark.tor - #def test_stop_share(self): - # self.server_is_stopped(self.gui.share_mode, True) - # self.web_service_is_stopped() - - @pytest.mark.run(order=4) + @pytest.mark.run(after='test_run_share_mode_tests') @pytest.mark.tor def test_cancel_the_share(self): self.cancel_the_share(self.gui.share_mode) - @pytest.mark.run(order=5) + @pytest.mark.run(after='test_cancel_the_share') @pytest.mark.tor def test_server_is_stopped_round2(self): self.server_is_stopped(self.gui.share_mode, False) - @pytest.mark.run(order=6) + @pytest.mark.run(after='test_server_is_stopped_round2') @pytest.mark.tor def test_web_service_is_stopped_round2(self): self.web_service_is_stopped() diff --git a/tests_gui/onionshare_receive_mode_upload_public_mode_test.py b/tests_gui/onionshare_receive_mode_upload_public_mode_test.py index 8561cbce..ee0c5c34 100644 --- a/tests_gui/onionshare_receive_mode_upload_public_mode_test.py +++ b/tests_gui/onionshare_receive_mode_upload_public_mode_test.py @@ -13,12 +13,11 @@ class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): } cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_all_receive_mode_tests(self): self.run_all_receive_mode_tests(True, True) diff --git a/tests_gui/onionshare_receive_mode_upload_test.py b/tests_gui/onionshare_receive_mode_upload_test.py index 6dac4bc8..f1f683cc 100644 --- a/tests_gui/onionshare_receive_mode_upload_test.py +++ b/tests_gui/onionshare_receive_mode_upload_test.py @@ -12,12 +12,11 @@ class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): } cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_all_receive_mode_tests(self): self.run_all_receive_mode_tests(False, True) diff --git a/tests_gui/onionshare_share_mode_cancel_share_test.py b/tests_gui/onionshare_share_mode_cancel_share_test.py index 62dbc8ad..97adf9ce 100644 --- a/tests_gui/onionshare_share_mode_cancel_share_test.py +++ b/tests_gui/onionshare_share_mode_cancel_share_test.py @@ -11,17 +11,16 @@ class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_share_mode_setup_tests(self): self.run_all_share_mode_setup_tests() - @pytest.mark.run(order=3) + @pytest.mark.run(after='test_run_share_mode_setup_tests') @pytest.mark.tor def test_cancel_the_share(self): self.cancel_the_share(self.gui.share_mode) diff --git a/tests_gui/onionshare_share_mode_download_public_mode_test.py b/tests_gui/onionshare_share_mode_download_public_mode_test.py index 3a17b47e..a4a3bfb1 100644 --- a/tests_gui/onionshare_share_mode_download_public_mode_test.py +++ b/tests_gui/onionshare_share_mode_download_public_mode_test.py @@ -12,12 +12,11 @@ class ShareModePublicModeTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(True, False) diff --git a/tests_gui/onionshare_share_mode_download_stay_open_test.py b/tests_gui/onionshare_share_mode_download_stay_open_test.py index ddb513dd..33544217 100644 --- a/tests_gui/onionshare_share_mode_download_stay_open_test.py +++ b/tests_gui/onionshare_share_mode_download_stay_open_test.py @@ -12,12 +12,11 @@ class ShareModeStayOpenTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(False, True) diff --git a/tests_gui/onionshare_share_mode_download_test.py b/tests_gui/onionshare_share_mode_download_test.py index 17c94215..8d6d9655 100644 --- a/tests_gui/onionshare_share_mode_download_test.py +++ b/tests_gui/onionshare_share_mode_download_test.py @@ -11,12 +11,11 @@ class ShareModeTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(False, False) diff --git a/tests_gui/onionshare_share_mode_persistent_test.py b/tests_gui/onionshare_share_mode_persistent_test.py index 415ce42e..665aecd5 100644 --- a/tests_gui/onionshare_share_mode_persistent_test.py +++ b/tests_gui/onionshare_share_mode_persistent_test.py @@ -16,12 +16,11 @@ class LocalShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_all_share_mode_tests(self): self.run_all_share_mode_persistent_tests(False, True) diff --git a/tests_gui/onionshare_share_mode_stealth_test.py b/tests_gui/onionshare_share_mode_stealth_test.py index 9e4ffa1f..a6bbe08e 100644 --- a/tests_gui/onionshare_share_mode_stealth_test.py +++ b/tests_gui/onionshare_share_mode_stealth_test.py @@ -13,23 +13,22 @@ class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStealthTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_share_mode_setup_tests(self): self.run_all_share_mode_setup_tests() self.run_all_share_mode_started_tests(False) - @pytest.mark.run(order=3) + @pytest.mark.run(after='test_run_share_mode_setup_tests') @pytest.mark.tor def test_copy_have_hidserv_auth_button(self): self.copy_have_hidserv_auth_button(self.gui.share_mode) - @pytest.mark.run(order=4) + @pytest.mark.run(after='test_run_share_mode_setup_tests') @pytest.mark.tor def test_hidserv_auth_string(self): self.hidserv_auth_string() diff --git a/tests_gui/onionshare_share_mode_timer_test.py b/tests_gui/onionshare_share_mode_timer_test.py index d0b4f4cd..32e28c00 100644 --- a/tests_gui/onionshare_share_mode_timer_test.py +++ b/tests_gui/onionshare_share_mode_timer_test.py @@ -13,12 +13,11 @@ class ShareModeTimerTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTimerTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_all_share_mode_timer_tests(self): self.run_all_share_mode_timer_tests(False) diff --git a/tests_gui/onionshare_share_mode_tor_connection_killed_test.py b/tests_gui/onionshare_share_mode_tor_connection_killed_test.py index 6ebdec97..9112aedd 100644 --- a/tests_gui/onionshare_share_mode_tor_connection_killed_test.py +++ b/tests_gui/onionshare_share_mode_tor_connection_killed_test.py @@ -11,28 +11,27 @@ class ShareModeTorConnectionKilledTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTorConnectionKilledTest') - @pytest.mark.run(order=1) @pytest.mark.tor def test_run_all_common_setup_tests(self): self.run_all_common_setup_tests() - @pytest.mark.run(order=2) + @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor def test_run_share_mode_setup_tests(self): self.run_all_share_mode_setup_tests() self.run_all_share_mode_started_tests(False) - @pytest.mark.run(order=3) + @pytest.mark.run(after='test_run_share_mode_setup_tests') @pytest.mark.tor def test_tor_killed_statusbar_message_shown(self): self.tor_killed_statusbar_message_shown(self.gui.share_mode) - @pytest.mark.run(order=4) + @pytest.mark.run(after='test_tor_killed_statusbar_message_shown') @pytest.mark.tor def test_server_is_stopped(self): self.server_is_stopped(self.gui.share_mode, False) - @pytest.mark.run(order=5) + @pytest.mark.run(after='test_tor_killed_statusbar_message_shown') @pytest.mark.tor def test_web_service_is_stopped(self): self.web_service_is_stopped() From e3459a5136098b12a13fa522228e41dd0787dec9 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 13 Oct 2018 10:35:09 +1100 Subject: [PATCH 14/72] Move GUI tests into tests/ dir and fix conftest related stuff so everything loads what it needs and passes --- .travis.yml | 3 +- {tests_gui => tests}/GuiBaseTest.py | 0 {tests_gui => tests}/GuiReceiveTest.py | 0 {tests_gui => tests}/GuiShareTest.py | 0 {tests_gui => tests}/TorGuiBaseTest.py | 0 {tests_gui => tests}/TorGuiReceiveTest.py | 0 {tests_gui => tests}/TorGuiShareTest.py | 0 tests/conftest.py | 22 ++- ...re_receive_mode_upload_public_mode_test.py | 0 ...cal_onionshare_receive_mode_upload_test.py | 0 ...re_share_mode_download_public_mode_test.py | 0 ...hare_share_mode_download_stay_open_test.py | 0 ...cal_onionshare_share_mode_download_test.py | 0 ...onshare_share_mode_slug_persistent_test.py | 0 .../local_onionshare_share_mode_timer_test.py | 0 ...onshare_790_cancel_on_second_share_test.py | 0 ...re_receive_mode_upload_public_mode_test.py | 0 .../onionshare_receive_mode_upload_test.py | 0 ...onionshare_share_mode_cancel_share_test.py | 0 ...re_share_mode_download_public_mode_test.py | 0 ...hare_share_mode_download_stay_open_test.py | 0 .../onionshare_share_mode_download_test.py | 0 .../onionshare_share_mode_persistent_test.py | 0 .../onionshare_share_mode_stealth_test.py | 0 .../onionshare_share_mode_timer_test.py | 0 ...e_share_mode_tor_connection_killed_test.py | 0 tests/test_onionshare_strings.py | 5 +- tests/test_onionshare_web.py | 3 +- tests_gui/__init__.py | 0 tests_gui/conftest.py | 176 ------------------ tests_gui/run_unit_tests.sh | 5 - 31 files changed, 25 insertions(+), 189 deletions(-) rename {tests_gui => tests}/GuiBaseTest.py (100%) rename {tests_gui => tests}/GuiReceiveTest.py (100%) rename {tests_gui => tests}/GuiShareTest.py (100%) rename {tests_gui => tests}/TorGuiBaseTest.py (100%) rename {tests_gui => tests}/TorGuiReceiveTest.py (100%) rename {tests_gui => tests}/TorGuiShareTest.py (100%) rename {tests_gui => tests}/local_onionshare_receive_mode_upload_public_mode_test.py (100%) rename {tests_gui => tests}/local_onionshare_receive_mode_upload_test.py (100%) rename {tests_gui => tests}/local_onionshare_share_mode_download_public_mode_test.py (100%) rename {tests_gui => tests}/local_onionshare_share_mode_download_stay_open_test.py (100%) rename {tests_gui => tests}/local_onionshare_share_mode_download_test.py (100%) rename {tests_gui => tests}/local_onionshare_share_mode_slug_persistent_test.py (100%) rename {tests_gui => tests}/local_onionshare_share_mode_timer_test.py (100%) rename {tests_gui => tests}/onionshare_790_cancel_on_second_share_test.py (100%) rename {tests_gui => tests}/onionshare_receive_mode_upload_public_mode_test.py (100%) rename {tests_gui => tests}/onionshare_receive_mode_upload_test.py (100%) rename {tests_gui => tests}/onionshare_share_mode_cancel_share_test.py (100%) rename {tests_gui => tests}/onionshare_share_mode_download_public_mode_test.py (100%) rename {tests_gui => tests}/onionshare_share_mode_download_stay_open_test.py (100%) rename {tests_gui => tests}/onionshare_share_mode_download_test.py (100%) rename {tests_gui => tests}/onionshare_share_mode_persistent_test.py (100%) rename {tests_gui => tests}/onionshare_share_mode_stealth_test.py (100%) rename {tests_gui => tests}/onionshare_share_mode_timer_test.py (100%) rename {tests_gui => tests}/onionshare_share_mode_tor_connection_killed_test.py (100%) delete mode 100644 tests_gui/__init__.py delete mode 100644 tests_gui/conftest.py delete mode 100755 tests_gui/run_unit_tests.sh diff --git a/.travis.yml b/.travis.yml index 118aa147..ec7ba912 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,5 +19,4 @@ before_script: - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics # run CLI tests and local GUI tests script: - - pytest --cov=onionshare tests/ - - xvfb-run pytest tests_gui/ + - xvfb-run pytest --cov=onionshare --cov=onionshare_gui -vvv tests/ diff --git a/tests_gui/GuiBaseTest.py b/tests/GuiBaseTest.py similarity index 100% rename from tests_gui/GuiBaseTest.py rename to tests/GuiBaseTest.py diff --git a/tests_gui/GuiReceiveTest.py b/tests/GuiReceiveTest.py similarity index 100% rename from tests_gui/GuiReceiveTest.py rename to tests/GuiReceiveTest.py diff --git a/tests_gui/GuiShareTest.py b/tests/GuiShareTest.py similarity index 100% rename from tests_gui/GuiShareTest.py rename to tests/GuiShareTest.py diff --git a/tests_gui/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py similarity index 100% rename from tests_gui/TorGuiBaseTest.py rename to tests/TorGuiBaseTest.py diff --git a/tests_gui/TorGuiReceiveTest.py b/tests/TorGuiReceiveTest.py similarity index 100% rename from tests_gui/TorGuiReceiveTest.py rename to tests/TorGuiReceiveTest.py diff --git a/tests_gui/TorGuiShareTest.py b/tests/TorGuiShareTest.py similarity index 100% rename from tests_gui/TorGuiShareTest.py rename to tests/TorGuiShareTest.py diff --git a/tests/conftest.py b/tests/conftest.py index 3ae6fd52..688b22d8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,6 +10,22 @@ import pytest from onionshare import common, web, settings, strings +def pytest_addoption(parser): + parser.addoption( + "--runtor", action="store_true", default=False, help="run tor tests" + ) + + +def pytest_collection_modifyitems(config, items): + if config.getoption("--runtor"): + # --runtor given in cli: do not skip tor tests + return + skip_tor = pytest.mark.skip(reason="need --runtor option to run") + for item in items: + if "tor" in item.keywords: + item.add_marker(skip_tor) + + @pytest.fixture def temp_dir_1024(): """ Create a temporary directory that has a single file of a @@ -151,13 +167,11 @@ def time_strftime(monkeypatch): @pytest.fixture def common_obj(): - _common = common.Common() - _common.settings = settings.Settings(_common) - strings.load_strings(_common) - return _common + return common.Common() @pytest.fixture def settings_obj(sys_onionshare_dev_mode, platform_linux): _common = common.Common() _common.version = 'DUMMY_VERSION_1.2.3' + strings.load_strings(_common) return settings.Settings(_common) diff --git a/tests_gui/local_onionshare_receive_mode_upload_public_mode_test.py b/tests/local_onionshare_receive_mode_upload_public_mode_test.py similarity index 100% rename from tests_gui/local_onionshare_receive_mode_upload_public_mode_test.py rename to tests/local_onionshare_receive_mode_upload_public_mode_test.py diff --git a/tests_gui/local_onionshare_receive_mode_upload_test.py b/tests/local_onionshare_receive_mode_upload_test.py similarity index 100% rename from tests_gui/local_onionshare_receive_mode_upload_test.py rename to tests/local_onionshare_receive_mode_upload_test.py diff --git a/tests_gui/local_onionshare_share_mode_download_public_mode_test.py b/tests/local_onionshare_share_mode_download_public_mode_test.py similarity index 100% rename from tests_gui/local_onionshare_share_mode_download_public_mode_test.py rename to tests/local_onionshare_share_mode_download_public_mode_test.py diff --git a/tests_gui/local_onionshare_share_mode_download_stay_open_test.py b/tests/local_onionshare_share_mode_download_stay_open_test.py similarity index 100% rename from tests_gui/local_onionshare_share_mode_download_stay_open_test.py rename to tests/local_onionshare_share_mode_download_stay_open_test.py diff --git a/tests_gui/local_onionshare_share_mode_download_test.py b/tests/local_onionshare_share_mode_download_test.py similarity index 100% rename from tests_gui/local_onionshare_share_mode_download_test.py rename to tests/local_onionshare_share_mode_download_test.py diff --git a/tests_gui/local_onionshare_share_mode_slug_persistent_test.py b/tests/local_onionshare_share_mode_slug_persistent_test.py similarity index 100% rename from tests_gui/local_onionshare_share_mode_slug_persistent_test.py rename to tests/local_onionshare_share_mode_slug_persistent_test.py diff --git a/tests_gui/local_onionshare_share_mode_timer_test.py b/tests/local_onionshare_share_mode_timer_test.py similarity index 100% rename from tests_gui/local_onionshare_share_mode_timer_test.py rename to tests/local_onionshare_share_mode_timer_test.py diff --git a/tests_gui/onionshare_790_cancel_on_second_share_test.py b/tests/onionshare_790_cancel_on_second_share_test.py similarity index 100% rename from tests_gui/onionshare_790_cancel_on_second_share_test.py rename to tests/onionshare_790_cancel_on_second_share_test.py diff --git a/tests_gui/onionshare_receive_mode_upload_public_mode_test.py b/tests/onionshare_receive_mode_upload_public_mode_test.py similarity index 100% rename from tests_gui/onionshare_receive_mode_upload_public_mode_test.py rename to tests/onionshare_receive_mode_upload_public_mode_test.py diff --git a/tests_gui/onionshare_receive_mode_upload_test.py b/tests/onionshare_receive_mode_upload_test.py similarity index 100% rename from tests_gui/onionshare_receive_mode_upload_test.py rename to tests/onionshare_receive_mode_upload_test.py diff --git a/tests_gui/onionshare_share_mode_cancel_share_test.py b/tests/onionshare_share_mode_cancel_share_test.py similarity index 100% rename from tests_gui/onionshare_share_mode_cancel_share_test.py rename to tests/onionshare_share_mode_cancel_share_test.py diff --git a/tests_gui/onionshare_share_mode_download_public_mode_test.py b/tests/onionshare_share_mode_download_public_mode_test.py similarity index 100% rename from tests_gui/onionshare_share_mode_download_public_mode_test.py rename to tests/onionshare_share_mode_download_public_mode_test.py diff --git a/tests_gui/onionshare_share_mode_download_stay_open_test.py b/tests/onionshare_share_mode_download_stay_open_test.py similarity index 100% rename from tests_gui/onionshare_share_mode_download_stay_open_test.py rename to tests/onionshare_share_mode_download_stay_open_test.py diff --git a/tests_gui/onionshare_share_mode_download_test.py b/tests/onionshare_share_mode_download_test.py similarity index 100% rename from tests_gui/onionshare_share_mode_download_test.py rename to tests/onionshare_share_mode_download_test.py diff --git a/tests_gui/onionshare_share_mode_persistent_test.py b/tests/onionshare_share_mode_persistent_test.py similarity index 100% rename from tests_gui/onionshare_share_mode_persistent_test.py rename to tests/onionshare_share_mode_persistent_test.py diff --git a/tests_gui/onionshare_share_mode_stealth_test.py b/tests/onionshare_share_mode_stealth_test.py similarity index 100% rename from tests_gui/onionshare_share_mode_stealth_test.py rename to tests/onionshare_share_mode_stealth_test.py diff --git a/tests_gui/onionshare_share_mode_timer_test.py b/tests/onionshare_share_mode_timer_test.py similarity index 100% rename from tests_gui/onionshare_share_mode_timer_test.py rename to tests/onionshare_share_mode_timer_test.py diff --git a/tests_gui/onionshare_share_mode_tor_connection_killed_test.py b/tests/onionshare_share_mode_tor_connection_killed_test.py similarity index 100% rename from tests_gui/onionshare_share_mode_tor_connection_killed_test.py rename to tests/onionshare_share_mode_tor_connection_killed_test.py diff --git a/tests/test_onionshare_strings.py b/tests/test_onionshare_strings.py index 6d39598c..ea57e3a9 100644 --- a/tests/test_onionshare_strings.py +++ b/tests/test_onionshare_strings.py @@ -23,7 +23,7 @@ import types import pytest from onionshare import strings - +from onionshare.settings import Settings # # Stub get_resource_path so it finds the correct path while running tests # def get_resource_path(filename): @@ -40,6 +40,7 @@ class TestLoadStrings: def test_load_strings_defaults_to_english( self, common_obj, locale_en, sys_onionshare_dev_mode): """ load_strings() loads English by default """ + common_obj.settings = Settings(common_obj) strings.load_strings(common_obj) assert strings._('preparing_files') == "Compressing files." @@ -47,6 +48,7 @@ class TestLoadStrings: def test_load_strings_loads_other_languages( self, common_obj, locale_fr, sys_onionshare_dev_mode): """ load_strings() loads other languages in different locales """ + common_obj.settings = Settings(common_obj) common_obj.settings.set('locale', 'fr') strings.load_strings(common_obj) assert strings._('preparing_files') == "Préparation des fichiers à partager." @@ -55,5 +57,6 @@ class TestLoadStrings: self, common_obj, locale_invalid, sys_onionshare_dev_mode): """ load_strings() raises a KeyError for an invalid locale """ with pytest.raises(KeyError): + common_obj.settings = Settings(common_obj) common_obj.settings.set('locale', 'XX') strings.load_strings(common_obj) diff --git a/tests/test_onionshare_web.py b/tests/test_onionshare_web.py index 24a0e163..d42adde4 100644 --- a/tests/test_onionshare_web.py +++ b/tests/test_onionshare_web.py @@ -31,6 +31,7 @@ import tempfile import pytest from onionshare.common import Common +from onionshare import strings from onionshare.web import Web from onionshare.settings import Settings @@ -41,7 +42,7 @@ RANDOM_STR_REGEX = re.compile(r'^[a-z2-7]+$') def web_obj(common_obj, mode, num_files=0): """ Creates a Web object, in either share mode or receive mode, ready for testing """ common_obj.load_settings() - + strings.load_strings(common_obj) web = Web(common_obj, False, mode) web.generate_slug() web.stay_open = True diff --git a/tests_gui/__init__.py b/tests_gui/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests_gui/conftest.py b/tests_gui/conftest.py deleted file mode 100644 index 62108e05..00000000 --- a/tests_gui/conftest.py +++ /dev/null @@ -1,176 +0,0 @@ -import sys -# Force tests to look for resources in the source code tree -sys.onionshare_dev_mode = True - -import os -import shutil -import tempfile - -import pytest - -from onionshare import common, web, settings - -def pytest_addoption(parser): - parser.addoption( - "--runtor", action="store_true", default=False, help="run tor tests" - ) - - -def pytest_collection_modifyitems(config, items): - if config.getoption("--runtor"): - # --runtor given in cli: do not skip tor tests - return - skip_tor = pytest.mark.skip(reason="need --runtor option to run") - for item in items: - if "tor" in item.keywords: - item.add_marker(skip_tor) - - -@pytest.fixture -def temp_dir_1024(): - """ Create a temporary directory that has a single file of a - particular size (1024 bytes). - """ - - tmp_dir = tempfile.mkdtemp() - tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir) - with open(tmp_file, 'wb') as f: - f.write(b'*' * 1024) - return tmp_dir - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture -def temp_dir_1024_delete(): - """ Create a temporary directory that has a single file of a - particular size (1024 bytes). The temporary directory (including - the file inside) will be deleted after fixture usage. - """ - - with tempfile.TemporaryDirectory() as tmp_dir: - tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir) - with open(tmp_file, 'wb') as f: - f.write(b'*' * 1024) - yield tmp_dir - - -@pytest.fixture -def temp_file_1024(): - """ Create a temporary file of a particular size (1024 bytes). """ - - with tempfile.NamedTemporaryFile(delete=False) as tmp_file: - tmp_file.write(b'*' * 1024) - return tmp_file.name - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture -def temp_file_1024_delete(): - """ - Create a temporary file of a particular size (1024 bytes). - The temporary file will be deleted after fixture usage. - """ - - with tempfile.NamedTemporaryFile() as tmp_file: - tmp_file.write(b'*' * 1024) - tmp_file.flush() - yield tmp_file.name - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture(scope='session') -def custom_zw(): - zw = web.share_mode.ZipWriter( - common.Common(), - zip_filename=common.Common.random_string(4, 6), - processed_size_callback=lambda _: 'custom_callback' - ) - yield zw - zw.close() - os.remove(zw.zip_filename) - - -# pytest > 2.9 only needs @pytest.fixture -@pytest.yield_fixture(scope='session') -def default_zw(): - zw = web.share_mode.ZipWriter(common.Common()) - yield zw - zw.close() - tmp_dir = os.path.dirname(zw.zip_filename) - shutil.rmtree(tmp_dir) - - -@pytest.fixture -def locale_en(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8')) - - -@pytest.fixture -def locale_fr(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8')) - - -@pytest.fixture -def locale_invalid(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8')) - - -@pytest.fixture -def locale_ru(monkeypatch): - monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8')) - - -@pytest.fixture -def platform_darwin(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Darwin') - - -@pytest.fixture # (scope="session") -def platform_linux(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Linux') - - -@pytest.fixture -def platform_windows(monkeypatch): - monkeypatch.setattr('platform.system', lambda: 'Windows') - - -@pytest.fixture -def sys_argv_sys_prefix(monkeypatch): - monkeypatch.setattr('sys.argv', [sys.prefix]) - - -@pytest.fixture -def sys_frozen(monkeypatch): - monkeypatch.setattr('sys.frozen', True, raising=False) - - -@pytest.fixture -def sys_meipass(monkeypatch): - monkeypatch.setattr( - 'sys._MEIPASS', os.path.expanduser('~'), raising=False) - - -@pytest.fixture # (scope="session") -def sys_onionshare_dev_mode(monkeypatch): - monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False) - - -@pytest.fixture -def time_time_100(monkeypatch): - monkeypatch.setattr('time.time', lambda: 100) - - -@pytest.fixture -def time_strftime(monkeypatch): - monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00') - -@pytest.fixture -def common_obj(): - return common.Common() - -@pytest.fixture -def settings_obj(sys_onionshare_dev_mode, platform_linux): - _common = common.Common() - _common.version = 'DUMMY_VERSION_1.2.3' - return settings.Settings(_common) diff --git a/tests_gui/run_unit_tests.sh b/tests_gui/run_unit_tests.sh deleted file mode 100755 index 81542749..00000000 --- a/tests_gui/run_unit_tests.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -for test in `ls -1 | egrep ^local_`; do - pytest $test -vvv || exit 1 -done From 0698f8ca6d93a161c586711e7b62d6ba5a2d123b Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 13 Oct 2018 10:39:26 +1100 Subject: [PATCH 15/72] Update test documentation --- BUILD.md | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/BUILD.md b/BUILD.md index 00d24cd2..b92f4110 100644 --- a/BUILD.md +++ b/BUILD.md @@ -143,24 +143,16 @@ OnionShare includes PyTest unit tests. To run the tests, first install some depe pip3 install -r install/requirements-tests.txt ``` -If you'd like to run the CLI-based tests that Travis runs: +Then you can run `pytest` against the `tests/` directory. ```sh pytest tests/ ``` -If you would like to run the GUI unit tests in 'local only mode': +If you would like to also run the GUI unit tests in 'tor' mode, start Tor Browser in the background, then run: ```sh -cd tests_gui_local/ -./run_unit_tests.sh -``` - -If you would like to run the GUI unit tests in 'tor' (bundled) mode: - -```sh -cd tests_gui_tor/ -./run_unit_tests.sh +pytest --runtor tests/ ``` Keep in mind that the Tor tests take a lot longer to run than local mode, but they are also more comprehensive. From 5df43ed232545c5a94d925f59ff33967afc4badd Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sun, 14 Oct 2018 09:22:09 +1100 Subject: [PATCH 16/72] Remove unnecessary dependencies --- tests/TorGuiBaseTest.py | 3 --- tests/TorGuiShareTest.py | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py index b182b1d4..82ecc1b4 100644 --- a/tests/TorGuiBaseTest.py +++ b/tests/TorGuiBaseTest.py @@ -1,8 +1,5 @@ import json -import os import requests -import shutil -import socket import socks from PyQt5 import QtCore, QtTest diff --git a/tests/TorGuiShareTest.py b/tests/TorGuiShareTest.py index 8e17abad..aa622b4f 100644 --- a/tests/TorGuiShareTest.py +++ b/tests/TorGuiShareTest.py @@ -1,7 +1,6 @@ import requests -import socks import zipfile -from PyQt5 import QtCore, QtTest +from PyQt5 import QtTest from .TorGuiBaseTest import TorGuiBaseTest from .GuiShareTest import GuiShareTest From 7329cd0fa5599ca0a684c7ce8873ec68a8563d84 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sun, 14 Oct 2018 14:26:22 +1100 Subject: [PATCH 17/72] Fix class name of Tor persistent mode test --- tests/onionshare_share_mode_persistent_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/onionshare_share_mode_persistent_test.py b/tests/onionshare_share_mode_persistent_test.py index 665aecd5..9a813e5d 100644 --- a/tests/onionshare_share_mode_persistent_test.py +++ b/tests/onionshare_share_mode_persistent_test.py @@ -4,7 +4,7 @@ import unittest from .TorGuiShareTest import TorGuiShareTest -class LocalShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest): +class ShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest): @classmethod def setUpClass(cls): test_settings = { From 1a1d3d9c8aa2c0cfb2bc8f92798def5b96b14132 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sun, 14 Oct 2018 15:11:57 +1100 Subject: [PATCH 18/72] fix stealth test. Remove tor connection killed test, because it doesn't work like this in 'automatic' connection mode which we need for Mac/Windows testing --- tests/TorGuiBaseTest.py | 7 ---- tests/onionshare_share_mode_stealth_test.py | 10 +---- ...e_share_mode_tor_connection_killed_test.py | 41 ------------------- 3 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 tests/onionshare_share_mode_tor_connection_killed_test.py diff --git a/tests/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py index 82ecc1b4..2fadfab7 100644 --- a/tests/TorGuiBaseTest.py +++ b/tests/TorGuiBaseTest.py @@ -149,10 +149,3 @@ class TorGuiBaseTest(GuiBaseTest): def hidserv_auth_string(self): '''Test the validity of the HidservAuth string''' self.assertRegex(self.gui.app.auth_string, r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host) - - # Miscellaneous tests - def tor_killed_statusbar_message_shown(self, mode): - '''Test that the status bar message shows Tor was disconnected''' - self.gui.app.onion.cleanup(stop_tor=True) - QtTest.QTest.qWait(2500) - self.assertTrue(mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost')) diff --git a/tests/onionshare_share_mode_stealth_test.py b/tests/onionshare_share_mode_stealth_test.py index a6bbe08e..d7e13540 100644 --- a/tests/onionshare_share_mode_stealth_test.py +++ b/tests/onionshare_share_mode_stealth_test.py @@ -19,18 +19,10 @@ class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest): @pytest.mark.run(after='test_run_all_common_setup_tests') @pytest.mark.tor - def test_run_share_mode_setup_tests(self): + def test_run_stealth_mode_tests(self): self.run_all_share_mode_setup_tests() self.run_all_share_mode_started_tests(False) - - @pytest.mark.run(after='test_run_share_mode_setup_tests') - @pytest.mark.tor - def test_copy_have_hidserv_auth_button(self): self.copy_have_hidserv_auth_button(self.gui.share_mode) - - @pytest.mark.run(after='test_run_share_mode_setup_tests') - @pytest.mark.tor - def test_hidserv_auth_string(self): self.hidserv_auth_string() if __name__ == "__main__": diff --git a/tests/onionshare_share_mode_tor_connection_killed_test.py b/tests/onionshare_share_mode_tor_connection_killed_test.py deleted file mode 100644 index 9112aedd..00000000 --- a/tests/onionshare_share_mode_tor_connection_killed_test.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python3 -import pytest -import unittest - -from .TorGuiShareTest import TorGuiShareTest - -class ShareModeTorConnectionKilledTest(unittest.TestCase, TorGuiShareTest): - @classmethod - def setUpClass(cls): - test_settings = { - } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTorConnectionKilledTest') - - @pytest.mark.tor - def test_run_all_common_setup_tests(self): - self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_share_mode_setup_tests(self): - self.run_all_share_mode_setup_tests() - self.run_all_share_mode_started_tests(False) - - @pytest.mark.run(after='test_run_share_mode_setup_tests') - @pytest.mark.tor - def test_tor_killed_statusbar_message_shown(self): - self.tor_killed_statusbar_message_shown(self.gui.share_mode) - - @pytest.mark.run(after='test_tor_killed_statusbar_message_shown') - @pytest.mark.tor - def test_server_is_stopped(self): - self.server_is_stopped(self.gui.share_mode, False) - - @pytest.mark.run(after='test_tor_killed_statusbar_message_shown') - @pytest.mark.tor - def test_web_service_is_stopped(self): - self.web_service_is_stopped() - - -if __name__ == "__main__": - unittest.main() From 668aa66323d2009f5c18ce62b3b084f6a55366ae Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 15 Oct 2018 11:15:32 +1100 Subject: [PATCH 19/72] Move GUI tests into a single function each, which solves ordering bugs, and also means we don't need to depend on pytest-ordering --- install/requirements-tests.txt | 1 - ...are_receive_mode_upload_public_mode_test.py | 5 +---- ...ocal_onionshare_receive_mode_upload_test.py | 5 +---- ...are_share_mode_download_public_mode_test.py | 5 +---- ...share_share_mode_download_stay_open_test.py | 5 +---- ...ocal_onionshare_share_mode_download_test.py | 5 +---- ...ionshare_share_mode_slug_persistent_test.py | 5 +---- .../local_onionshare_share_mode_timer_test.py | 5 +---- ...ionshare_790_cancel_on_second_share_test.py | 18 +----------------- ...are_receive_mode_upload_public_mode_test.py | 6 +----- tests/onionshare_receive_mode_upload_test.py | 6 +----- .../onionshare_share_mode_cancel_share_test.py | 10 +--------- ...are_share_mode_download_public_mode_test.py | 6 +----- ...share_share_mode_download_stay_open_test.py | 6 +----- tests/onionshare_share_mode_download_test.py | 6 +----- tests/onionshare_share_mode_persistent_test.py | 6 +----- tests/onionshare_share_mode_stealth_test.py | 6 +----- tests/onionshare_share_mode_timer_test.py | 6 +----- 18 files changed, 17 insertions(+), 95 deletions(-) diff --git a/install/requirements-tests.txt b/install/requirements-tests.txt index 0d9c1581..b931afd1 100644 --- a/install/requirements-tests.txt +++ b/install/requirements-tests.txt @@ -5,7 +5,6 @@ pluggy==0.6.0 py==1.6.0 pytest==3.4.2 pytest-faulthandler==1.5.0 -pytest-ordering==0.5 pytest-qt==3.1.0 six==1.11.0 urllib3==1.23 diff --git a/tests/local_onionshare_receive_mode_upload_public_mode_test.py b/tests/local_onionshare_receive_mode_upload_public_mode_test.py index 27bf9b2c..c99fae52 100644 --- a/tests/local_onionshare_receive_mode_upload_public_mode_test.py +++ b/tests/local_onionshare_receive_mode_upload_public_mode_test.py @@ -13,11 +13,8 @@ class LocalReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModePublicModeTest') - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - def test_run_all_receive_mode_tests(self): self.run_all_receive_mode_tests(True, True) if __name__ == "__main__": diff --git a/tests/local_onionshare_receive_mode_upload_test.py b/tests/local_onionshare_receive_mode_upload_test.py index f6594105..dc6c1f06 100644 --- a/tests/local_onionshare_receive_mode_upload_test.py +++ b/tests/local_onionshare_receive_mode_upload_test.py @@ -12,11 +12,8 @@ class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - def test_run_all_receive_mode_tests(self): self.run_all_receive_mode_tests(False, True) if __name__ == "__main__": diff --git a/tests/local_onionshare_share_mode_download_public_mode_test.py b/tests/local_onionshare_share_mode_download_public_mode_test.py index 2a3f9584..bfed9443 100644 --- a/tests/local_onionshare_share_mode_download_public_mode_test.py +++ b/tests/local_onionshare_share_mode_download_public_mode_test.py @@ -12,11 +12,8 @@ class LocalShareModePublicModeTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePublicModeTest') - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(True, False) if __name__ == "__main__": diff --git a/tests/local_onionshare_share_mode_download_stay_open_test.py b/tests/local_onionshare_share_mode_download_stay_open_test.py index 1f734ae7..b68516a2 100644 --- a/tests/local_onionshare_share_mode_download_stay_open_test.py +++ b/tests/local_onionshare_share_mode_download_stay_open_test.py @@ -12,11 +12,8 @@ class LocalShareModeStayOpenTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeStayOpenTest') - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(False, True) if __name__ == "__main__": diff --git a/tests/local_onionshare_share_mode_download_test.py b/tests/local_onionshare_share_mode_download_test.py index 274cc311..a2a16c96 100644 --- a/tests/local_onionshare_share_mode_download_test.py +++ b/tests/local_onionshare_share_mode_download_test.py @@ -11,11 +11,8 @@ class LocalShareModeTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(False, False) if __name__ == "__main__": diff --git a/tests/local_onionshare_share_mode_slug_persistent_test.py b/tests/local_onionshare_share_mode_slug_persistent_test.py index 3450ec3f..03285fa1 100644 --- a/tests/local_onionshare_share_mode_slug_persistent_test.py +++ b/tests/local_onionshare_share_mode_slug_persistent_test.py @@ -15,11 +15,8 @@ class LocalShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePersistentSlugTest') - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - def test_run_all_share_mode_tests(self): self.run_all_share_mode_persistent_tests(False, True) if __name__ == "__main__": diff --git a/tests/local_onionshare_share_mode_timer_test.py b/tests/local_onionshare_share_mode_timer_test.py index f9f36c48..3d20efc4 100644 --- a/tests/local_onionshare_share_mode_timer_test.py +++ b/tests/local_onionshare_share_mode_timer_test.py @@ -13,11 +13,8 @@ class LocalShareModeTimerTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTest') - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - def test_run_all_share_mode_timer_tests(self): self.run_all_share_mode_timer_tests(False) if __name__ == "__main__": diff --git a/tests/onionshare_790_cancel_on_second_share_test.py b/tests/onionshare_790_cancel_on_second_share_test.py index 36725fb0..21747d4c 100644 --- a/tests/onionshare_790_cancel_on_second_share_test.py +++ b/tests/onionshare_790_cancel_on_second_share_test.py @@ -14,27 +14,11 @@ class ShareModeCancelSecondShareTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelSecondShareTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_share_mode_tests(self): self.run_all_share_mode_tests(False, False) - - @pytest.mark.run(after='test_run_share_mode_tests') - @pytest.mark.tor - def test_cancel_the_share(self): self.cancel_the_share(self.gui.share_mode) - - @pytest.mark.run(after='test_cancel_the_share') - @pytest.mark.tor - def test_server_is_stopped_round2(self): self.server_is_stopped(self.gui.share_mode, False) - - @pytest.mark.run(after='test_server_is_stopped_round2') - @pytest.mark.tor - def test_web_service_is_stopped_round2(self): self.web_service_is_stopped() if __name__ == "__main__": diff --git a/tests/onionshare_receive_mode_upload_public_mode_test.py b/tests/onionshare_receive_mode_upload_public_mode_test.py index ee0c5c34..56b49c81 100644 --- a/tests/onionshare_receive_mode_upload_public_mode_test.py +++ b/tests/onionshare_receive_mode_upload_public_mode_test.py @@ -14,12 +14,8 @@ class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_all_receive_mode_tests(self): self.run_all_receive_mode_tests(True, True) if __name__ == "__main__": diff --git a/tests/onionshare_receive_mode_upload_test.py b/tests/onionshare_receive_mode_upload_test.py index f1f683cc..0fd8d5ed 100644 --- a/tests/onionshare_receive_mode_upload_test.py +++ b/tests/onionshare_receive_mode_upload_test.py @@ -13,12 +13,8 @@ class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_all_receive_mode_tests(self): self.run_all_receive_mode_tests(False, True) if __name__ == "__main__": diff --git a/tests/onionshare_share_mode_cancel_share_test.py b/tests/onionshare_share_mode_cancel_share_test.py index 97adf9ce..9770cc35 100644 --- a/tests/onionshare_share_mode_cancel_share_test.py +++ b/tests/onionshare_share_mode_cancel_share_test.py @@ -12,17 +12,9 @@ class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_share_mode_setup_tests(self): self.run_all_share_mode_setup_tests() - - @pytest.mark.run(after='test_run_share_mode_setup_tests') - @pytest.mark.tor - def test_cancel_the_share(self): self.cancel_the_share(self.gui.share_mode) if __name__ == "__main__": diff --git a/tests/onionshare_share_mode_download_public_mode_test.py b/tests/onionshare_share_mode_download_public_mode_test.py index a4a3bfb1..8409720a 100644 --- a/tests/onionshare_share_mode_download_public_mode_test.py +++ b/tests/onionshare_share_mode_download_public_mode_test.py @@ -13,12 +13,8 @@ class ShareModePublicModeTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(True, False) if __name__ == "__main__": diff --git a/tests/onionshare_share_mode_download_stay_open_test.py b/tests/onionshare_share_mode_download_stay_open_test.py index 33544217..c16f91e9 100644 --- a/tests/onionshare_share_mode_download_stay_open_test.py +++ b/tests/onionshare_share_mode_download_stay_open_test.py @@ -13,12 +13,8 @@ class ShareModeStayOpenTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(False, True) if __name__ == "__main__": diff --git a/tests/onionshare_share_mode_download_test.py b/tests/onionshare_share_mode_download_test.py index 8d6d9655..194328d9 100644 --- a/tests/onionshare_share_mode_download_test.py +++ b/tests/onionshare_share_mode_download_test.py @@ -12,12 +12,8 @@ class ShareModeTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_all_share_mode_tests(self): self.run_all_share_mode_tests(False, False) if __name__ == "__main__": diff --git a/tests/onionshare_share_mode_persistent_test.py b/tests/onionshare_share_mode_persistent_test.py index 9a813e5d..3c283943 100644 --- a/tests/onionshare_share_mode_persistent_test.py +++ b/tests/onionshare_share_mode_persistent_test.py @@ -17,12 +17,8 @@ class ShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_all_share_mode_tests(self): self.run_all_share_mode_persistent_tests(False, True) if __name__ == "__main__": diff --git a/tests/onionshare_share_mode_stealth_test.py b/tests/onionshare_share_mode_stealth_test.py index d7e13540..b414de1f 100644 --- a/tests/onionshare_share_mode_stealth_test.py +++ b/tests/onionshare_share_mode_stealth_test.py @@ -14,12 +14,8 @@ class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStealthTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_stealth_mode_tests(self): self.run_all_share_mode_setup_tests() self.run_all_share_mode_started_tests(False) self.copy_have_hidserv_auth_button(self.gui.share_mode) diff --git a/tests/onionshare_share_mode_timer_test.py b/tests/onionshare_share_mode_timer_test.py index 32e28c00..b53905d0 100644 --- a/tests/onionshare_share_mode_timer_test.py +++ b/tests/onionshare_share_mode_timer_test.py @@ -14,12 +14,8 @@ class ShareModeTimerTest(unittest.TestCase, TorGuiShareTest): cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTimerTest') @pytest.mark.tor - def test_run_all_common_setup_tests(self): + def test_gui(self): self.run_all_common_setup_tests() - - @pytest.mark.run(after='test_run_all_common_setup_tests') - @pytest.mark.tor - def test_run_all_share_mode_timer_tests(self): self.run_all_share_mode_timer_tests(False) if __name__ == "__main__": From 57b105b631275217f1254843fcd6f2d0c59e4f5e Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Mon, 15 Oct 2018 17:33:21 +1100 Subject: [PATCH 20/72] Remove second arg from two calls to strings() --- onionshare_gui/mode/share_mode/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare_gui/mode/share_mode/__init__.py b/onionshare_gui/mode/share_mode/__init__.py index 62c5d8a7..436d42f7 100644 --- a/onionshare_gui/mode/share_mode/__init__.py +++ b/onionshare_gui/mode/share_mode/__init__.py @@ -284,7 +284,7 @@ class ShareMode(Mode): # Update in progress count self.history.in_progress_count -= 1 self.history.update_in_progress() - self.system_tray.showMessage(strings._('systray_download_canceled_title', True), strings._('systray_download_canceled_message', True)) + self.system_tray.showMessage(strings._('systray_download_canceled_title'), strings._('systray_download_canceled_message')) def on_reload_settings(self): """ From b2a7b0c929f4f142a4f8b2c4ca541b2a88d2815d Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 16 Oct 2018 13:01:44 +1100 Subject: [PATCH 21/72] More coverage such as 404 ratelimit, large file tests. Standardise some method naming conventions and other fixes/cleanup --- tests/GuiBaseTest.py | 80 +++++++++++---- tests/GuiReceiveTest.py | 65 ++++++++++-- tests/GuiShareTest.py | 99 ++++++++++++------- tests/TorGuiBaseTest.py | 31 ++++-- tests/TorGuiReceiveTest.py | 14 ++- tests/TorGuiShareTest.py | 31 +++++- ...re_404_public_mode_skips_ratelimit_test.py | 21 ++++ ..._onionshare_404_triggers_ratelimit_test.py | 20 ++++ ...onshare_receive_mode_sender_closed_test.py | 20 ++++ ...ocal_onionshare_receive_mode_timer_test.py | 20 ++++ ...ceive_mode_upload_non_writable_dir_test.py | 19 ++++ ...re_receive_mode_upload_public_mode_test.py | 1 - ...cal_onionshare_receive_mode_upload_test.py | 1 - ...re_share_mode_download_public_mode_test.py | 1 - ...hare_share_mode_download_stay_open_test.py | 1 - ...cal_onionshare_share_mode_download_test.py | 1 - ...ionshare_share_mode_large_download_test.py | 18 ++++ ...onshare_share_mode_slug_persistent_test.py | 1 - .../local_onionshare_share_mode_timer_test.py | 1 - ...onshare_790_cancel_on_second_share_test.py | 2 +- 20 files changed, 360 insertions(+), 87 deletions(-) create mode 100644 tests/local_onionshare_404_public_mode_skips_ratelimit_test.py create mode 100644 tests/local_onionshare_404_triggers_ratelimit_test.py create mode 100644 tests/local_onionshare_receive_mode_sender_closed_test.py create mode 100644 tests/local_onionshare_receive_mode_timer_test.py create mode 100644 tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py create mode 100644 tests/local_onionshare_share_mode_large_download_test.py diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index 79543468..e2f194db 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -26,6 +26,13 @@ class GuiBaseTest(object): testfile.write('onionshare') testfile.close() + # Create a test dir and files + if not os.path.exists('/tmp/testdir'): + testdir = os.mkdir('/tmp/testdir') + testfile = open('/tmp/testdir/test.txt', 'w') + testfile.write('onionshare') + testfile.close() + common = Common() common.settings = Settings(common) common.define_css() @@ -46,14 +53,17 @@ class GuiBaseTest(object): web = Web(common, False, True) open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) - gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], '/tmp/{}.json'.format(settings_filename), True) + gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/{}.json'.format(settings_filename), True) return gui @staticmethod def tear_down(): + '''Clean up after tests''' try: os.remove('/tmp/test.txt') + os.remove('/tmp/largefile') shutil.rmtree('/tmp/OnionShare') + shutil.rmtree('/tmp/testdir') except: pass @@ -72,6 +82,11 @@ class GuiBaseTest(object): '''Test that the settings button is visible''' self.assertTrue(self.gui.settings_button.isVisible()) + + def settings_button_is_hidden(self): + '''Test that the settings button is hidden when the server starts''' + self.assertFalse(self.gui.settings_button.isVisible()) + def server_status_bar_is_visible(self): '''Test that the status bar is visible''' @@ -152,22 +167,17 @@ class GuiBaseTest(object): def server_status_indicator_says_starting(self, mode): '''Test that the Server Status indicator shows we are Starting''' - self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) + self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_working')) - def settings_button_is_hidden(self): - '''Test that the settings button is hidden when the server starts''' - self.assertFalse(self.gui.settings_button.isVisible()) - - - def a_server_is_started(self, mode): + def server_is_started(self, mode, startup_time=2000): '''Test that the server has started''' - QtTest.QTest.qWait(2000) + QtTest.QTest.qWait(startup_time) # Should now be in SERVER_STARTED state self.assertEqual(mode.server_status.status, 2) - def a_web_server_is_running(self): + def web_server_is_running(self): '''Test that the web server has started''' sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -187,17 +197,24 @@ class GuiBaseTest(object): self.assertTrue(mode.server_status.url_description.isVisible()) - def have_copy_url_button(self, mode): - '''Test that the Copy URL button is shown''' + def have_copy_url_button(self, mode, public_mode): + '''Test that the Copy URL button is shown and that the clipboard is correct''' self.assertTrue(mode.server_status.copy_url_button.isVisible()) + QtTest.QTest.mouseClick(mode.server_status.copy_url_button, QtCore.Qt.LeftButton) + clipboard = self.gui.qtapp.clipboard() + if public_mode: + self.assertEqual(clipboard.text(), 'http://127.0.0.1:{}'.format(self.gui.app.port)) + else: + self.assertEqual(clipboard.text(), 'http://127.0.0.1:{}/{}'.format(self.gui.app.port, mode.server_status.web.slug)) + def server_status_indicator_says_started(self, mode): '''Test that the Server Status indicator shows we are started''' if type(mode) == ReceiveMode: - self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_receive_started')) + self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_receive_started')) if type(mode) == ShareMode: - self.assertEquals(mode.server_status_label.text(), strings._('gui_status_indicator_share_started')) + self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_started')) def web_page(self, mode, string, public_mode): @@ -237,17 +254,17 @@ class GuiBaseTest(object): def counter_incremented(self, mode, count): '''Test that the counter has incremented''' - self.assertEquals(mode.history.completed_count, count) + self.assertEqual(mode.history.completed_count, count) def server_is_stopped(self, mode, stay_open): '''Test that the server stops when we click Stop''' if type(mode) == ReceiveMode or (type(mode) == ShareMode and stay_open): QtTest.QTest.mouseClick(mode.server_status.server_button, QtCore.Qt.LeftButton) - self.assertEquals(mode.server_status.status, 0) + self.assertEqual(mode.server_status.status, 0) - def web_service_is_stopped(self): + def web_server_is_stopped(self): '''Test that the web server also stopped''' QtTest.QTest.qWait(2000) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -259,12 +276,35 @@ class GuiBaseTest(object): def server_status_indicator_says_closed(self, mode, stay_open): '''Test that the Server Status indicator shows we closed''' if type(mode) == ReceiveMode: - self.assertEquals(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped')) + self.assertEqual(self.gui.receive_mode.server_status_label.text(), strings._('gui_status_indicator_receive_stopped')) if type(mode) == ShareMode: if stay_open: - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped')) + self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('gui_status_indicator_share_stopped')) else: - self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically')) + self.assertEqual(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically')) + + + # Auto-stop timer tests + def set_timeout(self, mode, timeout): + '''Test that the timeout can be set''' + timer = QtCore.QDateTime.currentDateTime().addSecs(timeout) + mode.server_status.shutdown_timeout.setDateTime(timer) + self.assertTrue(mode.server_status.shutdown_timeout.dateTime(), timer) + + + def timeout_widget_hidden(self, mode): + '''Test that the timeout widget is hidden when share has started''' + self.assertFalse(mode.server_status.shutdown_timeout_container.isVisible()) + + + def server_timed_out(self, mode, wait): + '''Test that the server has timed out after the timer ran out''' + QtTest.QTest.qWait(wait) + # We should have timed out now + self.assertEqual(mode.server_status.status, 0) + + + # 'Grouped' tests follow from here def run_all_common_setup_tests(self): self.gui_loaded() diff --git a/tests/GuiReceiveTest.py b/tests/GuiReceiveTest.py index 1fa5c4dc..84d6a55a 100644 --- a/tests/GuiReceiveTest.py +++ b/tests/GuiReceiveTest.py @@ -15,7 +15,39 @@ class GuiReceiveTest(GuiBaseTest): QtTest.QTest.qWait(2000) self.assertTrue(os.path.isfile(expected_file)) - def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): + def upload_file_should_fail(self, public_mode, expected_file): + '''Test that we can't upload the file when permissions are wrong, and expected content is shown''' + files = {'file[]': open('/tmp/test.txt', 'rb')} + if not public_mode: + path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug) + else: + path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port) + response = requests.post(path, files=files) + + # A nasty hack to avoid the Alert dialog that blocks the rest of the test + self.gui.qtapp.exit() + self.assertTrue('Error uploading, please inform the OnionShare user' in response.text) + + def upload_dir_permissions(self, mode=0o755): + '''Manipulate the permissions on the upload dir in between tests''' + os.chmod('/tmp/OnionShare', mode) + + def run_receive_mode_sender_closed_tests(self, public_mode): + '''Test that the share can be stopped by the sender in receive mode''' + if not public_mode: + path = 'http://127.0.0.1:{}/{}/close'.format(self.gui.app.port, self.gui.receive_mode.web.slug) + else: + path = 'http://127.0.0.1:{}/close'.format(self.gui.app.port) + response = requests.post(path) + self.server_is_stopped(self.gui.receive_mode, False) + self.web_server_is_stopped() + self.server_status_indicator_says_closed(self.gui.receive_mode, False) + + + # 'Grouped' tests follow from here + + def run_all_receive_mode_setup_tests(self, public_mode): + '''Set up a share in Receive mode and start it''' self.click_mode(self.gui.receive_mode) self.history_is_not_visible(self.gui.receive_mode) self.click_toggle_history(self.gui.receive_mode) @@ -23,13 +55,17 @@ class GuiReceiveTest(GuiBaseTest): self.server_working_on_start_button_pressed(self.gui.receive_mode) self.server_status_indicator_says_starting(self.gui.receive_mode) self.settings_button_is_hidden() - self.a_server_is_started(self.gui.receive_mode) - self.a_web_server_is_running() + self.server_is_started(self.gui.receive_mode) + self.web_server_is_running() self.have_a_slug(self.gui.receive_mode, public_mode) self.url_description_shown(self.gui.receive_mode) - self.have_copy_url_button(self.gui.receive_mode) + self.have_copy_url_button(self.gui.receive_mode, public_mode) self.server_status_indicator_says_started(self.gui.receive_mode) self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode) + + def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): + '''Upload files in receive mode and stop the share''' + self.run_all_receive_mode_setup_tests(public_mode) self.upload_file(public_mode, '/tmp/OnionShare/test.txt') self.history_widgets_present(self.gui.receive_mode) self.counter_incremented(self.gui.receive_mode, 1) @@ -37,9 +73,26 @@ class GuiReceiveTest(GuiBaseTest): self.counter_incremented(self.gui.receive_mode, 2) self.history_indicator(self.gui.receive_mode, public_mode) self.server_is_stopped(self.gui.receive_mode, False) - self.web_service_is_stopped() + self.web_server_is_stopped() self.server_status_indicator_says_closed(self.gui.receive_mode, False) self.server_working_on_start_button_pressed(self.gui.receive_mode) - self.a_server_is_started(self.gui.receive_mode) + self.server_is_started(self.gui.receive_mode) self.history_indicator(self.gui.receive_mode, public_mode) + def run_all_receive_mode_unwritable_dir_tests(self, public_mode, receive_allow_receiver_shutdown): + '''Attempt to upload (unwritable) files in receive mode and stop the share''' + self.run_all_receive_mode_setup_tests(public_mode) + self.upload_dir_permissions(0o400) + self.upload_file_should_fail(public_mode, '/tmp/OnionShare/test.txt') + self.server_is_stopped(self.gui.receive_mode, True) + self.web_server_is_stopped() + self.server_status_indicator_says_closed(self.gui.receive_mode, False) + self.upload_dir_permissions(0o755) + + def run_all_receive_mode_timer_tests(self, public_mode): + """Auto-stop timer tests in receive mode""" + self.run_all_receive_mode_setup_tests(public_mode) + self.set_timeout(self.gui.receive_mode, 5) + self.timeout_widget_hidden(self.gui.receive_mode) + self.server_timed_out(self.gui.receive_mode, 15000) + self.web_server_is_stopped() diff --git a/tests/GuiShareTest.py b/tests/GuiShareTest.py index 34149dec..4f2f58e7 100644 --- a/tests/GuiShareTest.py +++ b/tests/GuiShareTest.py @@ -1,29 +1,11 @@ +import os +import requests import socks import zipfile from PyQt5 import QtCore, QtTest from .GuiBaseTest import GuiBaseTest class GuiShareTest(GuiBaseTest): - # Auto-stop timer tests - - def set_timeout(self, mode, timeout): - '''Test that the timeout can be set''' - timer = QtCore.QDateTime.currentDateTime().addSecs(timeout) - mode.server_status.shutdown_timeout.setDateTime(timer) - self.assertTrue(mode.server_status.shutdown_timeout.dateTime(), timer) - - - def timeout_widget_hidden(self, mode): - '''Test that the timeout widget is hidden when share has started''' - self.assertFalse(mode.server_status.shutdown_timeout_container.isVisible()) - - - def server_timed_out(self, mode, wait): - '''Test that the server has timed out after the timer ran out''' - QtTest.QTest.qWait(wait) - # 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''' @@ -31,19 +13,26 @@ class GuiShareTest(GuiBaseTest): # Share-specific tests - def file_selection_widget_has_a_file(self): - '''Test that the number of files in the list is 1''' - self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 1) + def file_selection_widget_has_files(self): + '''Test that the number of items in the list is 2''' + self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2) - def deleting_only_file_hides_delete_button(self): + def deleting_all_files_hides_delete_button(self): '''Test that clicking on the file item shows the delete button. Test that deleting the only item in the list hides the delete button''' rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0)) QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center()) # Delete button should be visible self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) - # Click delete, and since there's no more files, the delete button should be hidden + # Click delete, delete button should still be visible since we have one more file QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton) + + rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(self.gui.share_mode.server_status.file_selection.file_list.item(0)) + QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.viewport(), QtCore.Qt.LeftButton, pos=rect.center()) + self.assertTrue(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) + QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.delete_button, QtCore.Qt.LeftButton) + + # No more files, the delete button should be hidden self.assertFalse(self.gui.share_mode.server_status.file_selection.delete_button.isVisible()) @@ -60,7 +49,15 @@ class GuiShareTest(GuiBaseTest): self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/test.txt') self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2) + + def add_large_file(self): + '''Add a large file to the share''' + size = 1024*1024*155 + with open('/tmp/large_file', 'wb') as fout: + fout.write(os.urandom(size)) + self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/large_file') + def add_delete_buttons_hidden(self): '''Test that the add and delete buttons are hidden when the server starts''' self.assertFalse(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) @@ -95,35 +92,56 @@ class GuiShareTest(GuiBaseTest): QtTest.QTest.qWait(2000) self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8')) - + def hit_404(self, public_mode): + '''Test that the server stops after too many 404s, or doesn't when in public_mode''' + bogus_path = '/gimme' + url = "http://127.0.0.1:{}/{}".format(self.gui.app.port, bogus_path) + + for _ in range(20): + r = requests.get(url) + + # A nasty hack to avoid the Alert dialog that blocks the rest of the test + if not public_mode: + self.gui.qtapp.exit() + + # In public mode, we should still be running (no rate-limiting) + if public_mode: + self.web_server_is_running() + # In non-public mode, we should be shut down (rate-limiting) + else: + self.web_server_is_stopped() + + def add_button_visible(self): '''Test that the add button should be visible''' self.assertTrue(self.gui.share_mode.server_status.file_selection.add_button.isVisible()) + # 'Grouped' tests follow from here + def run_all_share_mode_setup_tests(self): """Tests in share mode prior to starting a share""" self.click_mode(self.gui.share_mode) - self.file_selection_widget_has_a_file() + self.file_selection_widget_has_files() self.history_is_not_visible(self.gui.share_mode) self.click_toggle_history(self.gui.share_mode) self.history_is_visible(self.gui.share_mode) - self.deleting_only_file_hides_delete_button() + self.deleting_all_files_hides_delete_button() self.add_a_file_and_delete_using_its_delete_widget() self.file_selection_widget_readd_files() - def run_all_share_mode_started_tests(self, public_mode): + def run_all_share_mode_started_tests(self, public_mode, startup_time=2000): """Tests in share mode after starting a share""" self.server_working_on_start_button_pressed(self.gui.share_mode) self.server_status_indicator_says_starting(self.gui.share_mode) self.add_delete_buttons_hidden() self.settings_button_is_hidden() - self.a_server_is_started(self.gui.share_mode) - self.a_web_server_is_running() + self.server_is_started(self.gui.share_mode, startup_time) + self.web_server_is_running() self.have_a_slug(self.gui.share_mode, public_mode) self.url_description_shown(self.gui.share_mode) - self.have_copy_url_button(self.gui.share_mode) + self.have_copy_url_button(self.gui.share_mode, public_mode) self.server_status_indicator_says_started(self.gui.share_mode) @@ -133,11 +151,11 @@ class GuiShareTest(GuiBaseTest): self.download_share(public_mode) self.history_widgets_present(self.gui.share_mode) self.server_is_stopped(self.gui.share_mode, stay_open) - self.web_service_is_stopped() + self.web_server_is_stopped() self.server_status_indicator_says_closed(self.gui.share_mode, stay_open) self.add_button_visible() self.server_working_on_start_button_pressed(self.gui.share_mode) - self.a_server_is_started(self.gui.share_mode) + self.server_is_started(self.gui.share_mode) self.history_indicator(self.gui.share_mode, public_mode) @@ -148,6 +166,17 @@ class GuiShareTest(GuiBaseTest): self.run_all_share_mode_download_tests(public_mode, stay_open) + def run_all_large_file_tests(self, public_mode, stay_open): + """Same as above but with a larger file""" + self.run_all_share_mode_setup_tests() + self.add_large_file() + self.run_all_share_mode_started_tests(public_mode, startup_time=15000) + self.assertTrue(self.gui.share_mode.filesize_warning.isVisible()) + self.server_is_stopped(self.gui.share_mode, stay_open) + self.web_server_is_stopped() + self.server_status_indicator_says_closed(self.gui.share_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() @@ -164,5 +193,5 @@ class GuiShareTest(GuiBaseTest): self.run_all_share_mode_started_tests(public_mode) self.timeout_widget_hidden(self.gui.share_mode) self.server_timed_out(self.gui.share_mode, 10000) - self.web_service_is_stopped() + self.web_server_is_stopped() diff --git a/tests/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py index 2fadfab7..aee05096 100644 --- a/tests/TorGuiBaseTest.py +++ b/tests/TorGuiBaseTest.py @@ -1,4 +1,5 @@ import json +import os import requests import socks @@ -24,6 +25,13 @@ class TorGuiBaseTest(GuiBaseTest): testfile.write('onionshare') testfile.close() + # Create a test dir and files + if not os.path.exists('/tmp/testdir'): + testdir = os.mkdir('/tmp/testdir') + testfile = open('/tmp/testdir/test.txt', 'w') + testfile.write('onionshare') + testfile.close() + common = Common() common.settings = Settings(common) common.define_css() @@ -45,7 +53,7 @@ class TorGuiBaseTest(GuiBaseTest): web = Web(common, False, False) open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) - gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], '/tmp/{}.json'.format(settings_filename), False) + gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/{}.json'.format(settings_filename), False) return gui def history_indicator(self, mode, public_mode): @@ -91,12 +99,6 @@ class TorGuiBaseTest(GuiBaseTest): QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton) self.assertFalse(mode.toggle_history.indicator_label.isVisible()) - def a_server_is_started(self, mode): - '''Test that the server has started (overriding from local tests to wait for longer)''' - QtTest.QTest.qWait(45000) - # Should now be in SERVER_STARTED state - self.assertEqual(mode.server_status.status, 2) - def have_an_onion_service(self): '''Test that we have a valid Onion URL''' self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion') @@ -127,6 +129,17 @@ class TorGuiBaseTest(GuiBaseTest): self.assertTrue(string in f.read()) f.close() + def have_copy_url_button(self, mode, public_mode): + '''Test that the Copy URL button is shown and that the clipboard is correct''' + self.assertTrue(mode.server_status.copy_url_button.isVisible()) + + QtTest.QTest.mouseClick(mode.server_status.copy_url_button, QtCore.Qt.LeftButton) + clipboard = self.gui.qtapp.clipboard() + if public_mode: + self.assertEqual(clipboard.text(), 'http://{}'.format(self.gui.app.onion_host)) + else: + self.assertEqual(clipboard.text(), 'http://{}/{}'.format(self.gui.app.onion_host, mode.server_status.web.slug)) + def cancel_the_share(self, mode): '''Test that we can cancel this share before it's started up ''' self.server_working_on_start_button_pressed(self.gui.share_mode) @@ -138,13 +151,15 @@ class TorGuiBaseTest(GuiBaseTest): QtTest.QTest.mouseRelease(mode.server_status.server_button, QtCore.Qt.LeftButton) self.assertEqual(mode.server_status.status, 0) self.server_is_stopped(self.gui.share_mode, False) - self.web_service_is_stopped() + self.web_server_is_stopped() # Stealth tests def copy_have_hidserv_auth_button(self, mode): '''Test that the Copy HidservAuth button is shown''' self.assertTrue(mode.server_status.copy_hidservauth_button.isVisible()) + clipboard = self.gui.qtapp.clipboard() + self.assertRegex(clipboard.text(), r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host) def hidserv_auth_string(self): '''Test the validity of the HidservAuth string''' diff --git a/tests/TorGuiReceiveTest.py b/tests/TorGuiReceiveTest.py index 67b6a811..3c380b8a 100644 --- a/tests/TorGuiReceiveTest.py +++ b/tests/TorGuiReceiveTest.py @@ -20,7 +20,11 @@ class TorGuiReceiveTest(TorGuiBaseTest): QtTest.QTest.qWait(4000) self.assertTrue(os.path.isfile(expected_file)) + + # 'Grouped' tests follow from here + def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): + '''Run a full suite of tests in Receive mode''' self.click_mode(self.gui.receive_mode) self.history_is_not_visible(self.gui.receive_mode) self.click_toggle_history(self.gui.receive_mode) @@ -28,12 +32,12 @@ class TorGuiReceiveTest(TorGuiBaseTest): self.server_working_on_start_button_pressed(self.gui.receive_mode) self.server_status_indicator_says_starting(self.gui.receive_mode) self.settings_button_is_hidden() - self.a_server_is_started(self.gui.receive_mode) - self.a_web_server_is_running() + self.server_is_started(self.gui.receive_mode, startup_time=45000) + self.web_server_is_running() self.have_an_onion_service() self.have_a_slug(self.gui.receive_mode, public_mode) self.url_description_shown(self.gui.receive_mode) - self.have_copy_url_button(self.gui.receive_mode) + self.have_copy_url_button(self.gui.receive_mode, public_mode) self.server_status_indicator_says_started(self.gui.receive_mode) self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode) self.upload_file(public_mode, '/tmp/OnionShare/test.txt') @@ -43,9 +47,9 @@ class TorGuiReceiveTest(TorGuiBaseTest): self.counter_incremented(self.gui.receive_mode, 2) self.history_indicator(self.gui.receive_mode, public_mode) self.server_is_stopped(self.gui.receive_mode, False) - self.web_service_is_stopped() + self.web_server_is_stopped() self.server_status_indicator_says_closed(self.gui.receive_mode, False) self.server_working_on_start_button_pressed(self.gui.receive_mode) - self.a_server_is_started(self.gui.receive_mode) + self.server_is_started(self.gui.receive_mode, startup_time=45000) self.history_indicator(self.gui.receive_mode, public_mode) diff --git a/tests/TorGuiShareTest.py b/tests/TorGuiShareTest.py index aa622b4f..ff8d0bb7 100644 --- a/tests/TorGuiShareTest.py +++ b/tests/TorGuiShareTest.py @@ -6,6 +6,7 @@ from .GuiShareTest import GuiShareTest class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): def download_share(self, public_mode): + '''Test downloading a share''' # Set up connecting to the onion (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port() session = requests.session() @@ -27,27 +28,46 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): file_to_write.close() zip = zipfile.ZipFile('/tmp/download.zip') QtTest.QTest.qWait(4000) - self.assertEquals('onionshare', zip.read('test.txt').decode('utf-8')) + self.assertEqual('onionshare', zip.read('test.txt').decode('utf-8')) + # Persistence tests def have_same_onion(self, onion): '''Test that we have the same onion''' self.assertEqual(self.gui.app.onion_host, onion) + + # 'Grouped' tests follow from here + def run_all_share_mode_started_tests(self, public_mode): """Tests in share mode after starting a share""" self.server_working_on_start_button_pressed(self.gui.share_mode) self.server_status_indicator_says_starting(self.gui.share_mode) self.add_delete_buttons_hidden() self.settings_button_is_hidden() - self.a_server_is_started(self.gui.share_mode) - self.a_web_server_is_running() + self.server_is_started(self.gui.share_mode, startup_time=45000) + self.web_server_is_running() self.have_an_onion_service() self.have_a_slug(self.gui.share_mode, public_mode) self.url_description_shown(self.gui.share_mode) - self.have_copy_url_button(self.gui.share_mode) + self.have_copy_url_button(self.gui.share_mode, public_mode) self.server_status_indicator_says_started(self.gui.share_mode) + + def run_all_share_mode_download_tests(self, public_mode, stay_open): + """Tests in share mode after downloading a share""" + self.web_page(self.gui.share_mode, 'Total size', public_mode) + self.download_share(public_mode) + self.history_widgets_present(self.gui.share_mode) + self.server_is_stopped(self.gui.share_mode, stay_open) + self.web_server_is_stopped() + self.server_status_indicator_says_closed(self.gui.share_mode, stay_open) + self.add_button_visible() + self.server_working_on_start_button_pressed(self.gui.share_mode) + self.server_is_started(self.gui.share_mode, startup_time=45000) + self.history_indicator(self.gui.share_mode, public_mode) + + 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() @@ -57,6 +77,7 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): self.run_all_share_mode_download_tests(public_mode, stay_open) self.have_same_onion(onion) self.have_same_slug(slug) + def run_all_share_mode_timer_tests(self, public_mode): """Auto-stop timer tests in share mode""" @@ -65,5 +86,5 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): self.run_all_share_mode_started_tests(public_mode) self.timeout_widget_hidden(self.gui.share_mode) self.server_timed_out(self.gui.share_mode, 125000) - self.web_service_is_stopped() + self.web_server_is_stopped() diff --git a/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py b/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py new file mode 100644 index 00000000..e4e0a03f --- /dev/null +++ b/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiShareTest import GuiShareTest + +class Local404PublicModeRateLimitTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "close_after_first_download": False, + "public_mode": True + } + cls.gui = GuiShareTest.set_up(test_settings, 'Local404PublicModeRateLimitTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_tests(True, True) + self.hit_404(True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_404_triggers_ratelimit_test.py b/tests/local_onionshare_404_triggers_ratelimit_test.py new file mode 100644 index 00000000..ce26eae1 --- /dev/null +++ b/tests/local_onionshare_404_triggers_ratelimit_test.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiShareTest import GuiShareTest + +class Local404RateLimitTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "close_after_first_download": False + } + cls.gui = GuiShareTest.set_up(test_settings, 'Local404RateLimitTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_tests(False, True) + self.hit_404(False) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_receive_mode_sender_closed_test.py b/tests/local_onionshare_receive_mode_sender_closed_test.py new file mode 100644 index 00000000..6960301a --- /dev/null +++ b/tests/local_onionshare_receive_mode_sender_closed_test.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiReceiveTest import GuiReceiveTest + +class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "receive_allow_receiver_shutdown": True + } + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_receive_mode_tests(False, True) + self.run_receive_mode_sender_closed_tests(False) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_receive_mode_timer_test.py b/tests/local_onionshare_receive_mode_timer_test.py new file mode 100644 index 00000000..1784ba94 --- /dev/null +++ b/tests/local_onionshare_receive_mode_timer_test.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiReceiveTest import GuiReceiveTest + +class LocalReceiveModeTimerTest(unittest.TestCase, GuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": False, + "shutdown_timeout": True, + } + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTimerTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_receive_mode_timer_tests(False) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py new file mode 100644 index 00000000..e33a6461 --- /dev/null +++ b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiReceiveTest import GuiReceiveTest + +class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "receive_allow_receiver_shutdown": True + } + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_receive_mode_unwritable_dir_tests(False, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_receive_mode_upload_public_mode_test.py b/tests/local_onionshare_receive_mode_upload_public_mode_test.py index c99fae52..2c7cbd5e 100644 --- a/tests/local_onionshare_receive_mode_upload_public_mode_test.py +++ b/tests/local_onionshare_receive_mode_upload_public_mode_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiReceiveTest import GuiReceiveTest diff --git a/tests/local_onionshare_receive_mode_upload_test.py b/tests/local_onionshare_receive_mode_upload_test.py index dc6c1f06..fb5d36a7 100644 --- a/tests/local_onionshare_receive_mode_upload_test.py +++ b/tests/local_onionshare_receive_mode_upload_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiReceiveTest import GuiReceiveTest diff --git a/tests/local_onionshare_share_mode_download_public_mode_test.py b/tests/local_onionshare_share_mode_download_public_mode_test.py index bfed9443..3b4ad0e8 100644 --- a/tests/local_onionshare_share_mode_download_public_mode_test.py +++ b/tests/local_onionshare_share_mode_download_public_mode_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/local_onionshare_share_mode_download_stay_open_test.py b/tests/local_onionshare_share_mode_download_stay_open_test.py index b68516a2..dfe7f56c 100644 --- a/tests/local_onionshare_share_mode_download_stay_open_test.py +++ b/tests/local_onionshare_share_mode_download_stay_open_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/local_onionshare_share_mode_download_test.py b/tests/local_onionshare_share_mode_download_test.py index a2a16c96..6b6b0bcc 100644 --- a/tests/local_onionshare_share_mode_download_test.py +++ b/tests/local_onionshare_share_mode_download_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/local_onionshare_share_mode_large_download_test.py b/tests/local_onionshare_share_mode_large_download_test.py new file mode 100644 index 00000000..6fe77752 --- /dev/null +++ b/tests/local_onionshare_share_mode_large_download_test.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiShareTest import GuiShareTest + +class LocalShareModeTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_large_file_tests(False, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_share_mode_slug_persistent_test.py b/tests/local_onionshare_share_mode_slug_persistent_test.py index 03285fa1..a28f5a23 100644 --- a/tests/local_onionshare_share_mode_slug_persistent_test.py +++ b/tests/local_onionshare_share_mode_slug_persistent_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/local_onionshare_share_mode_timer_test.py b/tests/local_onionshare_share_mode_timer_test.py index 3d20efc4..9e3b0b5e 100644 --- a/tests/local_onionshare_share_mode_timer_test.py +++ b/tests/local_onionshare_share_mode_timer_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from .GuiShareTest import GuiShareTest diff --git a/tests/onionshare_790_cancel_on_second_share_test.py b/tests/onionshare_790_cancel_on_second_share_test.py index 21747d4c..327a8456 100644 --- a/tests/onionshare_790_cancel_on_second_share_test.py +++ b/tests/onionshare_790_cancel_on_second_share_test.py @@ -19,7 +19,7 @@ class ShareModeCancelSecondShareTest(unittest.TestCase, TorGuiShareTest): self.run_all_share_mode_tests(False, False) self.cancel_the_share(self.gui.share_mode) self.server_is_stopped(self.gui.share_mode, False) - self.web_service_is_stopped() + self.web_server_is_stopped() if __name__ == "__main__": unittest.main() From 1a6356870c4c7c1ee249c519a5c756d74f43b673 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 16 Oct 2018 15:53:35 +1100 Subject: [PATCH 22/72] Add Settings GUI test --- tests/SettingsGuiBaseTest.py | 49 +++++ ...re_404_public_mode_skips_ratelimit_test.py | 4 + ..._onionshare_404_triggers_ratelimit_test.py | 4 + ...onshare_receive_mode_sender_closed_test.py | 4 + ...ocal_onionshare_receive_mode_timer_test.py | 4 + ...ceive_mode_upload_non_writable_dir_test.py | 4 + ...re_receive_mode_upload_public_mode_test.py | 4 + ...cal_onionshare_receive_mode_upload_test.py | 4 + .../local_onionshare_settings_dialog_test.py | 173 ++++++++++++++++++ ...re_share_mode_download_public_mode_test.py | 4 + ...hare_share_mode_download_stay_open_test.py | 4 + ...cal_onionshare_share_mode_download_test.py | 4 + ...ionshare_share_mode_large_download_test.py | 4 + ...onshare_share_mode_slug_persistent_test.py | 4 + .../local_onionshare_share_mode_timer_test.py | 4 + ...onshare_790_cancel_on_second_share_test.py | 4 + ...re_receive_mode_upload_public_mode_test.py | 4 + tests/onionshare_receive_mode_upload_test.py | 4 + ...onionshare_share_mode_cancel_share_test.py | 4 + ...re_share_mode_download_public_mode_test.py | 4 + ...hare_share_mode_download_stay_open_test.py | 4 + tests/onionshare_share_mode_download_test.py | 4 + .../onionshare_share_mode_persistent_test.py | 4 + tests/onionshare_share_mode_stealth_test.py | 4 + tests/onionshare_share_mode_timer_test.py | 4 + 25 files changed, 314 insertions(+) create mode 100644 tests/SettingsGuiBaseTest.py create mode 100644 tests/local_onionshare_settings_dialog_test.py diff --git a/tests/SettingsGuiBaseTest.py b/tests/SettingsGuiBaseTest.py new file mode 100644 index 00000000..dac074fc --- /dev/null +++ b/tests/SettingsGuiBaseTest.py @@ -0,0 +1,49 @@ +import json +import os +import sys +from PyQt5 import QtWidgets + +from onionshare import strings +from onionshare.common import Common +from onionshare.settings import Settings +from onionshare.onion import Onion +from onionshare.web import Web +from onionshare_gui import Application, OnionShare +from onionshare_gui.settings_dialog import SettingsDialog + +class SettingsGuiBaseTest(object): + @staticmethod + def set_up(test_settings, settings_filename): + '''Create the GUI''' + # Create our test file + testfile = open('/tmp/test.txt', 'w') + testfile.write('onionshare') + testfile.close() + + common = Common() + common.settings = Settings(common) + common.define_css() + strings.load_strings(common) + + # Start the Onion + testonion = Onion(common) + global qtapp + qtapp = Application(common) + app = OnionShare(common, testonion, True, 0) + + web = Web(common, False, True) + + for key, val in common.settings.default_settings.items(): + if key not in test_settings: + test_settings[key] = val + + open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) + + gui = SettingsDialog(common, testonion, qtapp, '/tmp/{}.json'.format(settings_filename), True) + return gui + + + @staticmethod + def tear_down(): + '''Clean up after tests''' + os.remove('/tmp/settings.json') diff --git a/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py b/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py index e4e0a03f..c4c271b8 100644 --- a/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py +++ b/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py @@ -12,6 +12,10 @@ class Local404PublicModeRateLimitTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'Local404PublicModeRateLimitTest') + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_share_mode_tests(True, True) diff --git a/tests/local_onionshare_404_triggers_ratelimit_test.py b/tests/local_onionshare_404_triggers_ratelimit_test.py index ce26eae1..8f9caa7c 100644 --- a/tests/local_onionshare_404_triggers_ratelimit_test.py +++ b/tests/local_onionshare_404_triggers_ratelimit_test.py @@ -11,6 +11,10 @@ class Local404RateLimitTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'Local404RateLimitTest') + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_share_mode_tests(False, True) diff --git a/tests/local_onionshare_receive_mode_sender_closed_test.py b/tests/local_onionshare_receive_mode_sender_closed_test.py index 6960301a..1f16b5fb 100644 --- a/tests/local_onionshare_receive_mode_sender_closed_test.py +++ b/tests/local_onionshare_receive_mode_sender_closed_test.py @@ -11,6 +11,10 @@ class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + @classmethod + def tearDownClass(cls): + GuiReceiveTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_receive_mode_tests(False, True) diff --git a/tests/local_onionshare_receive_mode_timer_test.py b/tests/local_onionshare_receive_mode_timer_test.py index 1784ba94..039acff4 100644 --- a/tests/local_onionshare_receive_mode_timer_test.py +++ b/tests/local_onionshare_receive_mode_timer_test.py @@ -12,6 +12,10 @@ class LocalReceiveModeTimerTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTimerTest') + @classmethod + def tearDownClass(cls): + GuiReceiveTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_receive_mode_timer_tests(False) diff --git a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py index e33a6461..ee3a7215 100644 --- a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py +++ b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py @@ -11,6 +11,10 @@ class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + @classmethod + def tearDownClass(cls): + GuiReceiveTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_receive_mode_unwritable_dir_tests(False, True) diff --git a/tests/local_onionshare_receive_mode_upload_public_mode_test.py b/tests/local_onionshare_receive_mode_upload_public_mode_test.py index 2c7cbd5e..654895ca 100644 --- a/tests/local_onionshare_receive_mode_upload_public_mode_test.py +++ b/tests/local_onionshare_receive_mode_upload_public_mode_test.py @@ -12,6 +12,10 @@ class LocalReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModePublicModeTest') + @classmethod + def tearDownClass(cls): + GuiReceiveTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_receive_mode_tests(True, True) diff --git a/tests/local_onionshare_receive_mode_upload_test.py b/tests/local_onionshare_receive_mode_upload_test.py index fb5d36a7..c06d30cd 100644 --- a/tests/local_onionshare_receive_mode_upload_test.py +++ b/tests/local_onionshare_receive_mode_upload_test.py @@ -11,6 +11,10 @@ class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): } cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + @classmethod + def tearDownClass(cls): + GuiReceiveTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_receive_mode_tests(False, True) diff --git a/tests/local_onionshare_settings_dialog_test.py b/tests/local_onionshare_settings_dialog_test.py new file mode 100644 index 00000000..64840d7d --- /dev/null +++ b/tests/local_onionshare_settings_dialog_test.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python3 +import json +import unittest +from PyQt5 import QtCore, QtTest + +from onionshare import strings +from .SettingsGuiBaseTest import SettingsGuiBaseTest + +class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest): + @classmethod + def setUpClass(cls): + test_settings = { + "no_bridges": False, + "tor_bridges_use_obfs4": True, + } + cls.gui = SettingsGuiBaseTest.set_up(test_settings, 'settings') + + @classmethod + def tearDownClass(cls): + SettingsGuiBaseTest.tear_down() + + def test_gui(self): + self.gui.show() + # Window is shown + self.assertTrue(self.gui.isVisible()) + self.assertEqual(self.gui.windowTitle(), strings._('gui_settings_window_title')) + # Check for updates button is hidden + self.assertFalse(self.gui.check_for_updates_button.isVisible()) + + # public mode is off + self.assertFalse(self.gui.public_mode_checkbox.isChecked()) + # enable public mode + QtTest.QTest.mouseClick(self.gui.public_mode_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.public_mode_checkbox.height()/2)) + self.assertTrue(self.gui.public_mode_checkbox.isChecked()) + + # shutdown timer is off + self.assertFalse(self.gui.shutdown_timeout_checkbox.isChecked()) + # enable shutdown timer + QtTest.QTest.mouseClick(self.gui.shutdown_timeout_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.shutdown_timeout_checkbox.height()/2)) + self.assertTrue(self.gui.shutdown_timeout_checkbox.isChecked()) + + # legacy mode checkbox and related widgets + # legacy mode is off + self.assertFalse(self.gui.use_legacy_v2_onions_checkbox.isChecked()) + # persistence, stealth is hidden and disabled + self.assertFalse(self.gui.save_private_key_widget.isVisible()) + self.assertFalse(self.gui.save_private_key_checkbox.isChecked()) + self.assertFalse(self.gui.use_stealth_widget.isVisible()) + self.assertFalse(self.gui.stealth_checkbox.isChecked()) + self.assertFalse(self.gui.hidservauth_copy_button.isVisible()) + + # enable legacy mode + QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2)) + self.assertTrue(self.gui.use_legacy_v2_onions_checkbox.isChecked()) + self.assertTrue(self.gui.save_private_key_checkbox.isVisible()) + self.assertTrue(self.gui.use_stealth_widget.isVisible()) + # enable persistent mode + QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2)) + self.assertTrue(self.gui.save_private_key_checkbox.isChecked()) + # enable stealth mode + QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2)) + self.assertTrue(self.gui.stealth_checkbox.isChecked()) + # now that stealth, persistence are enabled, we can't turn off legacy mode + self.assertFalse(self.gui.use_legacy_v2_onions_checkbox.isEnabled()) + # disable stealth, persistence + QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2)) + QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2)) + # legacy mode checkbox is enabled again + self.assertTrue(self.gui.use_legacy_v2_onions_checkbox.isEnabled()) + # uncheck legacy mode + QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2)) + # legacy options hidden again + self.assertFalse(self.gui.save_private_key_widget.isVisible()) + self.assertFalse(self.gui.use_stealth_widget.isVisible()) + # enable them all again so that we can see the setting stick in settings.json + QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2)) + QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2)) + QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2)) + + + # stay open toggled off, on + self.assertTrue(self.gui.close_after_first_download_checkbox.isChecked()) + QtTest.QTest.mouseClick(self.gui.close_after_first_download_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.close_after_first_download_checkbox.height()/2)) + self.assertFalse(self.gui.close_after_first_download_checkbox.isChecked()) + + # receive mode + self.gui.downloads_dir_lineedit.setText('/tmp/OnionShareSettingsTest') + # allow receiver shutdown is on + self.assertTrue(self.gui.receive_allow_receiver_shutdown_checkbox.isChecked()) + # disable receiver shutdown + QtTest.QTest.mouseClick(self.gui.receive_allow_receiver_shutdown_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.receive_allow_receiver_shutdown_checkbox.height()/2)) + self.assertFalse(self.gui.receive_allow_receiver_shutdown_checkbox.isChecked()) + + + # bundled mode is enabled + self.assertTrue(self.gui.connection_type_bundled_radio.isEnabled()) + self.assertTrue(self.gui.connection_type_bundled_radio.isChecked()) + # bridge options are shown + self.assertTrue(self.gui.connection_type_bridges_radio_group.isVisible()) + # bridges are set to obfs4 + self.assertFalse(self.gui.tor_bridges_no_bridges_radio.isChecked()) + self.assertTrue(self.gui.tor_bridges_use_obfs4_radio.isChecked()) + + # custom bridges are hidden + self.assertFalse(self.gui.tor_bridges_use_custom_textbox_options.isVisible()) + # other modes are unchecked but enabled + self.assertTrue(self.gui.connection_type_automatic_radio.isEnabled()) + self.assertTrue(self.gui.connection_type_control_port_radio.isEnabled()) + self.assertTrue(self.gui.connection_type_socket_file_radio.isEnabled()) + self.assertFalse(self.gui.connection_type_automatic_radio.isChecked()) + self.assertFalse(self.gui.connection_type_control_port_radio.isChecked()) + self.assertFalse(self.gui.connection_type_socket_file_radio.isChecked()) + + # enable automatic mode + QtTest.QTest.mouseClick(self.gui.connection_type_automatic_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_automatic_radio.height()/2)) + self.assertTrue(self.gui.connection_type_automatic_radio.isChecked()) + # bundled is off + self.assertFalse(self.gui.connection_type_bundled_radio.isChecked()) + # bridges are hidden + self.assertFalse(self.gui.connection_type_bridges_radio_group.isVisible()) + + # auth type is hidden in bundled or automatic mode + self.assertFalse(self.gui.authenticate_no_auth_radio.isVisible()) + self.assertFalse(self.gui.authenticate_password_radio.isVisible()) + + # enable control port mode + QtTest.QTest.mouseClick(self.gui.connection_type_control_port_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_control_port_radio.height()/2)) + self.assertTrue(self.gui.connection_type_control_port_radio.isChecked()) + # automatic is off + self.assertFalse(self.gui.connection_type_automatic_radio.isChecked()) + # auth options appear + self.assertTrue(self.gui.authenticate_no_auth_radio.isVisible()) + self.assertTrue(self.gui.authenticate_password_radio.isVisible()) + + # enable socket mode + QtTest.QTest.mouseClick(self.gui.connection_type_socket_file_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_socket_file_radio.height()/2)) + self.assertTrue(self.gui.connection_type_socket_file_radio.isChecked()) + # control port is off + self.assertFalse(self.gui.connection_type_control_port_radio.isChecked()) + # auth options are still present + self.assertTrue(self.gui.authenticate_no_auth_radio.isVisible()) + self.assertTrue(self.gui.authenticate_password_radio.isVisible()) + + # re-enable bundled mode + QtTest.QTest.mouseClick(self.gui.connection_type_bundled_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_bundled_radio.height()/2)) + # set some custom bridges + QtTest.QTest.mouseClick(self.gui.tor_bridges_use_custom_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_custom_radio.height()/2)) + self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked()) + self.assertTrue(self.gui.tor_bridges_use_custom_textbox.isVisible()) + self.gui.tor_bridges_use_custom_textbox.setPlainText('94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\n148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\n93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3') + + # Test that the Settings Dialog can save the settings and close itself + QtTest.QTest.mouseClick(self.gui.save_button, QtCore.Qt.LeftButton) + self.assertFalse(self.gui.isVisible()) + + # Test our settings are reflected in the settings json + with open('/tmp/settings.json') as f: + data = json.load(f) + + self.assertTrue(data["public_mode"]) + self.assertTrue(data["shutdown_timeout"]) + self.assertTrue(data["use_legacy_v2_onions"]) + self.assertTrue(data["save_private_key"]) + self.assertTrue(data["use_stealth"]) + self.assertEqual(data["downloads_dir"], "/tmp/OnionShareSettingsTest") + self.assertFalse(data["receive_allow_receiver_shutdown"]) + self.assertFalse(data["close_after_first_download"]) + self.assertEqual(data["connection_type"], "bundled") + self.assertFalse(data["tor_bridges_use_obfs4"]) + self.assertEqual(data["tor_bridges_use_custom_bridges"], "Bridge 94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\nBridge 148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\nBridge 93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3\n") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_share_mode_download_public_mode_test.py b/tests/local_onionshare_share_mode_download_public_mode_test.py index 3b4ad0e8..f1c29990 100644 --- a/tests/local_onionshare_share_mode_download_public_mode_test.py +++ b/tests/local_onionshare_share_mode_download_public_mode_test.py @@ -11,6 +11,10 @@ class LocalShareModePublicModeTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePublicModeTest') + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_share_mode_tests(True, False) diff --git a/tests/local_onionshare_share_mode_download_stay_open_test.py b/tests/local_onionshare_share_mode_download_stay_open_test.py index dfe7f56c..af02e841 100644 --- a/tests/local_onionshare_share_mode_download_stay_open_test.py +++ b/tests/local_onionshare_share_mode_download_stay_open_test.py @@ -11,6 +11,10 @@ class LocalShareModeStayOpenTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeStayOpenTest') + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_share_mode_tests(False, True) diff --git a/tests/local_onionshare_share_mode_download_test.py b/tests/local_onionshare_share_mode_download_test.py index 6b6b0bcc..53db0296 100644 --- a/tests/local_onionshare_share_mode_download_test.py +++ b/tests/local_onionshare_share_mode_download_test.py @@ -10,6 +10,10 @@ class LocalShareModeTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_share_mode_tests(False, False) diff --git a/tests/local_onionshare_share_mode_large_download_test.py b/tests/local_onionshare_share_mode_large_download_test.py index 6fe77752..b8017b77 100644 --- a/tests/local_onionshare_share_mode_large_download_test.py +++ b/tests/local_onionshare_share_mode_large_download_test.py @@ -10,6 +10,10 @@ class LocalShareModeTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_large_file_tests(False, True) diff --git a/tests/local_onionshare_share_mode_slug_persistent_test.py b/tests/local_onionshare_share_mode_slug_persistent_test.py index a28f5a23..c273fbda 100644 --- a/tests/local_onionshare_share_mode_slug_persistent_test.py +++ b/tests/local_onionshare_share_mode_slug_persistent_test.py @@ -14,6 +14,10 @@ class LocalShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePersistentSlugTest') + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_share_mode_persistent_tests(False, True) diff --git a/tests/local_onionshare_share_mode_timer_test.py b/tests/local_onionshare_share_mode_timer_test.py index 9e3b0b5e..394dec21 100644 --- a/tests/local_onionshare_share_mode_timer_test.py +++ b/tests/local_onionshare_share_mode_timer_test.py @@ -12,6 +12,10 @@ class LocalShareModeTimerTest(unittest.TestCase, GuiShareTest): } cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTest') + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + def test_gui(self): self.run_all_common_setup_tests() self.run_all_share_mode_timer_tests(False) diff --git a/tests/onionshare_790_cancel_on_second_share_test.py b/tests/onionshare_790_cancel_on_second_share_test.py index 327a8456..dce84f62 100644 --- a/tests/onionshare_790_cancel_on_second_share_test.py +++ b/tests/onionshare_790_cancel_on_second_share_test.py @@ -13,6 +13,10 @@ class ShareModeCancelSecondShareTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelSecondShareTest') + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_receive_mode_upload_public_mode_test.py b/tests/onionshare_receive_mode_upload_public_mode_test.py index 56b49c81..048186c3 100644 --- a/tests/onionshare_receive_mode_upload_public_mode_test.py +++ b/tests/onionshare_receive_mode_upload_public_mode_test.py @@ -13,6 +13,10 @@ class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): } cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') + @classmethod + def tearDownClass(cls): + TorGuiReceiveTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_receive_mode_upload_test.py b/tests/onionshare_receive_mode_upload_test.py index 0fd8d5ed..d3965d59 100644 --- a/tests/onionshare_receive_mode_upload_test.py +++ b/tests/onionshare_receive_mode_upload_test.py @@ -12,6 +12,10 @@ class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): } cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') + @classmethod + def tearDownClass(cls): + TorGuiReceiveTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_share_mode_cancel_share_test.py b/tests/onionshare_share_mode_cancel_share_test.py index 9770cc35..83a009a1 100644 --- a/tests/onionshare_share_mode_cancel_share_test.py +++ b/tests/onionshare_share_mode_cancel_share_test.py @@ -11,6 +11,10 @@ class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelTest') + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_share_mode_download_public_mode_test.py b/tests/onionshare_share_mode_download_public_mode_test.py index 8409720a..8c5740c5 100644 --- a/tests/onionshare_share_mode_download_public_mode_test.py +++ b/tests/onionshare_share_mode_download_public_mode_test.py @@ -12,6 +12,10 @@ class ShareModePublicModeTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_share_mode_download_stay_open_test.py b/tests/onionshare_share_mode_download_stay_open_test.py index c16f91e9..56ac924d 100644 --- a/tests/onionshare_share_mode_download_stay_open_test.py +++ b/tests/onionshare_share_mode_download_stay_open_test.py @@ -12,6 +12,10 @@ class ShareModeStayOpenTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_share_mode_download_test.py b/tests/onionshare_share_mode_download_test.py index 194328d9..125909d0 100644 --- a/tests/onionshare_share_mode_download_test.py +++ b/tests/onionshare_share_mode_download_test.py @@ -11,6 +11,10 @@ class ShareModeTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTest') + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_share_mode_persistent_test.py b/tests/onionshare_share_mode_persistent_test.py index 3c283943..3f103a1a 100644 --- a/tests/onionshare_share_mode_persistent_test.py +++ b/tests/onionshare_share_mode_persistent_test.py @@ -16,6 +16,10 @@ class ShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_share_mode_stealth_test.py b/tests/onionshare_share_mode_stealth_test.py index b414de1f..3096a8bc 100644 --- a/tests/onionshare_share_mode_stealth_test.py +++ b/tests/onionshare_share_mode_stealth_test.py @@ -13,6 +13,10 @@ class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStealthTest') + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() diff --git a/tests/onionshare_share_mode_timer_test.py b/tests/onionshare_share_mode_timer_test.py index b53905d0..9e690ec7 100644 --- a/tests/onionshare_share_mode_timer_test.py +++ b/tests/onionshare_share_mode_timer_test.py @@ -13,6 +13,10 @@ class ShareModeTimerTest(unittest.TestCase, TorGuiShareTest): } cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTimerTest') + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + @pytest.mark.tor def test_gui(self): self.run_all_common_setup_tests() From 054e5c0aeee16129bb4cad73cd2a1faa86fee03b Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 09:23:07 +1100 Subject: [PATCH 23/72] Fix stealth test, add legacy v2 onion test --- tests/TorGuiBaseTest.py | 4 +-- tests/TorGuiShareTest.py | 7 +++++- tests/onionshare_share_mode_stealth_test.py | 2 +- tests/onionshare_share_mode_v2_onion_test.py | 26 ++++++++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 tests/onionshare_share_mode_v2_onion_test.py diff --git a/tests/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py index aee05096..611cb202 100644 --- a/tests/TorGuiBaseTest.py +++ b/tests/TorGuiBaseTest.py @@ -158,9 +158,7 @@ class TorGuiBaseTest(GuiBaseTest): def copy_have_hidserv_auth_button(self, mode): '''Test that the Copy HidservAuth button is shown''' self.assertTrue(mode.server_status.copy_hidservauth_button.isVisible()) - clipboard = self.gui.qtapp.clipboard() - self.assertRegex(clipboard.text(), r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host) def hidserv_auth_string(self): '''Test the validity of the HidservAuth string''' - self.assertRegex(self.gui.app.auth_string, r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host) + self.assertRegex(self.gui.app.auth_string, r'HidServAuth {} [a-zA-Z1-9]'.format(self.gui.app.onion_host)) diff --git a/tests/TorGuiShareTest.py b/tests/TorGuiShareTest.py index ff8d0bb7..53641dce 100644 --- a/tests/TorGuiShareTest.py +++ b/tests/TorGuiShareTest.py @@ -36,11 +36,16 @@ class TorGuiShareTest(TorGuiBaseTest, GuiShareTest): '''Test that we have the same onion''' self.assertEqual(self.gui.app.onion_host, onion) + # legacy v2 onion test + def have_v2_onion(self): + '''Test that the onion is a v2 style onion''' + self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion') + self.assertEqual(len(self.gui.app.onion_host), 22) # 'Grouped' tests follow from here def run_all_share_mode_started_tests(self, public_mode): - """Tests in share mode after starting a share""" + '''Tests in share mode after starting a share''' self.server_working_on_start_button_pressed(self.gui.share_mode) self.server_status_indicator_says_starting(self.gui.share_mode) self.add_delete_buttons_hidden() diff --git a/tests/onionshare_share_mode_stealth_test.py b/tests/onionshare_share_mode_stealth_test.py index 3096a8bc..78e87e9e 100644 --- a/tests/onionshare_share_mode_stealth_test.py +++ b/tests/onionshare_share_mode_stealth_test.py @@ -22,8 +22,8 @@ class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest): self.run_all_common_setup_tests() self.run_all_share_mode_setup_tests() self.run_all_share_mode_started_tests(False) - self.copy_have_hidserv_auth_button(self.gui.share_mode) self.hidserv_auth_string() + self.copy_have_hidserv_auth_button(self.gui.share_mode) if __name__ == "__main__": unittest.main() diff --git a/tests/onionshare_share_mode_v2_onion_test.py b/tests/onionshare_share_mode_v2_onion_test.py new file mode 100644 index 00000000..f06f6631 --- /dev/null +++ b/tests/onionshare_share_mode_v2_onion_test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModeV2OnionTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "use_legacy_v2_onions": True, + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeV2OnionTest') + + @classmethod + def tearDownClass(cls): + TorGuiShareTest.tear_down() + + @pytest.mark.tor + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_tests(False, False) + self.have_v2_onion() + +if __name__ == "__main__": + unittest.main() From c9ce040e4b9ab55779ba54d909b5f470a4fac3ee Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 10:47:55 +1100 Subject: [PATCH 24/72] Fix call to Alert() when an autostop timer has run out before starting the share --- onionshare_gui/server_status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py index b86155f0..e34a3d16 100644 --- a/onionshare_gui/server_status.py +++ b/onionshare_gui/server_status.py @@ -269,7 +269,7 @@ class ServerStatus(QtWidgets.QWidget): self.timeout = self.shutdown_timeout.dateTime().toPyDateTime().replace(second=0, microsecond=0) # If the timeout has actually passed already before the user hit Start, refuse to start the server. if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.timeout: - Alert(self.common, strings._('gui_server_timeout_expired', QtWidgets.QMessageBox.Warning)) + Alert(self.common, strings._('gui_server_timeout_expired'), QtWidgets.QMessageBox.Warning) else: self.start_server() else: From 63ae7c0d51b53357bcdcdcd558086a43bb09b217 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 11:57:21 +1100 Subject: [PATCH 25/72] Add better workaround for blocking QDialogs. Add unreadable file test and reinstate tor connection killed test --- tests/GuiBaseTest.py | 5 +++ tests/GuiReceiveTest.py | 5 ++- tests/GuiShareTest.py | 21 ++++++++----- tests/TorGuiBaseTest.py | 9 ++++++ ...onshare_share_mode_timer_too_short_test.py | 31 +++++++++++++++++++ ...onshare_share_mode_unreadable_file_test.py | 22 +++++++++++++ ...e_share_mode_tor_connection_killed_test.py | 25 +++++++++++++++ 7 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 tests/local_onionshare_share_mode_timer_too_short_test.py create mode 100644 tests/local_onionshare_share_mode_unreadable_file_test.py create mode 100644 tests/onionshare_share_mode_tor_connection_killed_test.py diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index e2f194db..3b7ec4c4 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -303,6 +303,11 @@ class GuiBaseTest(object): # We should have timed out now self.assertEqual(mode.server_status.status, 0) + # Hack to close an Alert dialog that would otherwise block tests + def accept_dialog(self): + window = self.gui.qtapp.activeWindow() + if window: + window.close() # 'Grouped' tests follow from here diff --git a/tests/GuiReceiveTest.py b/tests/GuiReceiveTest.py index 84d6a55a..0c0cb770 100644 --- a/tests/GuiReceiveTest.py +++ b/tests/GuiReceiveTest.py @@ -1,6 +1,6 @@ import os import requests -from PyQt5 import QtTest +from PyQt5 import QtCore, QtTest from .GuiBaseTest import GuiBaseTest class GuiReceiveTest(GuiBaseTest): @@ -24,8 +24,7 @@ class GuiReceiveTest(GuiBaseTest): path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port) response = requests.post(path, files=files) - # A nasty hack to avoid the Alert dialog that blocks the rest of the test - self.gui.qtapp.exit() + QtCore.QTimer.singleShot(1000, self.accept_dialog) self.assertTrue('Error uploading, please inform the OnionShare user' in response.text) def upload_dir_permissions(self, mode=0o755): diff --git a/tests/GuiShareTest.py b/tests/GuiShareTest.py index 4f2f58e7..716bab73 100644 --- a/tests/GuiShareTest.py +++ b/tests/GuiShareTest.py @@ -12,10 +12,10 @@ class GuiShareTest(GuiBaseTest): self.assertEqual(self.gui.share_mode.server_status.web.slug, slug) # Share-specific tests - - def file_selection_widget_has_files(self): - '''Test that the number of items in the list is 2''' - self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2) + + def file_selection_widget_has_files(self, num=2): + '''Test that the number of items in the list is as expected''' + self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), num) def deleting_all_files_hides_delete_button(self): @@ -40,14 +40,14 @@ class GuiShareTest(GuiBaseTest): '''Test that we can also delete a file by clicking on its [X] widget''' self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts') QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.item(0).item_button, QtCore.Qt.LeftButton) - self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 0) + self.file_selection_widget_has_files(0) def file_selection_widget_readd_files(self): '''Re-add some files to the list so we can share''' self.gui.share_mode.server_status.file_selection.file_list.add_file('/etc/hosts') self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/test.txt') - self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2) + self.file_selection_widget_has_files(2) def add_large_file(self): @@ -102,7 +102,7 @@ class GuiShareTest(GuiBaseTest): # A nasty hack to avoid the Alert dialog that blocks the rest of the test if not public_mode: - self.gui.qtapp.exit() + QtCore.QTimer.singleShot(1000, self.accept_dialog) # In public mode, we should still be running (no rate-limiting) if public_mode: @@ -195,3 +195,10 @@ class GuiShareTest(GuiBaseTest): self.server_timed_out(self.gui.share_mode, 10000) self.web_server_is_stopped() + + def run_all_share_mode_unreadable_file_tests(self): + '''Attempt to share an unreadable file''' + self.run_all_share_mode_setup_tests() + QtCore.QTimer.singleShot(1000, self.accept_dialog) + self.gui.share_mode.server_status.file_selection.file_list.add_file('/tmp/nonexistent.txt') + self.file_selection_widget_has_files(2) diff --git a/tests/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py index 611cb202..2c88bb94 100644 --- a/tests/TorGuiBaseTest.py +++ b/tests/TorGuiBaseTest.py @@ -162,3 +162,12 @@ class TorGuiBaseTest(GuiBaseTest): def hidserv_auth_string(self): '''Test the validity of the HidservAuth string''' self.assertRegex(self.gui.app.auth_string, r'HidServAuth {} [a-zA-Z1-9]'.format(self.gui.app.onion_host)) + + + + # Miscellaneous tests + def tor_killed_statusbar_message_shown(self, mode): + '''Test that the status bar message shows Tor was disconnected''' + self.gui.app.onion.c = None + QtTest.QTest.qWait(1000) + self.assertTrue(mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost')) diff --git a/tests/local_onionshare_share_mode_timer_too_short_test.py b/tests/local_onionshare_share_mode_timer_too_short_test.py new file mode 100644 index 00000000..16153c3e --- /dev/null +++ b/tests/local_onionshare_share_mode_timer_too_short_test.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +import unittest +from PyQt5 import QtCore, QtTest + +from .GuiShareTest import GuiShareTest + +class LocalShareModeTimerTooShortTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": False, + "shutdown_timeout": True, + } + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTooShortTest') + + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_setup_tests() + # Set a low timeout + self.set_timeout(self.gui.share_mode, 2) + QtTest.QTest.qWait(3000) + QtCore.QTimer.singleShot(4000, self.accept_dialog) + QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton) + self.assertEqual(self.gui.share_mode.server_status.status, 0) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_share_mode_unreadable_file_test.py b/tests/local_onionshare_share_mode_unreadable_file_test.py new file mode 100644 index 00000000..0e0970ea --- /dev/null +++ b/tests/local_onionshare_share_mode_unreadable_file_test.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiShareTest import GuiShareTest + +class LocalShareModeUnReadableFileTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeUnReadableFileTest') + + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_unreadable_file_tests() + +if __name__ == "__main__": + unittest.main() diff --git a/tests/onionshare_share_mode_tor_connection_killed_test.py b/tests/onionshare_share_mode_tor_connection_killed_test.py new file mode 100644 index 00000000..382ed547 --- /dev/null +++ b/tests/onionshare_share_mode_tor_connection_killed_test.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .TorGuiShareTest import TorGuiShareTest + +class ShareModeTorConnectionKilledTest(unittest.TestCase, TorGuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTorConnectionKilledTest') + + @pytest.mark.tor + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_setup_tests() + self.run_all_share_mode_started_tests(False) + self.tor_killed_statusbar_message_shown(self.gui.share_mode) + self.server_is_stopped(self.gui.share_mode, False) + self.web_server_is_stopped() + + +if __name__ == "__main__": + unittest.main() From c9a342f444449a21fafdd13ba5488b11661a77ca Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 13:48:13 +1100 Subject: [PATCH 26/72] Add simple test to ensure we can click the settings button --- ...al_onionshare_open_settings_dialog_test.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/local_onionshare_open_settings_dialog_test.py diff --git a/tests/local_onionshare_open_settings_dialog_test.py b/tests/local_onionshare_open_settings_dialog_test.py new file mode 100644 index 00000000..2a4d1a01 --- /dev/null +++ b/tests/local_onionshare_open_settings_dialog_test.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +import pytest +import unittest +from PyQt5 import QtCore, QtTest + +from .GuiShareTest import GuiShareTest + +class LocalOpenSettingsDialogTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = GuiShareTest.set_up(test_settings, 'LocalOpenSettingsDialogTest') + + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_setup_tests() + # Make sure we can open the settings dialog via the settings button + QtCore.QTimer.singleShot(1000, self.accept_dialog) + QtTest.QTest.mouseClick(self.gui.settings_button, QtCore.Qt.LeftButton) + +if __name__ == "__main__": + unittest.main() From 042f89d31c853af30c1803eead333d06995ff9a4 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 14:33:31 +1100 Subject: [PATCH 27/72] Add a test for making sure quitting during a share prompts before shutting down share --- ...al_onionshare_open_settings_dialog_test.py | 1 - ...tting_during_share_prompts_warning_test.py | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/local_onionshare_quitting_during_share_prompts_warning_test.py diff --git a/tests/local_onionshare_open_settings_dialog_test.py b/tests/local_onionshare_open_settings_dialog_test.py index 2a4d1a01..b012b6a2 100644 --- a/tests/local_onionshare_open_settings_dialog_test.py +++ b/tests/local_onionshare_open_settings_dialog_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import pytest import unittest from PyQt5 import QtCore, QtTest diff --git a/tests/local_onionshare_quitting_during_share_prompts_warning_test.py b/tests/local_onionshare_quitting_during_share_prompts_warning_test.py new file mode 100644 index 00000000..f6425d1b --- /dev/null +++ b/tests/local_onionshare_quitting_during_share_prompts_warning_test.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +import unittest +from PyQt5 import QtCore, QtTest + +from .GuiShareTest import GuiShareTest + +class LocalQuittingDuringSharePromptsWarningTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "close_after_first_download": False + } + cls.gui = GuiShareTest.set_up(test_settings, 'LocalQuittingDuringSharePromptsWarningTest') + + #@classmethod + #def tearDownClass(cls): + # TorGuiShareTest.tear_down() + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_tests(False, True) + # Prepare our auto-accept of prompt + QtCore.QTimer.singleShot(5000, self.accept_dialog) + # Try to close the app + self.gui.close() + # Server should still be running (we've been prompted first) + self.server_is_started(self.gui.share_mode, 0) + self.web_server_is_running() + +if __name__ == "__main__": + unittest.main() From c60aeafc3f7efb8d711f405a81dbea354326aef0 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 14:34:29 +1100 Subject: [PATCH 28/72] Remove commented out teardownClass (even though the teardown isn't working atm :/) --- ...onionshare_quitting_during_share_prompts_warning_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/local_onionshare_quitting_during_share_prompts_warning_test.py b/tests/local_onionshare_quitting_during_share_prompts_warning_test.py index f6425d1b..b33b991c 100644 --- a/tests/local_onionshare_quitting_during_share_prompts_warning_test.py +++ b/tests/local_onionshare_quitting_during_share_prompts_warning_test.py @@ -12,9 +12,9 @@ class LocalQuittingDuringSharePromptsWarningTest(unittest.TestCase, GuiShareTest } cls.gui = GuiShareTest.set_up(test_settings, 'LocalQuittingDuringSharePromptsWarningTest') - #@classmethod - #def tearDownClass(cls): - # TorGuiShareTest.tear_down() + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() def test_gui(self): self.run_all_common_setup_tests() From e9cdf4f52d803f4dd4e8013608d1649036e0543b Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 15:21:04 +1100 Subject: [PATCH 29/72] More test coverage, particularly of Receive Mode --- tests/GuiBaseTest.py | 2 +- tests/GuiReceiveTest.py | 20 ++++++++++++---- tests/TorGuiReceiveTest.py | 12 ++++++---- ...ublic_mode_upload_non_writable_dir_test.py | 24 +++++++++++++++++++ ...onshare_receive_mode_sender_closed_test.py | 4 ++-- ...ceive_mode_upload_non_writable_dir_test.py | 4 ++-- .../local_onionshare_settings_dialog_test.py | 11 ++++++--- ...ionshare_share_mode_large_download_test.py | 4 ++-- 8 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index 3b7ec4c4..0e570412 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -29,7 +29,7 @@ class GuiBaseTest(object): # Create a test dir and files if not os.path.exists('/tmp/testdir'): testdir = os.mkdir('/tmp/testdir') - testfile = open('/tmp/testdir/test.txt', 'w') + testfile = open('/tmp/testdir/test', 'w') testfile.write('onionshare') testfile.close() diff --git a/tests/GuiReceiveTest.py b/tests/GuiReceiveTest.py index 0c0cb770..a659a79f 100644 --- a/tests/GuiReceiveTest.py +++ b/tests/GuiReceiveTest.py @@ -4,9 +4,9 @@ from PyQt5 import QtCore, QtTest from .GuiBaseTest import GuiBaseTest class GuiReceiveTest(GuiBaseTest): - def upload_file(self, public_mode, expected_file): + def upload_file(self, public_mode, file_to_upload, expected_file): '''Test that we can upload the file''' - files = {'file[]': open('/tmp/test.txt', 'rb')} + files = {'file[]': open(file_to_upload, 'rb')} if not public_mode: path = 'http://127.0.0.1:{}/{}/upload'.format(self.gui.app.port, self.gui.receive_mode.web.slug) else: @@ -31,6 +31,12 @@ class GuiReceiveTest(GuiBaseTest): '''Manipulate the permissions on the upload dir in between tests''' os.chmod('/tmp/OnionShare', mode) + def try_public_paths_in_non_public_mode(self): + response = requests.post('http://127.0.0.1:{}/upload'.format(self.gui.app.port)) + self.assertEqual(response.status_code, 404) + response = requests.get('http://127.0.0.1:{}/close'.format(self.gui.app.port)) + self.assertEqual(response.status_code, 404) + def run_receive_mode_sender_closed_tests(self, public_mode): '''Test that the share can be stopped by the sender in receive mode''' if not public_mode: @@ -65,11 +71,17 @@ class GuiReceiveTest(GuiBaseTest): def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown): '''Upload files in receive mode and stop the share''' self.run_all_receive_mode_setup_tests(public_mode) - self.upload_file(public_mode, '/tmp/OnionShare/test.txt') + if not public_mode: + self.try_public_paths_in_non_public_mode() + self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt') self.history_widgets_present(self.gui.receive_mode) self.counter_incremented(self.gui.receive_mode, 1) - self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt') + self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt') self.counter_incremented(self.gui.receive_mode, 2) + self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test') + self.counter_incremented(self.gui.receive_mode, 3) + self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2') + self.counter_incremented(self.gui.receive_mode, 4) self.history_indicator(self.gui.receive_mode, public_mode) self.server_is_stopped(self.gui.receive_mode, False) self.web_server_is_stopped() diff --git a/tests/TorGuiReceiveTest.py b/tests/TorGuiReceiveTest.py index 3c380b8a..a21dd4fc 100644 --- a/tests/TorGuiReceiveTest.py +++ b/tests/TorGuiReceiveTest.py @@ -5,13 +5,13 @@ from .TorGuiBaseTest import TorGuiBaseTest class TorGuiReceiveTest(TorGuiBaseTest): - def upload_file(self, public_mode, expected_file): + def upload_file(self, public_mode, file_to_upload, expected_file): '''Test that we can upload the file''' (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port() session = requests.session() session.proxies = {} session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port) - files = {'file[]': open('/tmp/test.txt', 'rb')} + files = {'file[]': open(file_to_upload, 'rb')} if not public_mode: path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, self.gui.receive_mode.web.slug) else: @@ -40,11 +40,15 @@ class TorGuiReceiveTest(TorGuiBaseTest): self.have_copy_url_button(self.gui.receive_mode, public_mode) self.server_status_indicator_says_started(self.gui.receive_mode) self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode) - self.upload_file(public_mode, '/tmp/OnionShare/test.txt') + self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt') self.history_widgets_present(self.gui.receive_mode) self.counter_incremented(self.gui.receive_mode, 1) - self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt') + self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt') self.counter_incremented(self.gui.receive_mode, 2) + self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test') + self.counter_incremented(self.gui.receive_mode, 3) + self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2') + self.counter_incremented(self.gui.receive_mode, 4) self.history_indicator(self.gui.receive_mode, public_mode) self.server_is_stopped(self.gui.receive_mode, False) self.web_server_is_stopped() diff --git a/tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py b/tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py new file mode 100644 index 00000000..2bffb4dd --- /dev/null +++ b/tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import unittest + +from .GuiReceiveTest import GuiReceiveTest + +class LocalReceivePublicModeUnwritableTest(unittest.TestCase, GuiReceiveTest): + @classmethod + def setUpClass(cls): + test_settings = { + "public_mode": True, + "receive_allow_receiver_shutdown": True + } + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceivePublicModeUnwritableTest') + + @classmethod + def tearDownClass(cls): + GuiReceiveTest.tear_down() + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_receive_mode_unwritable_dir_tests(True, True) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/local_onionshare_receive_mode_sender_closed_test.py b/tests/local_onionshare_receive_mode_sender_closed_test.py index 1f16b5fb..3a0d8617 100644 --- a/tests/local_onionshare_receive_mode_sender_closed_test.py +++ b/tests/local_onionshare_receive_mode_sender_closed_test.py @@ -3,13 +3,13 @@ import unittest from .GuiReceiveTest import GuiReceiveTest -class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): +class LocalReceiveModeSenderClosedTest(unittest.TestCase, GuiReceiveTest): @classmethod def setUpClass(cls): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeSenderClosedTest') @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py index ee3a7215..b6f06b08 100644 --- a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py +++ b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py @@ -3,13 +3,13 @@ import unittest from .GuiReceiveTest import GuiReceiveTest -class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): +class LocalReceiveModeUnwritableTest(unittest.TestCase, GuiReceiveTest): @classmethod def setUpClass(cls): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeUnwritableTest') @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_settings_dialog_test.py b/tests/local_onionshare_settings_dialog_test.py index 64840d7d..a328f53b 100644 --- a/tests/local_onionshare_settings_dialog_test.py +++ b/tests/local_onionshare_settings_dialog_test.py @@ -11,7 +11,7 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest): def setUpClass(cls): test_settings = { "no_bridges": False, - "tor_bridges_use_obfs4": True, + "tor_bridges_use_custom_bridges": "Bridge 1.2.3.4:56 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 5.6.7.8:910 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 11.12.13.14:1516 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n", } cls.gui = SettingsGuiBaseTest.set_up(test_settings, 'settings') @@ -97,8 +97,12 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest): self.assertTrue(self.gui.connection_type_bundled_radio.isChecked()) # bridge options are shown self.assertTrue(self.gui.connection_type_bridges_radio_group.isVisible()) - # bridges are set to obfs4 + # bridges are set to custom self.assertFalse(self.gui.tor_bridges_no_bridges_radio.isChecked()) + self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked()) + + # switch to obfs4 + QtTest.QTest.mouseClick(self.gui.tor_bridges_use_obfs4_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_obfs4_radio.height()/2)) self.assertTrue(self.gui.tor_bridges_use_obfs4_radio.isChecked()) # custom bridges are hidden @@ -143,10 +147,11 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest): # re-enable bundled mode QtTest.QTest.mouseClick(self.gui.connection_type_bundled_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_bundled_radio.height()/2)) - # set some custom bridges + # go back to custom bridges QtTest.QTest.mouseClick(self.gui.tor_bridges_use_custom_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_custom_radio.height()/2)) self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked()) self.assertTrue(self.gui.tor_bridges_use_custom_textbox.isVisible()) + self.assertFalse(self.gui.tor_bridges_use_obfs4_radio.isChecked()) self.gui.tor_bridges_use_custom_textbox.setPlainText('94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\n148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\n93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3') # Test that the Settings Dialog can save the settings and close itself diff --git a/tests/local_onionshare_share_mode_large_download_test.py b/tests/local_onionshare_share_mode_large_download_test.py index b8017b77..5f5de888 100644 --- a/tests/local_onionshare_share_mode_large_download_test.py +++ b/tests/local_onionshare_share_mode_large_download_test.py @@ -3,12 +3,12 @@ import unittest from .GuiShareTest import GuiShareTest -class LocalShareModeTest(unittest.TestCase, GuiShareTest): +class LocalShareModeLargeDownloadTest(unittest.TestCase, GuiShareTest): @classmethod def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') + cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeLargeDownloadTest') @classmethod def tearDownClass(cls): From ef01da3fadf437aef3f153240ea937a3a6cd56dc Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 16:31:51 +1100 Subject: [PATCH 30/72] Remove unique settings file per test, because they don't run concurrently anymore --- tests/GuiBaseTest.py | 7 ++++--- tests/SettingsGuiBaseTest.py | 6 +++--- tests/TorGuiBaseTest.py | 6 +++--- ...ocal_onionshare_404_public_mode_skips_ratelimit_test.py | 2 +- tests/local_onionshare_404_triggers_ratelimit_test.py | 2 +- tests/local_onionshare_open_settings_dialog_test.py | 2 +- ...nionshare_quitting_during_share_prompts_warning_test.py | 2 +- tests/local_onionshare_receive_mode_sender_closed_test.py | 2 +- tests/local_onionshare_receive_mode_timer_test.py | 2 +- ...onionshare_receive_mode_upload_non_writable_dir_test.py | 2 +- ...ceive_mode_upload_public_mode_non_writable_dir_test.py} | 2 +- ...ocal_onionshare_receive_mode_upload_public_mode_test.py | 2 +- tests/local_onionshare_receive_mode_upload_test.py | 2 +- tests/local_onionshare_settings_dialog_test.py | 2 +- ...ocal_onionshare_share_mode_download_public_mode_test.py | 2 +- .../local_onionshare_share_mode_download_stay_open_test.py | 2 +- tests/local_onionshare_share_mode_download_test.py | 2 +- tests/local_onionshare_share_mode_large_download_test.py | 2 +- tests/local_onionshare_share_mode_slug_persistent_test.py | 2 +- tests/local_onionshare_share_mode_timer_test.py | 2 +- tests/local_onionshare_share_mode_timer_too_short_test.py | 2 +- tests/local_onionshare_share_mode_unreadable_file_test.py | 2 +- tests/onionshare_790_cancel_on_second_share_test.py | 2 +- tests/onionshare_receive_mode_upload_public_mode_test.py | 2 +- tests/onionshare_receive_mode_upload_test.py | 2 +- tests/onionshare_share_mode_cancel_share_test.py | 2 +- tests/onionshare_share_mode_download_public_mode_test.py | 2 +- tests/onionshare_share_mode_download_stay_open_test.py | 2 +- tests/onionshare_share_mode_download_test.py | 2 +- tests/onionshare_share_mode_persistent_test.py | 2 +- tests/onionshare_share_mode_stealth_test.py | 2 +- tests/onionshare_share_mode_timer_test.py | 2 +- tests/onionshare_share_mode_tor_connection_killed_test.py | 2 +- tests/onionshare_share_mode_v2_onion_test.py | 2 +- 34 files changed, 41 insertions(+), 40 deletions(-) rename tests/{local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py => local_onionshare_receive_mode_upload_public_mode_non_writable_dir_test.py} (86%) diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index 0e570412..af5f1944 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -19,7 +19,7 @@ from onionshare_gui.mode.receive_mode import ReceiveMode class GuiBaseTest(object): @staticmethod - def set_up(test_settings, settings_filename): + def set_up(test_settings): '''Create GUI with given settings''' # Create our test file testfile = open('/tmp/test.txt', 'w') @@ -51,9 +51,9 @@ class GuiBaseTest(object): app = OnionShare(common, testonion, True, 0) web = Web(common, False, True) - open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) + open('/tmp/settings.json', 'w').write(json.dumps(test_settings)) - gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/{}.json'.format(settings_filename), True) + gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/settings.json', True) return gui @staticmethod @@ -61,6 +61,7 @@ class GuiBaseTest(object): '''Clean up after tests''' try: os.remove('/tmp/test.txt') + os.remove('/tmp/settings.json') os.remove('/tmp/largefile') shutil.rmtree('/tmp/OnionShare') shutil.rmtree('/tmp/testdir') diff --git a/tests/SettingsGuiBaseTest.py b/tests/SettingsGuiBaseTest.py index dac074fc..195e7933 100644 --- a/tests/SettingsGuiBaseTest.py +++ b/tests/SettingsGuiBaseTest.py @@ -13,7 +13,7 @@ from onionshare_gui.settings_dialog import SettingsDialog class SettingsGuiBaseTest(object): @staticmethod - def set_up(test_settings, settings_filename): + def set_up(test_settings): '''Create the GUI''' # Create our test file testfile = open('/tmp/test.txt', 'w') @@ -37,9 +37,9 @@ class SettingsGuiBaseTest(object): if key not in test_settings: test_settings[key] = val - open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) + open('/tmp/settings.json', 'w').write(json.dumps(test_settings)) - gui = SettingsDialog(common, testonion, qtapp, '/tmp/{}.json'.format(settings_filename), True) + gui = SettingsDialog(common, testonion, qtapp, '/tmp/settings.json', True) return gui diff --git a/tests/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py index 2c88bb94..9a0bda3e 100644 --- a/tests/TorGuiBaseTest.py +++ b/tests/TorGuiBaseTest.py @@ -18,7 +18,7 @@ from .GuiBaseTest import GuiBaseTest class TorGuiBaseTest(GuiBaseTest): @staticmethod - def set_up(test_settings, settings_filename): + def set_up(test_settings): '''Create GUI with given settings''' # Create our test file testfile = open('/tmp/test.txt', 'w') @@ -51,9 +51,9 @@ class TorGuiBaseTest(GuiBaseTest): app = OnionShare(common, testonion, False, 0) web = Web(common, False, False) - open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings)) + open('/tmp/settings.json', 'w').write(json.dumps(test_settings)) - gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/{}.json'.format(settings_filename), False) + gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt', '/tmp/testdir'], '/tmp/settings.json', False) return gui def history_indicator(self, mode, public_mode): diff --git a/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py b/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py index c4c271b8..11feb6f0 100644 --- a/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py +++ b/tests/local_onionshare_404_public_mode_skips_ratelimit_test.py @@ -10,7 +10,7 @@ class Local404PublicModeRateLimitTest(unittest.TestCase, GuiShareTest): "close_after_first_download": False, "public_mode": True } - cls.gui = GuiShareTest.set_up(test_settings, 'Local404PublicModeRateLimitTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_404_triggers_ratelimit_test.py b/tests/local_onionshare_404_triggers_ratelimit_test.py index 8f9caa7c..ad49c3f8 100644 --- a/tests/local_onionshare_404_triggers_ratelimit_test.py +++ b/tests/local_onionshare_404_triggers_ratelimit_test.py @@ -9,7 +9,7 @@ class Local404RateLimitTest(unittest.TestCase, GuiShareTest): test_settings = { "close_after_first_download": False } - cls.gui = GuiShareTest.set_up(test_settings, 'Local404RateLimitTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_open_settings_dialog_test.py b/tests/local_onionshare_open_settings_dialog_test.py index b012b6a2..61e66be2 100644 --- a/tests/local_onionshare_open_settings_dialog_test.py +++ b/tests/local_onionshare_open_settings_dialog_test.py @@ -9,7 +9,7 @@ class LocalOpenSettingsDialogTest(unittest.TestCase, GuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalOpenSettingsDialogTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_quitting_during_share_prompts_warning_test.py b/tests/local_onionshare_quitting_during_share_prompts_warning_test.py index b33b991c..d2fe4986 100644 --- a/tests/local_onionshare_quitting_during_share_prompts_warning_test.py +++ b/tests/local_onionshare_quitting_during_share_prompts_warning_test.py @@ -10,7 +10,7 @@ class LocalQuittingDuringSharePromptsWarningTest(unittest.TestCase, GuiShareTest test_settings = { "close_after_first_download": False } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalQuittingDuringSharePromptsWarningTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_receive_mode_sender_closed_test.py b/tests/local_onionshare_receive_mode_sender_closed_test.py index 3a0d8617..e177d2ef 100644 --- a/tests/local_onionshare_receive_mode_sender_closed_test.py +++ b/tests/local_onionshare_receive_mode_sender_closed_test.py @@ -9,7 +9,7 @@ class LocalReceiveModeSenderClosedTest(unittest.TestCase, GuiReceiveTest): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeSenderClosedTest') + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_receive_mode_timer_test.py b/tests/local_onionshare_receive_mode_timer_test.py index 039acff4..88002f94 100644 --- a/tests/local_onionshare_receive_mode_timer_test.py +++ b/tests/local_onionshare_receive_mode_timer_test.py @@ -10,7 +10,7 @@ class LocalReceiveModeTimerTest(unittest.TestCase, GuiReceiveTest): "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTimerTest') + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py index b6f06b08..7d7b2780 100644 --- a/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py +++ b/tests/local_onionshare_receive_mode_upload_non_writable_dir_test.py @@ -9,7 +9,7 @@ class LocalReceiveModeUnwritableTest(unittest.TestCase, GuiReceiveTest): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeUnwritableTest') + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py b/tests/local_onionshare_receive_mode_upload_public_mode_non_writable_dir_test.py similarity index 86% rename from tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py rename to tests/local_onionshare_receive_mode_upload_public_mode_non_writable_dir_test.py index 2bffb4dd..cdc4e62a 100644 --- a/tests/local_onionshare_receive_mode_public_mode_upload_non_writable_dir_test.py +++ b/tests/local_onionshare_receive_mode_upload_public_mode_non_writable_dir_test.py @@ -10,7 +10,7 @@ class LocalReceivePublicModeUnwritableTest(unittest.TestCase, GuiReceiveTest): "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceivePublicModeUnwritableTest') + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_receive_mode_upload_public_mode_test.py b/tests/local_onionshare_receive_mode_upload_public_mode_test.py index 654895ca..bedb7ae2 100644 --- a/tests/local_onionshare_receive_mode_upload_public_mode_test.py +++ b/tests/local_onionshare_receive_mode_upload_public_mode_test.py @@ -10,7 +10,7 @@ class LocalReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest): "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModePublicModeTest') + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_receive_mode_upload_test.py b/tests/local_onionshare_receive_mode_upload_test.py index c06d30cd..82baf3fd 100644 --- a/tests/local_onionshare_receive_mode_upload_test.py +++ b/tests/local_onionshare_receive_mode_upload_test.py @@ -9,7 +9,7 @@ class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest') + cls.gui = GuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_settings_dialog_test.py b/tests/local_onionshare_settings_dialog_test.py index a328f53b..6d8923b6 100644 --- a/tests/local_onionshare_settings_dialog_test.py +++ b/tests/local_onionshare_settings_dialog_test.py @@ -13,7 +13,7 @@ class SettingsGuiTest(unittest.TestCase, SettingsGuiBaseTest): "no_bridges": False, "tor_bridges_use_custom_bridges": "Bridge 1.2.3.4:56 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 5.6.7.8:910 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 11.12.13.14:1516 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n", } - cls.gui = SettingsGuiBaseTest.set_up(test_settings, 'settings') + cls.gui = SettingsGuiBaseTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_share_mode_download_public_mode_test.py b/tests/local_onionshare_share_mode_download_public_mode_test.py index f1c29990..d6dff13a 100644 --- a/tests/local_onionshare_share_mode_download_public_mode_test.py +++ b/tests/local_onionshare_share_mode_download_public_mode_test.py @@ -9,7 +9,7 @@ class LocalShareModePublicModeTest(unittest.TestCase, GuiShareTest): test_settings = { "public_mode": True, } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePublicModeTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_share_mode_download_stay_open_test.py b/tests/local_onionshare_share_mode_download_stay_open_test.py index af02e841..54d6de51 100644 --- a/tests/local_onionshare_share_mode_download_stay_open_test.py +++ b/tests/local_onionshare_share_mode_download_stay_open_test.py @@ -9,7 +9,7 @@ class LocalShareModeStayOpenTest(unittest.TestCase, GuiShareTest): test_settings = { "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeStayOpenTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_share_mode_download_test.py b/tests/local_onionshare_share_mode_download_test.py index 53db0296..ff182740 100644 --- a/tests/local_onionshare_share_mode_download_test.py +++ b/tests/local_onionshare_share_mode_download_test.py @@ -8,7 +8,7 @@ class LocalShareModeTest(unittest.TestCase, GuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_share_mode_large_download_test.py b/tests/local_onionshare_share_mode_large_download_test.py index 5f5de888..46e6df28 100644 --- a/tests/local_onionshare_share_mode_large_download_test.py +++ b/tests/local_onionshare_share_mode_large_download_test.py @@ -8,7 +8,7 @@ class LocalShareModeLargeDownloadTest(unittest.TestCase, GuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeLargeDownloadTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_share_mode_slug_persistent_test.py b/tests/local_onionshare_share_mode_slug_persistent_test.py index c273fbda..a1cc6972 100644 --- a/tests/local_onionshare_share_mode_slug_persistent_test.py +++ b/tests/local_onionshare_share_mode_slug_persistent_test.py @@ -12,7 +12,7 @@ class LocalShareModePersistentSlugTest(unittest.TestCase, GuiShareTest): "save_private_key": True, "close_after_first_download": False, } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePersistentSlugTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_share_mode_timer_test.py b/tests/local_onionshare_share_mode_timer_test.py index 394dec21..41a6268d 100644 --- a/tests/local_onionshare_share_mode_timer_test.py +++ b/tests/local_onionshare_share_mode_timer_test.py @@ -10,7 +10,7 @@ class LocalShareModeTimerTest(unittest.TestCase, GuiShareTest): "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_share_mode_timer_too_short_test.py b/tests/local_onionshare_share_mode_timer_too_short_test.py index 16153c3e..41c30883 100644 --- a/tests/local_onionshare_share_mode_timer_too_short_test.py +++ b/tests/local_onionshare_share_mode_timer_too_short_test.py @@ -11,7 +11,7 @@ class LocalShareModeTimerTooShortTest(unittest.TestCase, GuiShareTest): "public_mode": False, "shutdown_timeout": True, } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTooShortTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/local_onionshare_share_mode_unreadable_file_test.py b/tests/local_onionshare_share_mode_unreadable_file_test.py index 0e0970ea..38a0e847 100644 --- a/tests/local_onionshare_share_mode_unreadable_file_test.py +++ b/tests/local_onionshare_share_mode_unreadable_file_test.py @@ -8,7 +8,7 @@ class LocalShareModeUnReadableFileTest(unittest.TestCase, GuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeUnReadableFileTest') + cls.gui = GuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_790_cancel_on_second_share_test.py b/tests/onionshare_790_cancel_on_second_share_test.py index dce84f62..b144edf3 100644 --- a/tests/onionshare_790_cancel_on_second_share_test.py +++ b/tests/onionshare_790_cancel_on_second_share_test.py @@ -11,7 +11,7 @@ class ShareModeCancelSecondShareTest(unittest.TestCase, TorGuiShareTest): test_settings = { "close_after_first_download": True } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelSecondShareTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_receive_mode_upload_public_mode_test.py b/tests/onionshare_receive_mode_upload_public_mode_test.py index 048186c3..275e5953 100644 --- a/tests/onionshare_receive_mode_upload_public_mode_test.py +++ b/tests/onionshare_receive_mode_upload_public_mode_test.py @@ -11,7 +11,7 @@ class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): "public_mode": True, "receive_allow_receiver_shutdown": True } - cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') + cls.gui = TorGuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_receive_mode_upload_test.py b/tests/onionshare_receive_mode_upload_test.py index d3965d59..f9914659 100644 --- a/tests/onionshare_receive_mode_upload_test.py +++ b/tests/onionshare_receive_mode_upload_test.py @@ -10,7 +10,7 @@ class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest): test_settings = { "receive_allow_receiver_shutdown": True } - cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest') + cls.gui = TorGuiReceiveTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_share_mode_cancel_share_test.py b/tests/onionshare_share_mode_cancel_share_test.py index 83a009a1..5f4d6fb3 100644 --- a/tests/onionshare_share_mode_cancel_share_test.py +++ b/tests/onionshare_share_mode_cancel_share_test.py @@ -9,7 +9,7 @@ class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeCancelTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_share_mode_download_public_mode_test.py b/tests/onionshare_share_mode_download_public_mode_test.py index 8c5740c5..672603ce 100644 --- a/tests/onionshare_share_mode_download_public_mode_test.py +++ b/tests/onionshare_share_mode_download_public_mode_test.py @@ -10,7 +10,7 @@ class ShareModePublicModeTest(unittest.TestCase, TorGuiShareTest): test_settings = { "public_mode": True, } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePublicModeTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_share_mode_download_stay_open_test.py b/tests/onionshare_share_mode_download_stay_open_test.py index 56ac924d..e7e64083 100644 --- a/tests/onionshare_share_mode_download_stay_open_test.py +++ b/tests/onionshare_share_mode_download_stay_open_test.py @@ -10,7 +10,7 @@ class ShareModeStayOpenTest(unittest.TestCase, TorGuiShareTest): test_settings = { "close_after_first_download": False, } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_share_mode_download_test.py b/tests/onionshare_share_mode_download_test.py index 125909d0..7d414e5d 100644 --- a/tests/onionshare_share_mode_download_test.py +++ b/tests/onionshare_share_mode_download_test.py @@ -9,7 +9,7 @@ class ShareModeTest(unittest.TestCase, TorGuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_share_mode_persistent_test.py b/tests/onionshare_share_mode_persistent_test.py index 3f103a1a..86b61a81 100644 --- a/tests/onionshare_share_mode_persistent_test.py +++ b/tests/onionshare_share_mode_persistent_test.py @@ -14,7 +14,7 @@ class ShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest): "save_private_key": True, "close_after_first_download": False, } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_share_mode_stealth_test.py b/tests/onionshare_share_mode_stealth_test.py index 78e87e9e..b16669e6 100644 --- a/tests/onionshare_share_mode_stealth_test.py +++ b/tests/onionshare_share_mode_stealth_test.py @@ -11,7 +11,7 @@ class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest): "use_legacy_v2_onions": True, "use_stealth": True, } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStealthTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_share_mode_timer_test.py b/tests/onionshare_share_mode_timer_test.py index 9e690ec7..a13d2d80 100644 --- a/tests/onionshare_share_mode_timer_test.py +++ b/tests/onionshare_share_mode_timer_test.py @@ -11,7 +11,7 @@ class ShareModeTimerTest(unittest.TestCase, TorGuiShareTest): "public_mode": False, "shutdown_timeout": True, } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTimerTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): diff --git a/tests/onionshare_share_mode_tor_connection_killed_test.py b/tests/onionshare_share_mode_tor_connection_killed_test.py index 382ed547..62513a12 100644 --- a/tests/onionshare_share_mode_tor_connection_killed_test.py +++ b/tests/onionshare_share_mode_tor_connection_killed_test.py @@ -9,7 +9,7 @@ class ShareModeTorConnectionKilledTest(unittest.TestCase, TorGuiShareTest): def setUpClass(cls): test_settings = { } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTorConnectionKilledTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @pytest.mark.tor def test_gui(self): diff --git a/tests/onionshare_share_mode_v2_onion_test.py b/tests/onionshare_share_mode_v2_onion_test.py index f06f6631..c932abf9 100644 --- a/tests/onionshare_share_mode_v2_onion_test.py +++ b/tests/onionshare_share_mode_v2_onion_test.py @@ -10,7 +10,7 @@ class ShareModeV2OnionTest(unittest.TestCase, TorGuiShareTest): test_settings = { "use_legacy_v2_onions": True, } - cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeV2OnionTest') + cls.gui = TorGuiShareTest.set_up(test_settings) @classmethod def tearDownClass(cls): From ec6541dfbc321f421b64d4ece59284d38a250520 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 16:36:58 +1100 Subject: [PATCH 31/72] raise timer seuqnce on open settings dialog test (in case that's why it's segfaulting in Travis) --- tests/local_onionshare_open_settings_dialog_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/local_onionshare_open_settings_dialog_test.py b/tests/local_onionshare_open_settings_dialog_test.py index 61e66be2..af20c73f 100644 --- a/tests/local_onionshare_open_settings_dialog_test.py +++ b/tests/local_onionshare_open_settings_dialog_test.py @@ -19,7 +19,7 @@ class LocalOpenSettingsDialogTest(unittest.TestCase, GuiShareTest): self.run_all_common_setup_tests() self.run_all_share_mode_setup_tests() # Make sure we can open the settings dialog via the settings button - QtCore.QTimer.singleShot(1000, self.accept_dialog) + QtCore.QTimer.singleShot(4000, self.accept_dialog) QtTest.QTest.mouseClick(self.gui.settings_button, QtCore.Qt.LeftButton) if __name__ == "__main__": From 2692e47d5468cd58b0d2248adf8b0a6043b28f13 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 16:45:52 +1100 Subject: [PATCH 32/72] Revert "raise timer seuqnce on open settings dialog test (in case that's why it's segfaulting in Travis)" This reverts commit ec6541dfbc321f421b64d4ece59284d38a250520. --- tests/local_onionshare_open_settings_dialog_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/local_onionshare_open_settings_dialog_test.py b/tests/local_onionshare_open_settings_dialog_test.py index af20c73f..61e66be2 100644 --- a/tests/local_onionshare_open_settings_dialog_test.py +++ b/tests/local_onionshare_open_settings_dialog_test.py @@ -19,7 +19,7 @@ class LocalOpenSettingsDialogTest(unittest.TestCase, GuiShareTest): self.run_all_common_setup_tests() self.run_all_share_mode_setup_tests() # Make sure we can open the settings dialog via the settings button - QtCore.QTimer.singleShot(4000, self.accept_dialog) + QtCore.QTimer.singleShot(1000, self.accept_dialog) QtTest.QTest.mouseClick(self.gui.settings_button, QtCore.Qt.LeftButton) if __name__ == "__main__": From fddf65ec500ff1409664c86f1edce7164d7397a6 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 16:51:49 +1100 Subject: [PATCH 33/72] Add initial .circleci config --- .circleci/config.yml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..17e8979c --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,43 @@ +# Python CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-python/ for more details +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` + - image: circleci/python:3.6.1 + + working_directory: ~/repo + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "install/requirements-tests.txt" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: + name: install dependencies + command: | + python3 -m venv venv + . venv/bin/activate + pip install -r install/requirements-tests.txt + + - save_cache: + paths: + - ./venv + key: v1-dependencies-{{ checksum "install/requirements-tests.txt" }} + + # run tests! + - run: + name: run tests + command: | + . venv/bin/activate + xvfb-run pytest --cov=onionshare --cov=onionshare_gui --cov-report=term-missing -vvv tests/ + From 2dbc7d766aed541d8d6455e07c072846cb77a1f2 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 16:55:15 +1100 Subject: [PATCH 34/72] try to get circleci to build just this branch for now --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 17e8979c..79f902c5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,9 @@ version: 2 jobs: build: + branches: + only: + - fix_tor_tests docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` From 8bf740d9ccc63362bd44b0ecfa7c87cf0dc50820 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 16:58:05 +1100 Subject: [PATCH 35/72] circleci tweaks --- .circleci/config.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 79f902c5..6adcdfa9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,27 +18,26 @@ jobs: steps: - checkout - # Download and cache dependencies - - restore_cache: - keys: - - v1-dependencies-{{ checksum "install/requirements-tests.txt" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - run: name: install dependencies command: | + sudo apt-get update && sudo apt-get install python3-pyqt5 python3 -m venv venv . venv/bin/activate + pip install -r install/requirements.txt + pip install -r install/requirements-tests.txt + pip install pytest-cov flake8 pip install -r install/requirements-tests.txt - - save_cache: - paths: - - ./venv - key: v1-dependencies-{{ checksum "install/requirements-tests.txt" }} - # run tests! - run: + name: run flask tests + command: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + name: run tests command: | . venv/bin/activate From d2c10558230c304005087364f54e04569841e8b9 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 16:59:13 +1100 Subject: [PATCH 36/72] circleci tweaks --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6adcdfa9..f50a98f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,11 +33,13 @@ jobs: - run: name: run flask tests command: | + . venv/bin/activate # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - run: name: run tests command: | . venv/bin/activate From 6c5df1cffcc86436807d2fe37ff0f9bd53b90942 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:04:24 +1100 Subject: [PATCH 37/72] circleci tweaks --- .circleci/config.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f50a98f7..ff902d04 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,18 +22,14 @@ jobs: name: install dependencies command: | sudo apt-get update && sudo apt-get install python3-pyqt5 - python3 -m venv venv - . venv/bin/activate - pip install -r install/requirements.txt - pip install -r install/requirements-tests.txt - pip install pytest-cov flake8 - pip install -r install/requirements-tests.txt + pip3 install -r install/requirements.txt + pip3 install -r install/requirements-tests.txt + pip3 install pytest-cov flake8 # run tests! - run: name: run flask tests command: | - . venv/bin/activate # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide @@ -42,6 +38,5 @@ jobs: - run: name: run tests command: | - . venv/bin/activate xvfb-run pytest --cov=onionshare --cov=onionshare_gui --cov-report=term-missing -vvv tests/ From 3139aa9a57b9f70cc6fa4cd8f43b46bcb2b673dd Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:15:13 +1100 Subject: [PATCH 38/72] sudo --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ff902d04..ba6d4ab8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,9 +22,9 @@ jobs: name: install dependencies command: | sudo apt-get update && sudo apt-get install python3-pyqt5 - pip3 install -r install/requirements.txt - pip3 install -r install/requirements-tests.txt - pip3 install pytest-cov flake8 + sudo pip3 install -r install/requirements.txt + sudo pip3 install -r install/requirements-tests.txt + sudo pip3 install pytest-cov flake8 # run tests! - run: From 75dbf4f14b92d697d42280ada039cee41a60f2e8 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:15:34 +1100 Subject: [PATCH 39/72] remove branch specific config --- .circleci/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ba6d4ab8..52576430 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,9 +5,6 @@ version: 2 jobs: build: - branches: - only: - - fix_tor_tests docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` From 0e95749e33a3d26731552798cbd70f1c810fa969 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:17:43 +1100 Subject: [PATCH 40/72] Travis and CircleCI hate this simple test --- ...al_onionshare_open_settings_dialog_test.py | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 tests/local_onionshare_open_settings_dialog_test.py diff --git a/tests/local_onionshare_open_settings_dialog_test.py b/tests/local_onionshare_open_settings_dialog_test.py deleted file mode 100644 index 61e66be2..00000000 --- a/tests/local_onionshare_open_settings_dialog_test.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python3 -import unittest -from PyQt5 import QtCore, QtTest - -from .GuiShareTest import GuiShareTest - -class LocalOpenSettingsDialogTest(unittest.TestCase, GuiShareTest): - @classmethod - def setUpClass(cls): - test_settings = { - } - cls.gui = GuiShareTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiShareTest.tear_down() - - def test_gui(self): - self.run_all_common_setup_tests() - self.run_all_share_mode_setup_tests() - # Make sure we can open the settings dialog via the settings button - QtCore.QTimer.singleShot(1000, self.accept_dialog) - QtTest.QTest.mouseClick(self.gui.settings_button, QtCore.Qt.LeftButton) - -if __name__ == "__main__": - unittest.main() From 8e4c70e7fb2e528f7273ffc7f4a512733f09b07b Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:23:25 +1100 Subject: [PATCH 41/72] Fix path to large_file in teardown class --- tests/GuiBaseTest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index af5f1944..68f18f72 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -62,7 +62,7 @@ class GuiBaseTest(object): try: os.remove('/tmp/test.txt') os.remove('/tmp/settings.json') - os.remove('/tmp/largefile') + os.remove('/tmp/large_file') shutil.rmtree('/tmp/OnionShare') shutil.rmtree('/tmp/testdir') except: From 4ae5c9bcd92e49b36138da548abd9c1a1b23ce1e Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:28:13 +1100 Subject: [PATCH 42/72] run on same version of python as me --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 52576430..23bf4806 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` - - image: circleci/python:3.6.1 + - image: circleci/python:3.6.6 working_directory: ~/repo From 7a7d992cb7cedf36a2709092d3c9ad2ed07f47ea Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:29:44 +1100 Subject: [PATCH 43/72] more cleanup in teardown class --- tests/GuiBaseTest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index 68f18f72..c557fc15 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -63,8 +63,10 @@ class GuiBaseTest(object): os.remove('/tmp/test.txt') os.remove('/tmp/settings.json') os.remove('/tmp/large_file') - shutil.rmtree('/tmp/OnionShare') + os.remove('/tmp/download.zip') + os.remove('/tmp/webpage') shutil.rmtree('/tmp/testdir') + shutil.rmtree('/tmp/OnionShare') except: pass From 29f987a903ab96b4c741e809f00b83d47294910a Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:38:28 +1100 Subject: [PATCH 44/72] see if it's a version issue --- install/requirements-tests.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install/requirements-tests.txt b/install/requirements-tests.txt index b931afd1..849e1166 100644 --- a/install/requirements-tests.txt +++ b/install/requirements-tests.txt @@ -1,9 +1,9 @@ atomicwrites==1.2.1 attrs==18.2.0 more-itertools==4.3.0 -pluggy==0.6.0 -py==1.6.0 -pytest==3.4.2 +pluggy==0.7.1 +py==1.7.0 +pytest==3.8.2 pytest-faulthandler==1.5.0 pytest-qt==3.1.0 six==1.11.0 From 95f30f9a4241feb7de17b6f20a082e531d63349a Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:50:16 +1100 Subject: [PATCH 45/72] The only other version difference I can find is PyQt itself --- .circleci/config.yml | 1 - install/requirements.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 23bf4806..3594e9f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,6 @@ jobs: - run: name: install dependencies command: | - sudo apt-get update && sudo apt-get install python3-pyqt5 sudo pip3 install -r install/requirements.txt sudo pip3 install -r install/requirements-tests.txt sudo pip3 install pytest-cov flake8 diff --git a/install/requirements.txt b/install/requirements.txt index 32ec6887..f09d2e95 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -17,7 +17,7 @@ pycparser==2.18 pycryptodome==3.6.6 PyInstaller==3.4 PyNaCl==1.2.1 -PyQt5==5.11.2 +PyQt5==5.11.3 PyQt5-sip==4.19.12 PySocks==1.6.8 requests==2.19.1 From fab25aca114b0b578991cebd42eb002e5566ebd8 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:51:45 +1100 Subject: [PATCH 46/72] Revert "The only other version difference I can find is PyQt itself" This reverts commit 95f30f9a4241feb7de17b6f20a082e531d63349a. --- .circleci/config.yml | 1 + install/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3594e9f8..23bf4806 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,6 +18,7 @@ jobs: - run: name: install dependencies command: | + sudo apt-get update && sudo apt-get install python3-pyqt5 sudo pip3 install -r install/requirements.txt sudo pip3 install -r install/requirements-tests.txt sudo pip3 install pytest-cov flake8 diff --git a/install/requirements.txt b/install/requirements.txt index f09d2e95..32ec6887 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -17,7 +17,7 @@ pycparser==2.18 pycryptodome==3.6.6 PyInstaller==3.4 PyNaCl==1.2.1 -PyQt5==5.11.3 +PyQt5==5.11.2 PyQt5-sip==4.19.12 PySocks==1.6.8 requests==2.19.1 From 8a9b6ac63383c348ca88f656ee3d9362f338f1a6 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 17:59:16 +1100 Subject: [PATCH 47/72] Tweaks to SettingsGuiBaseTest object --- tests/SettingsGuiBaseTest.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/SettingsGuiBaseTest.py b/tests/SettingsGuiBaseTest.py index 195e7933..e59a58a8 100644 --- a/tests/SettingsGuiBaseTest.py +++ b/tests/SettingsGuiBaseTest.py @@ -1,13 +1,10 @@ import json import os -import sys -from PyQt5 import QtWidgets from onionshare import strings from onionshare.common import Common from onionshare.settings import Settings from onionshare.onion import Onion -from onionshare.web import Web from onionshare_gui import Application, OnionShare from onionshare_gui.settings_dialog import SettingsDialog @@ -31,8 +28,6 @@ class SettingsGuiBaseTest(object): qtapp = Application(common) app = OnionShare(common, testonion, True, 0) - web = Web(common, False, True) - for key, val in common.settings.default_settings.items(): if key not in test_settings: test_settings[key] = val From 7d9f2f1458f166b4860b5ea1a41c0b74ad98aff2 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Wed, 17 Oct 2018 18:04:38 +1100 Subject: [PATCH 48/72] pytest-qt is 3.2.1 on my machine --- install/requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/requirements-tests.txt b/install/requirements-tests.txt index 849e1166..57e98ce1 100644 --- a/install/requirements-tests.txt +++ b/install/requirements-tests.txt @@ -5,6 +5,6 @@ pluggy==0.7.1 py==1.7.0 pytest==3.8.2 pytest-faulthandler==1.5.0 -pytest-qt==3.1.0 +pytest-qt==3.2.1 six==1.11.0 urllib3==1.23 From 3b3e79fdf0101dadce70084c9af85fc1d73b7cb4 Mon Sep 17 00:00:00 2001 From: Austin Jackson Date: Wed, 17 Oct 2018 13:19:35 -0500 Subject: [PATCH 49/72] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55487045..fbb9c914 100644 --- a/README.md +++ b/README.md @@ -18,5 +18,5 @@ You can set up your development environment to build OnionShare yourself by foll # Screenshots -![Server Screenshot](/screenshots/server.png) +![Server Screenshot](/screenshots/appdata-server.png) ![Client Screenshot](/screenshots/client.png) From 25d6bd12ead9c6dca927f025e69cf1ba3cd5f291 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 16:57:05 +1100 Subject: [PATCH 50/72] try and build off buster --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 23bf4806..4ad43577 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` - - image: circleci/python:3.6.6 + - image: debian/buster working_directory: ~/repo @@ -18,7 +18,7 @@ jobs: - run: name: install dependencies command: | - sudo apt-get update && sudo apt-get install python3-pyqt5 + sudo apt-get update && sudo apt-get install python3-pyqt5 python3-pip sudo pip3 install -r install/requirements.txt sudo pip3 install -r install/requirements-tests.txt sudo pip3 install pytest-cov flake8 From fbc16f4d7b48f5aed0c4c1973da8827d9b9d2450 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 16:57:59 +1100 Subject: [PATCH 51/72] buster is a tag --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4ad43577..2585995a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` - - image: debian/buster + - image: debian:buster working_directory: ~/repo From e4e42849d6746ed5aad91c491e808ba961d0531a Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 16:59:49 +1100 Subject: [PATCH 52/72] see if we can avoid sudo --- .circleci/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2585995a..14a4a8c7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,10 +18,10 @@ jobs: - run: name: install dependencies command: | - sudo apt-get update && sudo apt-get install python3-pyqt5 python3-pip - sudo pip3 install -r install/requirements.txt - sudo pip3 install -r install/requirements-tests.txt - sudo pip3 install pytest-cov flake8 + apt-get update && apt-get install python3-pyqt5 python3-pip + pip3 install -r install/requirements.txt + pip3 install -r install/requirements-tests.txt + pip3 install pytest-cov flake8 # run tests! - run: From 6afe7354c96e4b862b375ecb5369cfc9e99b1e74 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:00:46 +1100 Subject: [PATCH 53/72] avoid prompt --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 14a4a8c7..e6974459 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ jobs: - run: name: install dependencies command: | - apt-get update && apt-get install python3-pyqt5 python3-pip + apt-get update && apt-get install -y python3-pyqt5 python3-pip pip3 install -r install/requirements.txt pip3 install -r install/requirements-tests.txt pip3 install pytest-cov flake8 From 4b6b7f68fb99144bb61e41e5fd4bdf3a1c170496 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:01:33 +1100 Subject: [PATCH 54/72] xvfb should be installed --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e6974459..5c05cf13 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ jobs: - run: name: install dependencies command: | - apt-get update && apt-get install -y python3-pyqt5 python3-pip + apt-get update && apt-get install -y python3-pyqt5 python3-pip xvfb pip3 install -r install/requirements.txt pip3 install -r install/requirements-tests.txt pip3 install pytest-cov flake8 From 9d986e41e1b4539597cd973a03d5db6fa2e6dc0c Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:11:39 +1100 Subject: [PATCH 55/72] don't install main requirements.txt --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5c05cf13..1a985254 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,6 @@ jobs: name: install dependencies command: | apt-get update && apt-get install -y python3-pyqt5 python3-pip xvfb - pip3 install -r install/requirements.txt pip3 install -r install/requirements-tests.txt pip3 install pytest-cov flake8 From 8095f0c9f888916baf929f53bdd310bba29aea52 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:15:00 +1100 Subject: [PATCH 56/72] Other dependencies --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a985254..313016d7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ jobs: - run: name: install dependencies command: | - apt-get update && apt-get install -y python3-pyqt5 python3-pip xvfb + apt-get update && apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python-nautilus xvfb pip3 install -r install/requirements-tests.txt pip3 install pytest-cov flake8 From 45edb9b991e1e0c9f8d20460268b25325b10a872 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:17:57 +1100 Subject: [PATCH 57/72] Add the other python dependencies from the BUILD.md --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 313016d7..1ad43878 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ jobs: - run: name: install dependencies command: | - apt-get update && apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python-nautilus xvfb + apt-get update && apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb pip3 install -r install/requirements-tests.txt pip3 install pytest-cov flake8 From 59312bddbc72d1d39629d058eea2b756070c24cf Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:34:34 +1100 Subject: [PATCH 58/72] Back to python container --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ad43878..46d1ab08 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` - - image: debian:buster + - image: circleci/python:3.6.6 working_directory: ~/repo @@ -18,7 +18,7 @@ jobs: - run: name: install dependencies command: | - apt-get update && apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb + apt-get update && apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy pip3 install -r install/requirements-tests.txt pip3 install pytest-cov flake8 From fc7dd52c62dfcfb3478fcfcfde6ff99bbe71d9a7 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:35:30 +1100 Subject: [PATCH 59/72] Back to sudo --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 46d1ab08..c90a85be 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,9 +18,9 @@ jobs: - run: name: install dependencies command: | - apt-get update && apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy - pip3 install -r install/requirements-tests.txt - pip3 install pytest-cov flake8 + sudo apt-get update && apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy + sudo pip3 install -r install/requirements-tests.txt + sudo pip3 install pytest-cov flake8 # run tests! - run: From 5d4dc1b4f5a2fdc48951867c85ee7c1337cdf2b0 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:36:12 +1100 Subject: [PATCH 60/72] more sudo --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c90a85be..c2af3b1e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ jobs: - run: name: install dependencies command: | - sudo apt-get update && apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy + sudo apt-get update && sudo apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy sudo pip3 install -r install/requirements-tests.txt sudo pip3 install pytest-cov flake8 From be71b23399d5739f62742e681175fce4739b36b7 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:38:15 +1100 Subject: [PATCH 61/72] back to installing main requirements.txt --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c2af3b1e..b8758353 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,12 +19,13 @@ jobs: name: install dependencies command: | sudo apt-get update && sudo apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy + sudo pip3 install -r install/requirements.txt sudo pip3 install -r install/requirements-tests.txt sudo pip3 install pytest-cov flake8 # run tests! - run: - name: run flask tests + name: run flake tests command: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics From 23b2f93f83c86012c5054d5179a2384769572af9 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:42:27 +1100 Subject: [PATCH 62/72] Tweak travis yml to run the same commands as circle just for curiosity --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec7ba912..2ae3f704 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,10 @@ python: - "nightly" # command to install dependencies install: - - sudo apt-get update && sudo apt-get install python3-pyqt5 - - pip install -r install/requirements.txt - - pip install -r install/requirements-tests.txt - - pip install pytest-cov flake8 + - sudo apt-get update && sudo apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy + - sudo pip3 install -r install/requirements.txt + - sudo pip3 install -r install/requirements-tests.txt + - sudo pip3 install pytest-cov flake8 before_script: # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics From 351f3f0d82ba2d746bb922f273cd298f7464ee76 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:42:57 +1100 Subject: [PATCH 63/72] Revert "Travis and CircleCI hate this simple test" This reverts commit 0e95749e33a3d26731552798cbd70f1c810fa969. --- ...al_onionshare_open_settings_dialog_test.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/local_onionshare_open_settings_dialog_test.py diff --git a/tests/local_onionshare_open_settings_dialog_test.py b/tests/local_onionshare_open_settings_dialog_test.py new file mode 100644 index 00000000..61e66be2 --- /dev/null +++ b/tests/local_onionshare_open_settings_dialog_test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import unittest +from PyQt5 import QtCore, QtTest + +from .GuiShareTest import GuiShareTest + +class LocalOpenSettingsDialogTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + } + cls.gui = GuiShareTest.set_up(test_settings) + + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_setup_tests() + # Make sure we can open the settings dialog via the settings button + QtCore.QTimer.singleShot(1000, self.accept_dialog) + QtTest.QTest.mouseClick(self.gui.settings_button, QtCore.Qt.LeftButton) + +if __name__ == "__main__": + unittest.main() From a63f6bc019f530b7e4cdf0df3d7c99ab14243cc6 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:55:11 +1100 Subject: [PATCH 64/72] Remove problematic test again --- ...al_onionshare_open_settings_dialog_test.py | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 tests/local_onionshare_open_settings_dialog_test.py diff --git a/tests/local_onionshare_open_settings_dialog_test.py b/tests/local_onionshare_open_settings_dialog_test.py deleted file mode 100644 index 61e66be2..00000000 --- a/tests/local_onionshare_open_settings_dialog_test.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python3 -import unittest -from PyQt5 import QtCore, QtTest - -from .GuiShareTest import GuiShareTest - -class LocalOpenSettingsDialogTest(unittest.TestCase, GuiShareTest): - @classmethod - def setUpClass(cls): - test_settings = { - } - cls.gui = GuiShareTest.set_up(test_settings) - - @classmethod - def tearDownClass(cls): - GuiShareTest.tear_down() - - def test_gui(self): - self.run_all_common_setup_tests() - self.run_all_share_mode_setup_tests() - # Make sure we can open the settings dialog via the settings button - QtCore.QTimer.singleShot(1000, self.accept_dialog) - QtTest.QTest.mouseClick(self.gui.settings_button, QtCore.Qt.LeftButton) - -if __name__ == "__main__": - unittest.main() From a19a4bc6cf8602794a7631304e5e77fc8e728443 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 18 Oct 2018 17:55:26 +1100 Subject: [PATCH 65/72] Revert "Tweak travis yml to run the same commands as circle just for curiosity" This reverts commit 23b2f93f83c86012c5054d5179a2384769572af9. --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2ae3f704..ec7ba912 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,10 @@ python: - "nightly" # command to install dependencies install: - - sudo apt-get update && sudo apt-get install -y python3-pip python3-flask python3-stem python3-pyqt5 python3-cryptography python3-crypto python3-nacl python3-socks python3-stdeb python3-all python-nautilus xvfb obfs4proxy - - sudo pip3 install -r install/requirements.txt - - sudo pip3 install -r install/requirements-tests.txt - - sudo pip3 install pytest-cov flake8 + - sudo apt-get update && sudo apt-get install python3-pyqt5 + - pip install -r install/requirements.txt + - pip install -r install/requirements-tests.txt + - pip install pytest-cov flake8 before_script: # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics From 6ee47cec6ff721a7f9c258f8d879ff2f2f563f3e Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 25 Oct 2018 11:01:09 -0700 Subject: [PATCH 66/72] Delete obsolete dev_scripts/run_all_tests.sh script, and add xvfb-run info to the build instructions --- BUILD.md | 6 ++++++ dev_scripts/run_all_tests.sh | 14 -------------- 2 files changed, 6 insertions(+), 14 deletions(-) delete mode 100755 dev_scripts/run_all_tests.sh diff --git a/BUILD.md b/BUILD.md index b92f4110..2a055d98 100644 --- a/BUILD.md +++ b/BUILD.md @@ -156,3 +156,9 @@ pytest --runtor tests/ ``` Keep in mind that the Tor tests take a lot longer to run than local mode, but they are also more comprehensive. + +You can also choose to wrap the tests in `xvfb-run` so that a ton of OnionShare windows don't pop up on your desktop (you may need to install the `xorg-x11-server-Xvfb` package), like this: + +```sh +xvfb-run pytest tests/ +``` diff --git a/dev_scripts/run_all_tests.sh b/dev_scripts/run_all_tests.sh deleted file mode 100755 index 90ef1dc0..00000000 --- a/dev_scripts/run_all_tests.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -ROOT="$( dirname $(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd ))" - -# CLI tests -cd $ROOT -pytest tests/ - -# Local GUI tests -cd $ROOT/tests_gui_local -./run_unit_tests.sh - -# Tor GUI tests -cd $ROOT/tests_gui_tor -./run_unit_tests.sh From 1b8821fc385c9ba4978776839125f413e2448f1f Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 25 Oct 2018 13:16:30 -0700 Subject: [PATCH 67/72] Remove .travis.yml because we're switching to CircleCI --- .travis.yml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ec7ba912..00000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: python -dist: trusty -sudo: required -python: - - "3.6" - - "3.6-dev" - - "3.7-dev" - - "nightly" -# command to install dependencies -install: - - sudo apt-get update && sudo apt-get install python3-pyqt5 - - pip install -r install/requirements.txt - - pip install -r install/requirements-tests.txt - - pip install pytest-cov flake8 -before_script: - # stop the build if there are Python syntax errors or undefined names - - flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics -# run CLI tests and local GUI tests -script: - - xvfb-run pytest --cov=onionshare --cov=onionshare_gui -vvv tests/ From 6067e60349b90c7f3716b5c1c5063b3e27b1dbf7 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 25 Oct 2018 13:20:46 -0700 Subject: [PATCH 68/72] Update CI build status image in readme to use CircleCI instead of Travis --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55487045..052aaf59 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OnionShare -[![Build Status](https://travis-ci.org/micahflee/onionshare.png)](https://travis-ci.org/micahflee/onionshare) +[![CircleCI](https://circleci.com/gh/micahflee/onionshare.svg?style=svg)](https://circleci.com/gh/micahflee/onionshare) [OnionShare](https://onionshare.org) lets you securely and anonymously share files of any size. It works by starting a web server, making it accessible as a Tor Onion Service, and generating an unguessable URL to access and download the files. It does _not_ require setting up a separate server or using a third party file-sharing service. You host the files on your own computer and use a Tor Onion Service to make it temporarily accessible over the internet. The receiving user just needs to open the URL in Tor Browser to download the file. From 2c45f6851e032f60d109ef3b3d368a5f0050b476 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 25 Oct 2018 21:13:16 -0700 Subject: [PATCH 69/72] Receive mode puts files in a directory based on the timestamp of the upload --- onionshare/__init__.py | 2 +- onionshare/common.py | 27 --------------------------- onionshare/web/receive_mode.py | 27 ++++++++++++++------------- onionshare/web/web.py | 1 - onionshare_gui/onionshare_gui.py | 5 +---- share/locale/en.json | 1 - 6 files changed, 16 insertions(+), 47 deletions(-) diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 069559c5..1e81333e 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -21,7 +21,7 @@ along with this program. If not, see . import os, sys, time, argparse, threading from . import strings -from .common import Common, DownloadsDirErrorCannotCreate, DownloadsDirErrorNotWritable +from .common import Common from .web import Web from .onion import * from .onionshare import OnionShare diff --git a/onionshare/common.py b/onionshare/common.py index cab1e747..ffa6529f 100644 --- a/onionshare/common.py +++ b/onionshare/common.py @@ -32,20 +32,6 @@ import time from .settings import Settings -class DownloadsDirErrorCannotCreate(Exception): - """ - Error creating the downloads dir (~/OnionShare by default). - """ - pass - - -class DownloadsDirErrorNotWritable(Exception): - """ - Downloads dir is not writable. - """ - pass - - class Common(object): """ The Common object is shared amongst all parts of OnionShare. @@ -390,19 +376,6 @@ class Common(object): }""" } - def validate_downloads_dir(self): - """ - Validate that downloads_dir exists, and create it if it doesn't - """ - if not os.path.isdir(self.settings.get('downloads_dir')): - try: - os.mkdir(self.settings.get('downloads_dir'), 0o700) - except: - raise DownloadsDirErrorCannotCreate - - if not os.access(self.settings.get('downloads_dir'), os.W_OK): - raise DownloadsDirErrorNotWritable - @staticmethod def random_string(num_bytes, output_len=None): """ diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py index 4a6934a1..66e00240 100644 --- a/onionshare/web/receive_mode.py +++ b/onionshare/web/receive_mode.py @@ -4,7 +4,6 @@ from datetime import datetime from flask import Request, request, render_template, make_response, flash, redirect from werkzeug.utils import secure_filename -from ..common import DownloadsDirErrorCannotCreate, DownloadsDirErrorNotWritable from .. import strings @@ -59,17 +58,19 @@ class ReceiveModeWeb(object): """ Upload files. """ - # Make sure downloads_dir exists + # Make sure the receive mode dir exists + now = datetime.now() + date_dir = now.strftime("%Y-%m-%d") + time_dir = now.strftime("%H.%M:%S") + receive_mode_dir = os.path.join(self.common.settings.get('downloads_dir'), date_dir, time_dir) valid = True try: - self.common.validate_downloads_dir() - except DownloadsDirErrorCannotCreate: - self.web.add_request(self.web.REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE, request.path) - print(strings._('error_cannot_create_downloads_dir').format(self.common.settings.get('downloads_dir'))) - valid = False - except DownloadsDirErrorNotWritable: - self.web.add_request(self.web.REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE, request.path) - print(strings._('error_downloads_dir_not_writable').format(self.common.settings.get('downloads_dir'))) + os.makedirs(receive_mode_dir, 0o700) + except PermissionError: + self.web.add_request(self.web.REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE, request.path, { + "receive_mode_dir": receive_mode_dir + }) + print(strings._('error_cannot_create_downloads_dir').format(receive_mode_dir)) valid = False if not valid: flash('Error uploading, please inform the OnionShare user', 'error') @@ -86,7 +87,7 @@ class ReceiveModeWeb(object): # Automatically rename the file, if a file of the same name already exists filename = secure_filename(f.filename) filenames.append(filename) - local_path = os.path.join(self.common.settings.get('downloads_dir'), filename) + local_path = os.path.join(receive_mode_dir, filename) if os.path.exists(local_path): if '.' in filename: # Add "-i", e.g. change "foo.txt" to "foo-2.txt" @@ -98,7 +99,7 @@ class ReceiveModeWeb(object): valid = False while not valid: new_filename = '{}-{}.{}'.format('.'.join(name), i, ext) - local_path = os.path.join(self.common.settings.get('downloads_dir'), new_filename) + local_path = os.path.join(receive_mode_dir, new_filename) if os.path.exists(local_path): i += 1 else: @@ -109,7 +110,7 @@ class ReceiveModeWeb(object): valid = False while not valid: new_filename = '{}-{}'.format(filename, i) - local_path = os.path.join(self.common.settings.get('downloads_dir'), new_filename) + local_path = os.path.join(receive_mode_dir, new_filename) if os.path.exists(local_path): i += 1 else: diff --git a/onionshare/web/web.py b/onionshare/web/web.py index 52c4da16..2ae011b7 100644 --- a/onionshare/web/web.py +++ b/onionshare/web/web.py @@ -39,7 +39,6 @@ class Web(object): REQUEST_UPLOAD_FILE_RENAMED = 7 REQUEST_UPLOAD_FINISHED = 8 REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 9 - REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE = 10 def __init__(self, common, is_gui, mode='share'): self.common = common diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 8c8e4e73..1e254f61 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -394,10 +394,7 @@ class OnionShareGui(QtWidgets.QMainWindow): mode.handle_request_upload_finished(event) if event["type"] == Web.REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE: - Alert(self.common, strings._('error_cannot_create_downloads_dir').format(self.common.settings.get('downloads_dir'))) - - if event["type"] == Web.REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE: - Alert(self.common, strings._('error_downloads_dir_not_writable').format(self.common.settings.get('downloads_dir'))) + Alert(self.common, strings._('error_cannot_create_downloads_dir').format(event["data"]["receive_mode_dir"])) if event["type"] == Web.REQUEST_OTHER: if event["path"] != '/favicon.ico' and event["path"] != "/{}/shutdown".format(mode.web.shutdown_slug): diff --git a/share/locale/en.json b/share/locale/en.json index db416c9b..d57ef3f3 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -155,7 +155,6 @@ "info_in_progress_uploads_tooltip": "{} upload(s) in progress", "info_completed_uploads_tooltip": "{} upload(s) completed", "error_cannot_create_downloads_dir": "Could not create receive mode folder: {}", - "error_downloads_dir_not_writable": "The receive mode folder is write protected: {}", "receive_mode_downloads_dir": "Files sent to you appear in this folder: {}", "receive_mode_warning": "Warning: Receive mode lets people upload files to your computer. Some files can potentially take control of your computer if you open them. Only open things from people you trust, or if you know what you are doing.", "gui_receive_mode_warning": "Receive mode lets people upload files to your computer.

Some files can potentially take control of your computer if you open them. Only open things from people you trust, or if you know what you are doing.", From 0bab7be4444936d4d025cc2cdafa24cacd50137e Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 25 Oct 2018 21:38:20 -0700 Subject: [PATCH 70/72] Communicate the receive mode dir to the GUI, so clicking the open folder button opens the file manager to the correct directory --- onionshare/web/receive_mode.py | 7 +++++++ onionshare/web/web.py | 5 +++-- onionshare_gui/mode/__init__.py | 6 ++++++ onionshare_gui/mode/history.py | 13 ++++++++++++- onionshare_gui/mode/receive_mode/__init__.py | 10 ++++++++++ onionshare_gui/onionshare_gui.py | 3 +++ onionshare_gui/receive_mode/uploads.py | 12 +++++++++++- 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py index 66e00240..edaf8bbc 100644 --- a/onionshare/web/receive_mode.py +++ b/onionshare/web/receive_mode.py @@ -125,6 +125,13 @@ class ReceiveModeWeb(object): 'new_filename': basename }) + # Tell the GUI the receive mode directory for this file + self.web.add_request(self.web.REQUEST_UPLOAD_SET_DIR, request.path, { + 'id': request.upload_id, + 'filename': basename, + 'dir': receive_mode_dir + }) + self.common.log('ReceiveModeWeb', 'define_routes', '/upload, uploaded {}, saving to {}'.format(f.filename, local_path)) print(strings._('receive_mode_received_file').format(local_path)) f.save(local_path) diff --git a/onionshare/web/web.py b/onionshare/web/web.py index 2ae011b7..a423b2e1 100644 --- a/onionshare/web/web.py +++ b/onionshare/web/web.py @@ -37,8 +37,9 @@ class Web(object): REQUEST_RATE_LIMIT = 5 REQUEST_CLOSE_SERVER = 6 REQUEST_UPLOAD_FILE_RENAMED = 7 - REQUEST_UPLOAD_FINISHED = 8 - REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 9 + REQUEST_UPLOAD_SET_DIR = 8 + REQUEST_UPLOAD_FINISHED = 9 + REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 10 def __init__(self, common, is_gui, mode='share'): self.common = common diff --git a/onionshare_gui/mode/__init__.py b/onionshare_gui/mode/__init__.py index 0971ff32..5110289f 100644 --- a/onionshare_gui/mode/__init__.py +++ b/onionshare_gui/mode/__init__.py @@ -324,6 +324,12 @@ class Mode(QtWidgets.QWidget): """ pass + def handle_request_upload_set_dir(self, event): + """ + Handle REQUEST_UPLOAD_SET_DIR event. + """ + pass + def handle_request_upload_finished(self, event): """ Handle REQUEST_UPLOAD_FINISHED event. diff --git a/onionshare_gui/mode/history.py b/onionshare_gui/mode/history.py index b446b9fb..38e0fed3 100644 --- a/onionshare_gui/mode/history.py +++ b/onionshare_gui/mode/history.py @@ -118,6 +118,7 @@ class UploadHistoryItemFile(QtWidgets.QWidget): self.common.log('UploadHistoryItemFile', '__init__', 'filename: {}'.format(filename)) self.filename = filename + self.dir = None self.started = datetime.now() # Filename label @@ -158,13 +159,20 @@ class UploadHistoryItemFile(QtWidgets.QWidget): self.filename = new_filename self.filename_label.setText(self.filename) + def set_dir(self, dir): + self.dir = dir + def open_folder(self): """ Open the downloads folder, with the file selected, in a cross-platform manner """ self.common.log('UploadHistoryItemFile', 'open_folder') - abs_filename = os.path.join(self.common.settings.get('downloads_dir'), self.filename) + if not self.dir: + self.common.log('UploadHistoryItemFile', 'open_folder', "dir has not been set yet, can't open folder") + return + + abs_filename = os.path.join(self.dir, self.filename) # Linux if self.common.platform == 'Linux' or self.common.platform == 'BSD': @@ -266,6 +274,9 @@ class UploadHistoryItem(HistoryItem): self.files[data['old_filename']].rename(data['new_filename']) self.files[data['new_filename']] = self.files.pop(data['old_filename']) + elif data['action'] == 'set_dir': + self.files[data['filename']].set_dir(data['dir']) + elif data['action'] == 'finished': # Hide the progress bar self.progress_bar.hide() diff --git a/onionshare_gui/mode/receive_mode/__init__.py b/onionshare_gui/mode/receive_mode/__init__.py index f070f963..d6c0c351 100644 --- a/onionshare_gui/mode/receive_mode/__init__.py +++ b/onionshare_gui/mode/receive_mode/__init__.py @@ -168,6 +168,16 @@ class ReceiveMode(Mode): 'new_filename': event["data"]["new_filename"] }) + def handle_request_upload_set_dir(self, event): + """ + Handle REQUEST_UPLOAD_SET_DIR event. + """ + self.history.update(event["data"]["id"], { + 'action': 'set_dir', + 'filename': event["data"]["filename"], + 'dir': event["data"]["dir"] + }) + def handle_request_upload_finished(self, event): """ Handle REQUEST_UPLOAD_FINISHED event. diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 1e254f61..eab3261e 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -390,6 +390,9 @@ class OnionShareGui(QtWidgets.QMainWindow): elif event["type"] == Web.REQUEST_UPLOAD_FILE_RENAMED: mode.handle_request_upload_file_renamed(event) + elif event["type"] == Web.REQUEST_UPLOAD_SET_DIR: + mode.handle_request_upload_set_dir(event) + elif event["type"] == Web.REQUEST_UPLOAD_FINISHED: mode.handle_request_upload_finished(event) diff --git a/onionshare_gui/receive_mode/uploads.py b/onionshare_gui/receive_mode/uploads.py index 33d993b3..68c94b1c 100644 --- a/onionshare_gui/receive_mode/uploads.py +++ b/onionshare_gui/receive_mode/uploads.py @@ -35,6 +35,7 @@ class File(QtWidgets.QWidget): self.common.log('File', '__init__', 'filename: {}'.format(filename)) self.filename = filename + self.dir = None self.started = datetime.now() # Filename label @@ -71,6 +72,9 @@ class File(QtWidgets.QWidget): if complete: self.folder_button.show() + def set_dir(self, dir): + self.dir = dir + def rename(self, new_filename): self.filename = new_filename self.filename_label.setText(self.filename) @@ -81,7 +85,10 @@ class File(QtWidgets.QWidget): """ self.common.log('File', 'open_folder') - abs_filename = os.path.join(self.common.settings.get('downloads_dir'), self.filename) + if not self.dir: + return + + abs_filename = os.path.join(self.dir, self.filename) # Linux if self.common.platform == 'Linux' or self.common.platform == 'BSD': @@ -182,6 +189,9 @@ class Upload(QtWidgets.QWidget): self.files[old_filename].rename(new_filename) self.files[new_filename] = self.files.pop(old_filename) + def set_dir(self, filename, dir): + self.files[filename].set_dir(dir) + def finished(self): # Hide the progress bar self.progress_bar.hide() From a8dae82ac3d903d1d23dc4c3109c88b816513ab6 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Fri, 26 Oct 2018 15:08:55 -0700 Subject: [PATCH 71/72] Fix tests so they recognize the new receive mode location --- onionshare/web/receive_mode.py | 2 +- tests/GuiReceiveTest.py | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/onionshare/web/receive_mode.py b/onionshare/web/receive_mode.py index edaf8bbc..3149029f 100644 --- a/onionshare/web/receive_mode.py +++ b/onionshare/web/receive_mode.py @@ -61,7 +61,7 @@ class ReceiveModeWeb(object): # Make sure the receive mode dir exists now = datetime.now() date_dir = now.strftime("%Y-%m-%d") - time_dir = now.strftime("%H.%M:%S") + time_dir = now.strftime("%H.%M.%S") receive_mode_dir = os.path.join(self.common.settings.get('downloads_dir'), date_dir, time_dir) valid = True try: diff --git a/tests/GuiReceiveTest.py b/tests/GuiReceiveTest.py index a659a79f..eaed8343 100644 --- a/tests/GuiReceiveTest.py +++ b/tests/GuiReceiveTest.py @@ -1,10 +1,11 @@ import os import requests +from datetime import datetime, timedelta from PyQt5 import QtCore, QtTest from .GuiBaseTest import GuiBaseTest class GuiReceiveTest(GuiBaseTest): - def upload_file(self, public_mode, file_to_upload, expected_file): + def upload_file(self, public_mode, file_to_upload, expected_basename): '''Test that we can upload the file''' files = {'file[]': open(file_to_upload, 'rb')} if not public_mode: @@ -13,9 +14,23 @@ class GuiReceiveTest(GuiBaseTest): path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port) response = requests.post(path, files=files) QtTest.QTest.qWait(2000) - self.assertTrue(os.path.isfile(expected_file)) - def upload_file_should_fail(self, public_mode, expected_file): + # Make sure the file is within the last 10 seconds worth of filenames + exists = False + now = datetime.now() + for i in range(10): + date_dir = now.strftime("%Y-%m-%d") + time_dir = now.strftime("%H.%M.%S") + receive_mode_dir = os.path.join(self.gui.common.settings.get('downloads_dir'), date_dir, time_dir) + expected_filename = os.path.join(receive_mode_dir, expected_basename) + if os.path.exists(expected_filename): + exists = True + break + now = now - timedelta(seconds=1) + + self.assertTrue(exists) + + def upload_file_should_fail(self, public_mode): '''Test that we can't upload the file when permissions are wrong, and expected content is shown''' files = {'file[]': open('/tmp/test.txt', 'rb')} if not public_mode: @@ -73,14 +88,14 @@ class GuiReceiveTest(GuiBaseTest): self.run_all_receive_mode_setup_tests(public_mode) if not public_mode: self.try_public_paths_in_non_public_mode() - self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test.txt') + self.upload_file(public_mode, '/tmp/test.txt', 'test.txt') self.history_widgets_present(self.gui.receive_mode) self.counter_incremented(self.gui.receive_mode, 1) - self.upload_file(public_mode, '/tmp/test.txt', '/tmp/OnionShare/test-2.txt') + self.upload_file(public_mode, '/tmp/test.txt', 'test.txt') self.counter_incremented(self.gui.receive_mode, 2) - self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test') + self.upload_file(public_mode, '/tmp/testdir/test', 'test') self.counter_incremented(self.gui.receive_mode, 3) - self.upload_file(public_mode, '/tmp/testdir/test', '/tmp/OnionShare/test-2') + self.upload_file(public_mode, '/tmp/testdir/test', 'test') self.counter_incremented(self.gui.receive_mode, 4) self.history_indicator(self.gui.receive_mode, public_mode) self.server_is_stopped(self.gui.receive_mode, False) @@ -94,7 +109,7 @@ class GuiReceiveTest(GuiBaseTest): '''Attempt to upload (unwritable) files in receive mode and stop the share''' self.run_all_receive_mode_setup_tests(public_mode) self.upload_dir_permissions(0o400) - self.upload_file_should_fail(public_mode, '/tmp/OnionShare/test.txt') + self.upload_file_should_fail(public_mode) self.server_is_stopped(self.gui.receive_mode, True) self.web_server_is_stopped() self.server_status_indicator_says_closed(self.gui.receive_mode, False) From 05aeaf02cb6c076008b37016edc6f7937b467352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allan=20Nordh=C3=B8y?= Date: Mon, 12 Nov 2018 01:35:18 +0100 Subject: [PATCH 72/72] Spelling: Recipient --- share/locale/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/locale/en.json b/share/locale/en.json index d57ef3f3..b02e522f 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -62,7 +62,7 @@ "gui_receive_quit_warning": "You're in the process of receiving files. Are you sure you want to quit OnionShare?", "gui_quit_warning_quit": "Quit", "gui_quit_warning_dont_quit": "Cancel", - "error_rate_limit": "Someone has made too many wrong attempts on your address, which means they could be trying to guess it, so OnionShare has stopped the server. Start sharing again and send the receipient a new address to share.", + "error_rate_limit": "Someone has made too many wrong attempts on your address, which means they could be trying to guess it, so OnionShare has stopped the server. Start sharing again and send the recipient a new address to share.", "zip_progress_bar_format": "Compressing: %p%", "error_stealth_not_supported": "To use client authorization, you need at least both Tor 0.2.9.1-alpha (or Tor Browser 6.5) and python3-stem 1.5.0.", "error_ephemeral_not_supported": "OnionShare requires at least both Tor 0.2.7.1 and python3-stem 1.4.0.",