Pass --local-only down to the ServerStatus and Mode so that we can set shorter timeouts for local GUI tests. Update the tests to use a very short timeout

This commit is contained in:
Miguel Jacq 2018-09-27 15:43:59 +10:00
parent 2a7adb2365
commit 201f351279
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
5 changed files with 29 additions and 16 deletions

View File

@ -37,7 +37,7 @@ class Mode(QtWidgets.QWidget):
starting_server_error = QtCore.pyqtSignal(str)
set_server_active = QtCore.pyqtSignal(bool)
def __init__(self, common, qtapp, app, status_bar, server_status_label, system_tray, filenames=None):
def __init__(self, common, qtapp, app, status_bar, server_status_label, system_tray, filenames=None, local_only=False):
super(Mode, self).__init__()
self.common = common
self.qtapp = qtapp
@ -54,12 +54,15 @@ class Mode(QtWidgets.QWidget):
# The web object gets created in init()
self.web = None
# Local mode is passed from OnionShareGui
self.local_only = local_only
# Threads start out as None
self.onion_thread = None
self.web_thread = None
# Server status
self.server_status = ServerStatus(self.common, self.qtapp, self.app)
self.server_status = ServerStatus(self.common, self.qtapp, self.app, None, self.local_only)
self.server_status.server_started.connect(self.start_server)
self.server_status.server_stopped.connect(self.stop_server)
self.server_status.server_canceled.connect(self.cancel_server)

View File

@ -121,7 +121,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.setStatusBar(self.status_bar)
# Share mode
self.share_mode = ShareMode(self.common, qtapp, app, self.status_bar, self.server_status_label, self.system_tray, filenames)
self.share_mode = ShareMode(self.common, qtapp, app, self.status_bar, self.server_status_label, self.system_tray, filenames, self.local_only)
self.share_mode.init()
self.share_mode.server_status.server_started.connect(self.update_server_status_indicator)
self.share_mode.server_status.server_stopped.connect(self.update_server_status_indicator)
@ -135,7 +135,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.share_mode.set_server_active.connect(self.set_server_active)
# Receive mode
self.receive_mode = ReceiveMode(self.common, qtapp, app, self.status_bar, self.server_status_label, self.system_tray)
self.receive_mode = ReceiveMode(self.common, qtapp, app, self.status_bar, self.server_status_label, self.system_tray, None, self.local_only)
self.receive_mode.init()
self.receive_mode.server_status.server_started.connect(self.update_server_status_indicator)
self.receive_mode.server_status.server_stopped.connect(self.update_server_status_indicator)

View File

@ -44,7 +44,7 @@ class ServerStatus(QtWidgets.QWidget):
STATUS_WORKING = 1
STATUS_STARTED = 2
def __init__(self, common, qtapp, app, file_selection=None):
def __init__(self, common, qtapp, app, file_selection=None, local_only=False):
super(ServerStatus, self).__init__()
self.common = common
@ -56,17 +56,23 @@ class ServerStatus(QtWidgets.QWidget):
self.app = app
self.web = None
self.local_only = local_only
self.resizeEvent(None)
# Shutdown timeout layout
self.shutdown_timeout_label = QtWidgets.QLabel(strings._('gui_settings_shutdown_timeout', True))
self.shutdown_timeout = QtWidgets.QDateTimeEdit()
# Set proposed timeout to be 5 minutes into the future
self.shutdown_timeout.setDisplayFormat("hh:mm A MMM d, yy")
if self.local_only:
# For testing
self.shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(15))
self.shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime())
else:
# Set proposed timeout to be 5 minutes into the future
self.shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
# Onion services can take a little while to start, so reduce the risk of it expiring too soon by setting the minimum to 2 min from now
self.shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(120))
# Onion services can take a little while to start, so reduce the risk of it expiring too soon by setting the minimum to 60s from now
self.shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
self.shutdown_timeout.setCurrentSection(QtWidgets.QDateTimeEdit.MinuteSection)
shutdown_timeout_layout = QtWidgets.QHBoxLayout()
shutdown_timeout_layout.addWidget(self.shutdown_timeout_label)
@ -154,7 +160,8 @@ class ServerStatus(QtWidgets.QWidget):
Reset the timeout in the UI after stopping a share
"""
self.shutdown_timeout.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
self.shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(120))
if not self.local_only:
self.shutdown_timeout.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
def update(self):
"""
@ -255,6 +262,9 @@ class ServerStatus(QtWidgets.QWidget):
"""
if self.status == self.STATUS_STOPPED:
if self.common.settings.get('shutdown_timeout'):
if self.local_only:
self.timeout = self.shutdown_timeout.dateTime().toPyDateTime()
else:
# Get the timeout chosen, stripped of its seconds. This prevents confusion if the share stops at (say) 37 seconds past the minute chosen
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.

View File

@ -203,9 +203,9 @@ class CommonTests(object):
self.assertEquals(self.gui.share_mode.server_status_label.text(), strings._('closing_automatically', True))
# Auto-stop timer tests
def test_set_timeout(self, mode):
def test_set_timeout(self, mode, timeout):
'''Test that the timeout can be set'''
timer = QtCore.QDateTime.currentDateTime().addSecs(120)
timer = QtCore.QDateTime.currentDateTime().addSecs(timeout)
if mode == 'receive':
self.gui.receive_mode.server_status.shutdown_timeout.setDateTime(timer)
self.assertTrue(self.gui.receive_mode.server_status.shutdown_timeout.dateTime(), timer)

View File

@ -108,7 +108,7 @@ class OnionShareGuiTest(unittest.TestCase):
@pytest.mark.run(order=8)
def test_set_timeout(self):
CommonTests.test_set_timeout(self, 'share')
CommonTests.test_set_timeout(self, 'share', 5)
@pytest.mark.run(order=9)
def test_server_working_on_start_button_pressed(self):
@ -132,7 +132,7 @@ class OnionShareGuiTest(unittest.TestCase):
@pytest.mark.run(order=14)
def test_timeout(self):
CommonTests.test_server_timed_out(self, 'share', 120000)
CommonTests.test_server_timed_out(self, 'share', 10000)
@pytest.mark.run(order=15)
def test_web_service_is_stopped(self):