summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2019-03-05 10:28:27 +1100
committerMiguel Jacq <mig@mig5.net>2019-03-05 10:28:27 +1100
commit31c360b44d411fc9507eeb5815728a26af6781cf (patch)
tree5ecc6d80b80989fdbd064611d7b5bfd9742f359a /tests
parent3af05dcc2041026380a71b8aed1af9af849416a5 (diff)
downloadonionshare-31c360b44d411fc9507eeb5815728a26af6781cf.tar.gz
onionshare-31c360b44d411fc9507eeb5815728a26af6781cf.zip
Add a Startup Timer feature (scheduled start / dead man's switch)
Diffstat (limited to 'tests')
-rw-r--r--tests/GuiBaseTest.py21
-rw-r--r--tests/GuiShareTest.py9
-rw-r--r--tests/local_onionshare_share_mode_startup_timer_test.py26
-rw-r--r--tests/test_onionshare.py3
-rw-r--r--tests/test_onionshare_settings.py1
5 files changed, 58 insertions, 2 deletions
diff --git a/tests/GuiBaseTest.py b/tests/GuiBaseTest.py
index e4b3d4c9..98b6c738 100644
--- a/tests/GuiBaseTest.py
+++ b/tests/GuiBaseTest.py
@@ -172,6 +172,9 @@ class GuiBaseTest(object):
'''Test that the Server Status indicator shows we are Starting'''
self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_working'))
+ def server_status_indicator_says_scheduled(self, mode):
+ '''Test that the Server Status indicator shows we are Scheduled'''
+ self.assertEqual(mode.server_status_label.text(), strings._('gui_status_indicator_share_scheduled'))
def server_is_started(self, mode, startup_time=2000):
'''Test that the server has started'''
@@ -294,7 +297,6 @@ class GuiBaseTest(object):
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())
@@ -306,6 +308,23 @@ class GuiBaseTest(object):
# We should have timed out now
self.assertEqual(mode.server_status.status, 0)
+ # Startup timer tests
+ def set_startup_timer(self, mode, timer):
+ '''Test that the timer can be set'''
+ schedule = QtCore.QDateTime.currentDateTime().addSecs(timer)
+ mode.server_status.startup_timer.setDateTime(schedule)
+ self.assertTrue(mode.server_status.startup_timer.dateTime(), schedule)
+
+ def startup_timer_widget_hidden(self, mode):
+ '''Test that the startup timer widget is hidden when share has started'''
+ self.assertFalse(mode.server_status.startup_timer_container.isVisible())
+
+ def scheduled_service_started(self, mode, wait):
+ '''Test that the server has timed out after the timer ran out'''
+ QtTest.QTest.qWait(wait)
+ # We should have started now
+ self.assertEqual(mode.server_status.status, 2)
+
# Hack to close an Alert dialog that would otherwise block tests
def accept_dialog(self):
window = self.gui.qtapp.activeWindow()
diff --git a/tests/GuiShareTest.py b/tests/GuiShareTest.py
index 716bab73..e37cd7ee 100644
--- a/tests/GuiShareTest.py
+++ b/tests/GuiShareTest.py
@@ -195,6 +195,15 @@ class GuiShareTest(GuiBaseTest):
self.server_timed_out(self.gui.share_mode, 10000)
self.web_server_is_stopped()
+ def run_all_share_mode_startup_timer_tests(self, public_mode):
+ """Auto-stop timer tests in share mode"""
+ self.run_all_share_mode_setup_tests()
+ self.set_startup_timer(self.gui.share_mode, 5)
+ self.server_working_on_start_button_pressed(self.gui.share_mode)
+ self.startup_timer_widget_hidden(self.gui.share_mode)
+ self.server_status_indicator_says_scheduled(self.gui.share_mode)
+ self.scheduled_service_started(self.gui.share_mode, 7000)
+ self.web_server_is_running()
def run_all_share_mode_unreadable_file_tests(self):
'''Attempt to share an unreadable file'''
diff --git a/tests/local_onionshare_share_mode_startup_timer_test.py b/tests/local_onionshare_share_mode_startup_timer_test.py
new file mode 100644
index 00000000..b5e08b10
--- /dev/null
+++ b/tests/local_onionshare_share_mode_startup_timer_test.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+import pytest
+import unittest
+
+from .GuiShareTest import GuiShareTest
+
+class LocalShareModeStartupTimerTest(unittest.TestCase, GuiShareTest):
+ @classmethod
+ def setUpClass(cls):
+ test_settings = {
+ "public_mode": False,
+ "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_startup_timer_tests(False)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/test_onionshare.py b/tests/test_onionshare.py
index 7592a777..f141fed7 100644
--- a/tests/test_onionshare.py
+++ b/tests/test_onionshare.py
@@ -30,9 +30,10 @@ class MyOnion:
self.auth_string = 'TestHidServAuth'
self.private_key = ''
self.stealth = stealth
+ self.scheduled_key = None
@staticmethod
- def start_onion_service(_):
+ def start_onion_service(self, await_publication=True, save_scheduled_key=False):
return 'test_service_id.onion'
diff --git a/tests/test_onionshare_settings.py b/tests/test_onionshare_settings.py
index f4be2930..74ab4f8f 100644
--- a/tests/test_onionshare_settings.py
+++ b/tests/test_onionshare_settings.py
@@ -52,6 +52,7 @@ class TestSettings:
'auth_password': '',
'close_after_first_download': True,
'shutdown_timeout': False,
+ 'startup_timer': False,
'use_stealth': False,
'use_autoupdate': True,
'autoupdate_timestamp': None,