From dc0fe4f7b13f980857bde7d79fadc82b7fd7567c Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 8 Mar 2019 11:03:37 +1100 Subject: [PATCH] Fix a minor corner case related to server status button when canceling a scheduled share. Leverage scheduled shares in order to test 'cancel' action in local mode for better test coverage --- onionshare_gui/threads.py | 4 +-- tests/GuiBaseTest.py | 14 ++++++++++ tests/TorGuiBaseTest.py | 13 ---------- ...onionshare_share_mode_cancel_share_test.py | 26 +++++++++++++++++++ ...onionshare_share_mode_cancel_share_test.py | 1 + 5 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 tests/local_onionshare_share_mode_cancel_share_test.py diff --git a/onionshare_gui/threads.py b/onionshare_gui/threads.py index fff56bc2..dda8094e 100644 --- a/onionshare_gui/threads.py +++ b/onionshare_gui/threads.py @@ -115,9 +115,9 @@ class StartupTimer(QtCore.QThread): now = QtCore.QDateTime.currentDateTime() scheduled_start = now.secsTo(self.mode.server_status.scheduled_start) # Timer has now finished - self.mode.server_status.server_button.setText(strings._('gui_please_wait')) - self.mode.server_status_label.setText(strings._('gui_status_indicator_share_working')) if self.canceled == False: + self.mode.server_status.server_button.setText(strings._('gui_please_wait')) + self.mode.server_status_label.setText(strings._('gui_status_indicator_share_working')) self.success.emit() except ValueError as e: self.error.emit(e.args[0]) diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py index 98b6c738..9ff0477f 100644 --- a/tests/GuiBaseTest.py +++ b/tests/GuiBaseTest.py @@ -325,6 +325,20 @@ class GuiBaseTest(object): # We should have started now self.assertEqual(mode.server_status.status, 2) + def cancel_the_share(self, mode): + '''Test that we can cancel a share before it's started up ''' + self.server_working_on_start_button_pressed(mode) + self.server_status_indicator_says_scheduled(mode) + self.add_delete_buttons_hidden() + self.settings_button_is_hidden() + self.set_startup_timer(mode, 10) + QtTest.QTest.mousePress(mode.server_status.server_button, QtCore.Qt.LeftButton) + QtTest.QTest.qWait(2000) + QtTest.QTest.mouseRelease(mode.server_status.server_button, QtCore.Qt.LeftButton) + self.assertEqual(mode.server_status.status, 0) + self.server_is_stopped(mode, False) + self.web_server_is_stopped() + # Hack to close an Alert dialog that would otherwise block tests def accept_dialog(self): window = self.gui.qtapp.activeWindow() diff --git a/tests/TorGuiBaseTest.py b/tests/TorGuiBaseTest.py index e437ac93..8bd963bd 100644 --- a/tests/TorGuiBaseTest.py +++ b/tests/TorGuiBaseTest.py @@ -140,19 +140,6 @@ class TorGuiBaseTest(GuiBaseTest): 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) - 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(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_server_is_stopped() - # Stealth tests def copy_have_hidserv_auth_button(self, mode): diff --git a/tests/local_onionshare_share_mode_cancel_share_test.py b/tests/local_onionshare_share_mode_cancel_share_test.py new file mode 100644 index 00000000..24408730 --- /dev/null +++ b/tests/local_onionshare_share_mode_cancel_share_test.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import pytest +import unittest + +from .GuiShareTest import GuiShareTest + +class LocalShareModeCancelTest(unittest.TestCase, GuiShareTest): + @classmethod + def setUpClass(cls): + test_settings = { + "startup_timer": True, + } + cls.gui = GuiShareTest.set_up(test_settings) + + @classmethod + def tearDownClass(cls): + GuiShareTest.tear_down() + + @pytest.mark.gui + def test_gui(self): + self.run_all_common_setup_tests() + self.run_all_share_mode_setup_tests() + self.cancel_the_share(self.gui.share_mode) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/onionshare_share_mode_cancel_share_test.py b/tests/onionshare_share_mode_cancel_share_test.py index ed28ddd7..ed087a2c 100644 --- a/tests/onionshare_share_mode_cancel_share_test.py +++ b/tests/onionshare_share_mode_cancel_share_test.py @@ -8,6 +8,7 @@ class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest): @classmethod def setUpClass(cls): test_settings = { + "startup_timer": True, } cls.gui = TorGuiShareTest.set_up(test_settings)