From 966ade5dda3dfc33a46e1862c87b9162a8210fb0 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Sat, 13 Oct 2018 09:49:05 +1100 Subject: [PATCH] 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()