2018-10-11 20:28:47 -04:00
|
|
|
import json
|
2018-09-23 20:41:48 -04:00
|
|
|
import os
|
|
|
|
import requests
|
2018-10-11 20:28:47 -04:00
|
|
|
import shutil
|
2019-05-24 16:38:41 -04:00
|
|
|
import base64
|
2018-09-23 20:41:48 -04:00
|
|
|
|
|
|
|
from PyQt5 import QtCore, QtTest
|
2018-09-30 21:19:25 -04:00
|
|
|
|
2018-09-23 20:41:48 -04:00
|
|
|
from onionshare import strings
|
2018-09-30 21:19:25 -04:00
|
|
|
from onionshare.common import Common
|
|
|
|
from onionshare.settings import Settings
|
|
|
|
from onionshare.onion import Onion
|
|
|
|
from onionshare.web import Web
|
2019-10-20 22:41:20 -04:00
|
|
|
from onionshare_gui import Application, OnionShare, MainWindow
|
2018-10-10 21:45:55 -04:00
|
|
|
from onionshare_gui.mode.share_mode import ShareMode
|
|
|
|
from onionshare_gui.mode.receive_mode import ReceiveMode
|
2019-09-02 21:51:59 -04:00
|
|
|
from onionshare_gui.mode.website_mode import WebsiteMode
|
2018-09-30 21:19:25 -04:00
|
|
|
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-11 00:09:27 -04:00
|
|
|
class GuiBaseTest(object):
|
2018-09-30 21:19:25 -04:00
|
|
|
@staticmethod
|
2018-10-17 01:31:51 -04:00
|
|
|
def set_up(test_settings):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Create GUI with given settings"""
|
2018-09-30 21:19:25 -04:00
|
|
|
# Create our test file
|
2019-10-13 00:01:25 -04:00
|
|
|
testfile = open("/tmp/test.txt", "w")
|
|
|
|
testfile.write("onionshare")
|
2018-09-30 21:19:25 -04:00
|
|
|
testfile.close()
|
|
|
|
|
2018-10-15 22:01:44 -04:00
|
|
|
# Create a test dir and files
|
2019-10-13 00:01:25 -04:00
|
|
|
if not os.path.exists("/tmp/testdir"):
|
|
|
|
testdir = os.mkdir("/tmp/testdir")
|
|
|
|
testfile = open("/tmp/testdir/test", "w")
|
|
|
|
testfile.write("onionshare")
|
2018-10-15 22:01:44 -04:00
|
|
|
testfile.close()
|
|
|
|
|
2018-09-30 21:19:25 -04:00
|
|
|
common = Common()
|
|
|
|
common.settings = Settings(common)
|
|
|
|
common.define_css()
|
|
|
|
strings.load_strings(common)
|
|
|
|
|
|
|
|
# Get all of the settings in test_settings
|
2019-10-13 00:01:25 -04:00
|
|
|
test_settings["data_dir"] = "/tmp/OnionShare"
|
2018-09-30 21:19:25 -04:00
|
|
|
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, True, 0)
|
|
|
|
|
|
|
|
web = Web(common, False, True)
|
2019-10-13 00:01:25 -04:00
|
|
|
open("/tmp/settings.json", "w").write(json.dumps(test_settings))
|
|
|
|
|
2019-10-20 22:41:20 -04:00
|
|
|
gui = MainWindow(
|
2019-10-13 00:01:25 -04:00
|
|
|
common,
|
|
|
|
testonion,
|
|
|
|
qtapp,
|
|
|
|
app,
|
|
|
|
["/tmp/test.txt", "/tmp/testdir"],
|
|
|
|
"/tmp/settings.json",
|
|
|
|
True,
|
|
|
|
)
|
2018-09-30 21:19:25 -04:00
|
|
|
return gui
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def tear_down():
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Clean up after tests"""
|
2018-09-30 21:19:25 -04:00
|
|
|
try:
|
2019-10-13 00:01:25 -04:00
|
|
|
os.remove("/tmp/test.txt")
|
|
|
|
os.remove("/tmp/settings.json")
|
|
|
|
os.remove("/tmp/large_file")
|
|
|
|
os.remove("/tmp/download.zip")
|
|
|
|
os.remove("/tmp/webpage")
|
|
|
|
shutil.rmtree("/tmp/testdir")
|
|
|
|
shutil.rmtree("/tmp/OnionShare")
|
2018-09-30 21:19:25 -04:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def gui_loaded(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the GUI actually is shown"""
|
2018-09-23 20:41:48 -04:00
|
|
|
self.assertTrue(self.gui.show)
|
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def windowTitle_seen(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the window title is OnionShare"""
|
|
|
|
self.assertEqual(self.gui.windowTitle(), "OnionShare")
|
2019-01-20 15:01:51 -05:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def settings_button_is_visible(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the settings button is visible"""
|
2018-09-23 20:41:48 -04:00
|
|
|
self.assertTrue(self.gui.settings_button.isVisible())
|
|
|
|
|
2018-10-15 22:01:44 -04:00
|
|
|
def settings_button_is_hidden(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the settings button is hidden when the server starts"""
|
2018-10-15 22:01:44 -04:00
|
|
|
self.assertFalse(self.gui.settings_button.isVisible())
|
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def server_status_bar_is_visible(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the status bar is visible"""
|
2018-09-23 20:41:48 -04:00
|
|
|
self.assertTrue(self.gui.status_bar.isVisible())
|
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def click_mode(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that we can switch Mode by clicking the button"""
|
2018-10-07 21:49:09 -04:00
|
|
|
if type(mode) == ReceiveMode:
|
2018-09-23 20:41:48 -04:00
|
|
|
QtTest.QTest.mouseClick(self.gui.receive_mode_button, QtCore.Qt.LeftButton)
|
|
|
|
self.assertTrue(self.gui.mode, self.gui.MODE_RECEIVE)
|
2018-10-07 21:49:09 -04:00
|
|
|
if type(mode) == ShareMode:
|
2018-09-23 20:41:48 -04:00
|
|
|
QtTest.QTest.mouseClick(self.gui.share_mode_button, QtCore.Qt.LeftButton)
|
|
|
|
self.assertTrue(self.gui.mode, self.gui.MODE_SHARE)
|
2019-09-02 21:51:59 -04:00
|
|
|
if type(mode) == WebsiteMode:
|
|
|
|
QtTest.QTest.mouseClick(self.gui.website_mode_button, QtCore.Qt.LeftButton)
|
|
|
|
self.assertTrue(self.gui.mode, self.gui.MODE_WEBSITE)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def click_toggle_history(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that we can toggle Download or Upload history by clicking the toggle button"""
|
2018-10-07 21:49:09 -04:00
|
|
|
currently_visible = mode.history.isVisible()
|
|
|
|
QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton)
|
|
|
|
self.assertEqual(mode.history.isVisible(), not currently_visible)
|
2018-09-29 21:24:11 -04:00
|
|
|
|
2019-09-08 22:19:39 -04:00
|
|
|
def history_indicator(self, mode, public_mode, indicator_count="1"):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that we can make sure the history is toggled off, do an action, and the indiciator works"""
|
2018-10-07 21:49:09 -04:00
|
|
|
# Make sure history is toggled off
|
|
|
|
if mode.history.isVisible():
|
|
|
|
QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton)
|
|
|
|
self.assertFalse(mode.history.isVisible())
|
2018-09-30 14:41:07 -04:00
|
|
|
|
2018-10-07 21:49:09 -04:00
|
|
|
# Indicator should not be visible yet
|
|
|
|
self.assertFalse(mode.toggle_history.indicator_label.isVisible())
|
2018-09-30 14:41:07 -04:00
|
|
|
|
2018-10-07 21:49:09 -04:00
|
|
|
if type(mode) == ReceiveMode:
|
2018-09-30 14:41:07 -04:00
|
|
|
# Upload a file
|
2019-10-13 00:01:25 -04:00
|
|
|
files = {"file[]": open("/tmp/test.txt", "rb")}
|
2019-10-20 13:46:14 -04:00
|
|
|
url = f"http://127.0.0.1:{self.gui.app.port}/upload"
|
2019-05-24 16:38:41 -04:00
|
|
|
if public_mode:
|
2019-05-24 20:59:04 -04:00
|
|
|
r = requests.post(url, files=files)
|
2018-09-30 14:41:07 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
r = requests.post(
|
|
|
|
url,
|
|
|
|
files=files,
|
|
|
|
auth=requests.auth.HTTPBasicAuth("onionshare", mode.web.password),
|
|
|
|
)
|
2018-09-30 14:41:07 -04:00
|
|
|
QtTest.QTest.qWait(2000)
|
|
|
|
|
2018-10-07 21:49:09 -04:00
|
|
|
if type(mode) == ShareMode:
|
2018-09-30 14:41:07 -04:00
|
|
|
# Download files
|
2019-10-20 13:46:14 -04:00
|
|
|
url = f"http://127.0.0.1:{self.gui.app.port}/download"
|
2018-09-30 14:41:07 -04:00
|
|
|
if public_mode:
|
2019-05-24 16:38:41 -04:00
|
|
|
r = requests.get(url)
|
2018-09-30 14:41:07 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
r = requests.get(
|
|
|
|
url,
|
|
|
|
auth=requests.auth.HTTPBasicAuth("onionshare", mode.web.password),
|
|
|
|
)
|
2018-09-30 14:41:07 -04:00
|
|
|
QtTest.QTest.qWait(2000)
|
|
|
|
|
2018-10-07 21:49:09 -04:00
|
|
|
# Indicator should be visible, have a value of "1"
|
|
|
|
self.assertTrue(mode.toggle_history.indicator_label.isVisible())
|
2019-09-08 22:19:39 -04:00
|
|
|
self.assertEqual(mode.toggle_history.indicator_label.text(), indicator_count)
|
2018-09-30 14:41:07 -04:00
|
|
|
|
2018-10-07 21:49:09 -04:00
|
|
|
# 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())
|
2018-09-30 14:41:07 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def history_is_not_visible(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the History section is not visible"""
|
2018-10-07 21:49:09 -04:00
|
|
|
self.assertFalse(mode.history.isVisible())
|
2018-09-29 21:24:11 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def history_is_visible(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the History section is visible"""
|
2018-10-07 21:49:09 -04:00
|
|
|
self.assertTrue(mode.history.isVisible())
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def server_working_on_start_button_pressed(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test we can start the service"""
|
2018-09-23 20:41:48 -04:00
|
|
|
# Should be in SERVER_WORKING state
|
2018-10-07 21:49:09 -04:00
|
|
|
QtTest.QTest.mouseClick(mode.server_status.server_button, QtCore.Qt.LeftButton)
|
|
|
|
self.assertEqual(mode.server_status.status, 1)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2019-09-03 03:02:00 -04:00
|
|
|
def toggle_indicator_is_reset(self, mode):
|
|
|
|
self.assertEqual(mode.toggle_history.indicator_count, 0)
|
|
|
|
self.assertFalse(mode.toggle_history.indicator_label.isVisible())
|
2019-01-20 15:01:51 -05:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def server_status_indicator_says_starting(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the Server Status indicator shows we are Starting"""
|
|
|
|
self.assertEqual(
|
|
|
|
mode.server_status_label.text(),
|
|
|
|
strings._("gui_status_indicator_share_working"),
|
|
|
|
)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2019-03-04 18:28:27 -05:00
|
|
|
def server_status_indicator_says_scheduled(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the Server Status indicator shows we are Scheduled"""
|
|
|
|
self.assertEqual(
|
|
|
|
mode.server_status_label.text(),
|
|
|
|
strings._("gui_status_indicator_share_scheduled"),
|
|
|
|
)
|
2019-01-20 15:01:51 -05:00
|
|
|
|
2018-10-15 22:01:44 -04:00
|
|
|
def server_is_started(self, mode, startup_time=2000):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the server has started"""
|
2018-10-15 22:01:44 -04:00
|
|
|
QtTest.QTest.qWait(startup_time)
|
2018-09-23 20:41:48 -04:00
|
|
|
# Should now be in SERVER_STARTED state
|
2018-10-07 21:49:09 -04:00
|
|
|
self.assertEqual(mode.server_status.status, 2)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-15 22:01:44 -04:00
|
|
|
def web_server_is_running(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the web server has started"""
|
2019-05-24 20:59:04 -04:00
|
|
|
try:
|
2019-10-20 13:46:14 -04:00
|
|
|
r = requests.get(f"http://127.0.0.1:{self.gui.app.port}/")
|
2019-05-24 20:59:04 -04:00
|
|
|
self.assertTrue(True)
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
self.assertTrue(False)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2019-05-22 23:55:31 -04:00
|
|
|
def have_a_password(self, mode, public_mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that we have a valid password"""
|
2018-10-07 21:49:09 -04:00
|
|
|
if not public_mode:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.assertRegex(mode.server_status.web.password, r"(\w+)-(\w+)")
|
2018-10-07 21:49:09 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.assertIsNone(mode.server_status.web.password, r"(\w+)-(\w+)")
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2019-09-02 22:23:27 -04:00
|
|
|
def add_button_visible(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the add button should be visible"""
|
2019-09-02 22:23:27 -04:00
|
|
|
self.assertTrue(mode.server_status.file_selection.add_button.isVisible())
|
2019-01-20 15:01:51 -05:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def url_description_shown(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the URL label is showing"""
|
2018-10-07 21:49:09 -04:00
|
|
|
self.assertTrue(mode.server_status.url_description.isVisible())
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-15 22:01:44 -04:00
|
|
|
def have_copy_url_button(self, mode, public_mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the Copy URL button is shown and that the clipboard is correct"""
|
2018-10-07 21:49:09 -04:00
|
|
|
self.assertTrue(mode.server_status.copy_url_button.isVisible())
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
QtTest.QTest.mouseClick(
|
|
|
|
mode.server_status.copy_url_button, QtCore.Qt.LeftButton
|
|
|
|
)
|
2018-10-15 22:01:44 -04:00
|
|
|
clipboard = self.gui.qtapp.clipboard()
|
|
|
|
if public_mode:
|
2019-10-20 13:46:14 -04:00
|
|
|
self.assertEqual(clipboard.text(), f"http://127.0.0.1:{self.gui.app.port}")
|
2018-10-15 22:01:44 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.assertEqual(
|
|
|
|
clipboard.text(),
|
2019-10-20 13:46:14 -04:00
|
|
|
f"http://onionshare:{mode.server_status.web.password}@127.0.0.1:{self.gui.app.port}",
|
2019-10-13 00:01:25 -04:00
|
|
|
)
|
2019-01-20 15:01:51 -05:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def server_status_indicator_says_started(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the Server Status indicator shows we are started"""
|
2018-10-07 21:49:09 -04:00
|
|
|
if type(mode) == ReceiveMode:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.assertEqual(
|
|
|
|
mode.server_status_label.text(),
|
|
|
|
strings._("gui_status_indicator_receive_started"),
|
|
|
|
)
|
2018-10-07 21:49:09 -04:00
|
|
|
if type(mode) == ShareMode:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.assertEqual(
|
|
|
|
mode.server_status_label.text(),
|
|
|
|
strings._("gui_status_indicator_share_started"),
|
|
|
|
)
|
2019-01-20 15:01:51 -05:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def web_page(self, mode, string, public_mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the web page contains a string"""
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2019-10-20 13:46:14 -04:00
|
|
|
url = f"http://127.0.0.1:{self.gui.app.port}/"
|
2019-05-24 20:59:04 -04:00
|
|
|
if public_mode:
|
|
|
|
r = requests.get(url)
|
2018-09-23 20:41:48 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
r = requests.get(
|
|
|
|
url, auth=requests.auth.HTTPBasicAuth("onionshare", mode.web.password)
|
|
|
|
)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2019-05-24 20:59:04 -04:00
|
|
|
self.assertTrue(string in r.text)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def history_widgets_present(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the relevant widgets are present in the history view after activity has taken place"""
|
2018-10-07 21:49:09 -04:00
|
|
|
self.assertFalse(mode.history.empty.isVisible())
|
|
|
|
self.assertTrue(mode.history.not_empty.isVisible())
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def counter_incremented(self, mode, count):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the counter has incremented"""
|
2018-10-15 22:01:44 -04:00
|
|
|
self.assertEqual(mode.history.completed_count, count)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def server_is_stopped(self, mode, stay_open):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the server stops when we click Stop"""
|
|
|
|
if (
|
|
|
|
type(mode) == ReceiveMode
|
|
|
|
or (type(mode) == ShareMode and stay_open)
|
|
|
|
or (type(mode) == WebsiteMode)
|
|
|
|
):
|
|
|
|
QtTest.QTest.mouseClick(
|
|
|
|
mode.server_status.server_button, QtCore.Qt.LeftButton
|
|
|
|
)
|
2018-10-15 22:01:44 -04:00
|
|
|
self.assertEqual(mode.server_status.status, 0)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-15 22:01:44 -04:00
|
|
|
def web_server_is_stopped(self):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the web server also stopped"""
|
2018-09-23 20:41:48 -04:00
|
|
|
QtTest.QTest.qWait(2000)
|
|
|
|
|
2019-05-24 20:59:04 -04:00
|
|
|
try:
|
2019-10-20 13:46:14 -04:00
|
|
|
r = requests.get(f"http://127.0.0.1:{self.gui.app.port}/")
|
2019-05-24 20:59:04 -04:00
|
|
|
self.assertTrue(False)
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
self.assertTrue(True)
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def server_status_indicator_says_closed(self, mode, stay_open):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the Server Status indicator shows we closed"""
|
2018-10-07 21:49:09 -04:00
|
|
|
if type(mode) == ReceiveMode:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.assertEqual(
|
|
|
|
self.gui.receive_mode.server_status_label.text(),
|
|
|
|
strings._("gui_status_indicator_receive_stopped"),
|
|
|
|
)
|
2018-10-07 21:49:09 -04:00
|
|
|
if type(mode) == ShareMode:
|
2018-09-23 20:41:48 -04:00
|
|
|
if stay_open:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.assertEqual(
|
|
|
|
self.gui.share_mode.server_status_label.text(),
|
|
|
|
strings._("gui_status_indicator_share_stopped"),
|
|
|
|
)
|
2018-09-23 20:41:48 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
self.assertEqual(
|
|
|
|
self.gui.share_mode.server_status_label.text(),
|
|
|
|
strings._("closing_automatically"),
|
|
|
|
)
|
2018-10-15 22:01:44 -04:00
|
|
|
|
2019-09-09 02:35:05 -04:00
|
|
|
def clear_all_history_items(self, mode, count):
|
|
|
|
if count == 0:
|
|
|
|
QtTest.QTest.mouseClick(mode.history.clear_button, QtCore.Qt.LeftButton)
|
|
|
|
self.assertEquals(len(mode.history.item_list.items.keys()), count)
|
2018-10-15 22:01:44 -04:00
|
|
|
|
|
|
|
# Auto-stop timer tests
|
|
|
|
def set_timeout(self, mode, timeout):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the timeout can be set"""
|
2018-10-15 22:01:44 -04:00
|
|
|
timer = QtCore.QDateTime.currentDateTime().addSecs(timeout)
|
2019-03-25 00:05:54 -04:00
|
|
|
mode.server_status.autostop_timer_widget.setDateTime(timer)
|
|
|
|
self.assertTrue(mode.server_status.autostop_timer_widget.dateTime(), timer)
|
2018-10-15 22:01:44 -04:00
|
|
|
|
2019-03-25 00:05:54 -04:00
|
|
|
def autostop_timer_widget_hidden(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the auto-stop timer widget is hidden when share has started"""
|
2019-03-25 00:05:54 -04:00
|
|
|
self.assertFalse(mode.server_status.autostop_timer_container.isVisible())
|
2018-10-15 22:01:44 -04:00
|
|
|
|
|
|
|
def server_timed_out(self, mode, wait):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the server has timed out after the timer ran out"""
|
2018-10-15 22:01:44 -04:00
|
|
|
QtTest.QTest.qWait(wait)
|
|
|
|
# We should have timed out now
|
|
|
|
self.assertEqual(mode.server_status.status, 0)
|
|
|
|
|
2019-03-25 00:28:31 -04:00
|
|
|
# Auto-start timer tests
|
|
|
|
def set_autostart_timer(self, mode, timer):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the timer can be set"""
|
2019-03-04 18:28:27 -05:00
|
|
|
schedule = QtCore.QDateTime.currentDateTime().addSecs(timer)
|
2019-03-25 00:28:31 -04:00
|
|
|
mode.server_status.autostart_timer_widget.setDateTime(schedule)
|
|
|
|
self.assertTrue(mode.server_status.autostart_timer_widget.dateTime(), schedule)
|
2019-03-04 18:28:27 -05:00
|
|
|
|
2019-03-25 00:28:31 -04:00
|
|
|
def autostart_timer_widget_hidden(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the auto-start timer widget is hidden when share has started"""
|
2019-03-25 00:28:31 -04:00
|
|
|
self.assertFalse(mode.server_status.autostart_timer_container.isVisible())
|
2019-03-04 18:28:27 -05:00
|
|
|
|
|
|
|
def scheduled_service_started(self, mode, wait):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that the server has timed out after the timer ran out"""
|
2019-03-04 18:28:27 -05:00
|
|
|
QtTest.QTest.qWait(wait)
|
|
|
|
# We should have started now
|
|
|
|
self.assertEqual(mode.server_status.status, 2)
|
|
|
|
|
2019-03-07 19:03:37 -05:00
|
|
|
def cancel_the_share(self, mode):
|
2019-10-13 00:01:25 -04:00
|
|
|
"""Test that we can cancel a share before it's started up """
|
2019-03-07 19:03:37 -05:00
|
|
|
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()
|
2019-03-25 00:28:31 -04:00
|
|
|
self.set_autostart_timer(mode, 10)
|
2019-03-07 19:03:37 -05:00
|
|
|
QtTest.QTest.mousePress(mode.server_status.server_button, QtCore.Qt.LeftButton)
|
|
|
|
QtTest.QTest.qWait(2000)
|
2019-10-13 00:01:25 -04:00
|
|
|
QtTest.QTest.mouseRelease(
|
|
|
|
mode.server_status.server_button, QtCore.Qt.LeftButton
|
|
|
|
)
|
2019-03-07 19:03:37 -05:00
|
|
|
self.assertEqual(mode.server_status.status, 0)
|
|
|
|
self.server_is_stopped(mode, False)
|
|
|
|
self.web_server_is_stopped()
|
|
|
|
|
2018-10-16 20:57:21 -04:00
|
|
|
# Hack to close an Alert dialog that would otherwise block tests
|
|
|
|
def accept_dialog(self):
|
|
|
|
window = self.gui.qtapp.activeWindow()
|
|
|
|
if window:
|
|
|
|
window.close()
|
2018-10-15 22:01:44 -04:00
|
|
|
|
|
|
|
# 'Grouped' tests follow from here
|
2018-09-23 20:41:48 -04:00
|
|
|
|
2018-10-11 20:28:47 -04:00
|
|
|
def run_all_common_setup_tests(self):
|
|
|
|
self.gui_loaded()
|
|
|
|
self.windowTitle_seen()
|
|
|
|
self.settings_button_is_visible()
|
|
|
|
self.server_status_bar_is_visible()
|