mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Start refactoring all of the share mode tests to work with tabs
This commit is contained in:
parent
ed098e8981
commit
3f04ffb69e
@ -40,6 +40,9 @@ class GuiBaseTest(unittest.TestCase):
|
||||
with open(filename, "w") as file:
|
||||
file.write(secrets.token_hex(10))
|
||||
cls.tmpfiles.append(filename)
|
||||
cls.tmpfile_test = os.path.join(cls.tmpdir.name, "test.txt")
|
||||
with open(cls.tmpfile_test, "w") as file:
|
||||
file.write("onionshare")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
@ -48,6 +51,64 @@ class GuiBaseTest(unittest.TestCase):
|
||||
|
||||
# Shared test methods
|
||||
|
||||
def verify_new_tab(self, tab):
|
||||
# Make sure the new tab widget is showing, and no mode has been started
|
||||
self.assertTrue(tab.new_tab.isVisible())
|
||||
self.assertFalse(hasattr(tab, "share_mode"))
|
||||
self.assertFalse(hasattr(tab, "receive_mode"))
|
||||
self.assertFalse(hasattr(tab, "website_mode"))
|
||||
|
||||
def new_share_tab(self):
|
||||
tab = self.gui.tabs.widget(0)
|
||||
self.verify_new_tab(tab)
|
||||
|
||||
# Share files
|
||||
tab.share_button.click()
|
||||
self.assertFalse(tab.new_tab.isVisible())
|
||||
self.assertTrue(tab.share_mode.isVisible())
|
||||
|
||||
return tab
|
||||
|
||||
def new_share_tab_with_files(self):
|
||||
tab = self.new_share_tab()
|
||||
|
||||
# Add files
|
||||
for filename in self.tmpfiles:
|
||||
tab.share_mode.server_status.file_selection.file_list.add_file(filename)
|
||||
|
||||
return tab
|
||||
|
||||
def new_receive_tab(self):
|
||||
tab = self.gui.tabs.widget(0)
|
||||
self.verify_new_tab(tab)
|
||||
|
||||
# Receive files
|
||||
tab.receive_button.click()
|
||||
self.assertFalse(tab.new_tab.isVisible())
|
||||
self.assertTrue(tab.receive_mode.isVisible())
|
||||
|
||||
return tab
|
||||
|
||||
def new_website_tab(self):
|
||||
tab = self.gui.tabs.widget(0)
|
||||
self.verify_new_tab(tab)
|
||||
|
||||
# Publish website
|
||||
tab.website_button.click()
|
||||
self.assertFalse(tab.new_tab.isVisible())
|
||||
self.assertTrue(tab.website_mode.isVisible())
|
||||
|
||||
return tab
|
||||
|
||||
def new_website_tab_with_files(self):
|
||||
tab = self.new_website_tab()
|
||||
|
||||
# Add files
|
||||
for filename in self.tmpfiles:
|
||||
tab.website_mode.server_status.file_selection.file_list.add_file(filename)
|
||||
|
||||
return tab
|
||||
|
||||
def gui_loaded(self):
|
||||
"""Test that the GUI actually is shown"""
|
||||
self.assertTrue(self.gui.show)
|
||||
@ -56,265 +117,268 @@ class GuiBaseTest(unittest.TestCase):
|
||||
"""Test that the window title is OnionShare"""
|
||||
self.assertEqual(self.gui.windowTitle(), "OnionShare")
|
||||
|
||||
def settings_button_is_visible(self):
|
||||
"""Test that the settings button is visible"""
|
||||
self.assertTrue(self.gui.settings_button.isVisible())
|
||||
|
||||
def settings_button_is_hidden(self):
|
||||
"""Test that the settings button is hidden when the server starts"""
|
||||
self.assertFalse(self.gui.settings_button.isVisible())
|
||||
|
||||
def server_status_bar_is_visible(self):
|
||||
"""Test that the status bar is visible"""
|
||||
self.assertTrue(self.gui.status_bar.isVisible())
|
||||
|
||||
def click_mode(self, mode):
|
||||
"""Test that we can switch Mode by clicking the button"""
|
||||
if type(mode) == ReceiveMode:
|
||||
QtTest.QTest.mouseClick(self.gui.receive_mode_button, QtCore.Qt.LeftButton)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_RECEIVE)
|
||||
if type(mode) == ShareMode:
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode_button, QtCore.Qt.LeftButton)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_SHARE)
|
||||
if type(mode) == WebsiteMode:
|
||||
QtTest.QTest.mouseClick(self.gui.website_mode_button, QtCore.Qt.LeftButton)
|
||||
self.assertTrue(self.gui.mode, self.gui.MODE_WEBSITE)
|
||||
def mode_settings_widget_is_visible(self, tab):
|
||||
"""Test that the mode settings are visible"""
|
||||
self.assertTrue(tab.get_mode().mode_settings_widget.isVisible())
|
||||
|
||||
def click_toggle_history(self, mode):
|
||||
def mode_settings_widget_is_hidden(self, tab):
|
||||
"""Test that the mode settings are hidden when the server starts"""
|
||||
self.assertFalse(tab.get_mode().mode_settings_widget.isVisible())
|
||||
|
||||
def click_toggle_history(self, tab):
|
||||
"""Test that we can toggle Download or Upload history by clicking the toggle button"""
|
||||
currently_visible = mode.history.isVisible()
|
||||
QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(mode.history.isVisible(), not currently_visible)
|
||||
currently_visible = tab.get_mode().history.isVisible()
|
||||
QtTest.QTest.mouseClick(tab.get_mode().toggle_history, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(tab.get_mode().history.isVisible(), not currently_visible)
|
||||
|
||||
def history_indicator(self, mode, public_mode, indicator_count="1"):
|
||||
def history_indicator(self, tab, indicator_count="1"):
|
||||
"""Test that we can make sure the history is toggled off, do an action, and the indiciator works"""
|
||||
# Make sure history is toggled off
|
||||
if mode.history.isVisible():
|
||||
QtTest.QTest.mouseClick(mode.toggle_history, QtCore.Qt.LeftButton)
|
||||
self.assertFalse(mode.history.isVisible())
|
||||
if tab.get_mode().history.isVisible():
|
||||
QtTest.QTest.mouseClick(tab.get_mode().toggle_history, QtCore.Qt.LeftButton)
|
||||
self.assertFalse(tab.get_mode().history.isVisible())
|
||||
|
||||
# Indicator should not be visible yet
|
||||
self.assertFalse(mode.toggle_history.indicator_label.isVisible())
|
||||
self.assertFalse(tab.get_mode().toggle_history.indicator_label.isVisible())
|
||||
|
||||
if type(mode) == ReceiveMode:
|
||||
if type(tab.get_mode()) == ReceiveMode:
|
||||
# Upload a file
|
||||
files = {"file[]": open("/tmp/test.txt", "rb")}
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/upload"
|
||||
if public_mode:
|
||||
files = {"file[]": open(self.tmpfiles[0], "rb")}
|
||||
url = f"http://127.0.0.1:{tab.app.port}/upload"
|
||||
if tab.settings.get("general", "public"):
|
||||
requests.post(url, files=files)
|
||||
else:
|
||||
requests.post(
|
||||
url,
|
||||
files=files,
|
||||
auth=requests.auth.HTTPBasicAuth("onionshare", mode.web.password),
|
||||
auth=requests.auth.HTTPBasicAuth(
|
||||
"onionshare", tab.get_mode().web.password
|
||||
),
|
||||
)
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
if type(mode) == ShareMode:
|
||||
if type(tab.get_mode()) == ShareMode:
|
||||
# Download files
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/download"
|
||||
if public_mode:
|
||||
url = f"http://127.0.0.1:{tab.app.port}/download"
|
||||
if tab.settings.get("general", "public"):
|
||||
requests.get(url)
|
||||
else:
|
||||
requests.get(
|
||||
url,
|
||||
auth=requests.auth.HTTPBasicAuth("onionshare", mode.web.password),
|
||||
auth=requests.auth.HTTPBasicAuth(
|
||||
"onionshare", tab.get_mode().web.password
|
||||
),
|
||||
)
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
# Indicator should be visible, have a value of "1"
|
||||
self.assertTrue(mode.toggle_history.indicator_label.isVisible())
|
||||
self.assertEqual(mode.toggle_history.indicator_label.text(), indicator_count)
|
||||
self.assertTrue(tab.get_mode().toggle_history.indicator_label.isVisible())
|
||||
self.assertEqual(
|
||||
tab.get_mode().toggle_history.indicator_label.text(), indicator_count
|
||||
)
|
||||
|
||||
# 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())
|
||||
QtTest.QTest.mouseClick(tab.get_mode().toggle_history, QtCore.Qt.LeftButton)
|
||||
self.assertFalse(tab.get_mode().toggle_history.indicator_label.isVisible())
|
||||
|
||||
def history_is_not_visible(self, mode):
|
||||
def history_is_not_visible(self, tab):
|
||||
"""Test that the History section is not visible"""
|
||||
self.assertFalse(mode.history.isVisible())
|
||||
self.assertFalse(tab.get_mode().history.isVisible())
|
||||
|
||||
def history_is_visible(self, mode):
|
||||
def history_is_visible(self, tab):
|
||||
"""Test that the History section is visible"""
|
||||
self.assertTrue(mode.history.isVisible())
|
||||
self.assertTrue(tab.get_mode().history.isVisible())
|
||||
|
||||
def server_working_on_start_button_pressed(self, mode):
|
||||
def server_working_on_start_button_pressed(self, tab):
|
||||
"""Test we can start the service"""
|
||||
# Should be in SERVER_WORKING state
|
||||
QtTest.QTest.mouseClick(mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(mode.server_status.status, 1)
|
||||
QtTest.QTest.mouseClick(
|
||||
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
||||
)
|
||||
self.assertEqual(tab.get_mode().server_status.status, 1)
|
||||
|
||||
def toggle_indicator_is_reset(self, mode):
|
||||
self.assertEqual(mode.toggle_history.indicator_count, 0)
|
||||
self.assertFalse(mode.toggle_history.indicator_label.isVisible())
|
||||
def toggle_indicator_is_reset(self, tab):
|
||||
self.assertEqual(tab.get_mode().toggle_history.indicator_count, 0)
|
||||
self.assertFalse(tab.get_mode().toggle_history.indicator_label.isVisible())
|
||||
|
||||
def server_status_indicator_says_starting(self, mode):
|
||||
def server_status_indicator_says_starting(self, tab):
|
||||
"""Test that the Server Status indicator shows we are Starting"""
|
||||
self.assertEqual(
|
||||
mode.server_status_label.text(),
|
||||
tab.get_mode().server_status_label.text(),
|
||||
strings._("gui_status_indicator_share_working"),
|
||||
)
|
||||
|
||||
def server_status_indicator_says_scheduled(self, mode):
|
||||
def server_status_indicator_says_scheduled(self, tab):
|
||||
"""Test that the Server Status indicator shows we are Scheduled"""
|
||||
self.assertEqual(
|
||||
mode.server_status_label.text(),
|
||||
tab.get_mode().server_status_label.text(),
|
||||
strings._("gui_status_indicator_share_scheduled"),
|
||||
)
|
||||
|
||||
def server_is_started(self, mode, startup_time=2000):
|
||||
def server_is_started(self, tab, startup_time=2000):
|
||||
"""Test that the server has started"""
|
||||
QtTest.QTest.qWait(startup_time)
|
||||
# Should now be in SERVER_STARTED state
|
||||
self.assertEqual(mode.server_status.status, 2)
|
||||
self.assertEqual(tab.get_mode().server_status.status, 2)
|
||||
|
||||
def web_server_is_running(self):
|
||||
def web_server_is_running(self, tab):
|
||||
"""Test that the web server has started"""
|
||||
try:
|
||||
r = requests.get(f"http://127.0.0.1:{self.gui.app.port}/")
|
||||
requests.get(f"http://127.0.0.1:{tab.app.port}/")
|
||||
self.assertTrue(True)
|
||||
except requests.exceptions.ConnectionError:
|
||||
self.assertTrue(False)
|
||||
|
||||
def have_a_password(self, mode, public_mode):
|
||||
def have_a_password(self, tab):
|
||||
"""Test that we have a valid password"""
|
||||
if not public_mode:
|
||||
self.assertRegex(mode.server_status.web.password, r"(\w+)-(\w+)")
|
||||
if not tab.settings.get("general", "public"):
|
||||
self.assertRegex(tab.get_mode().server_status.web.password, r"(\w+)-(\w+)")
|
||||
else:
|
||||
self.assertIsNone(mode.server_status.web.password, r"(\w+)-(\w+)")
|
||||
self.assertIsNone(tab.get_mode().server_status.web.password, r"(\w+)-(\w+)")
|
||||
|
||||
def add_button_visible(self, mode):
|
||||
def add_button_visible(self, tab):
|
||||
"""Test that the add button should be visible"""
|
||||
self.assertTrue(mode.server_status.file_selection.add_button.isVisible())
|
||||
self.assertTrue(
|
||||
tab.get_mode().server_status.file_selection.add_button.isVisible()
|
||||
)
|
||||
|
||||
def url_description_shown(self, mode):
|
||||
def url_description_shown(self, tab):
|
||||
"""Test that the URL label is showing"""
|
||||
self.assertTrue(mode.server_status.url_description.isVisible())
|
||||
self.assertTrue(tab.get_mode().server_status.url_description.isVisible())
|
||||
|
||||
def have_copy_url_button(self, mode, public_mode):
|
||||
def have_copy_url_button(self, tab):
|
||||
"""Test that the Copy URL button is shown and that the clipboard is correct"""
|
||||
self.assertTrue(mode.server_status.copy_url_button.isVisible())
|
||||
self.assertTrue(tab.get_mode().server_status.copy_url_button.isVisible())
|
||||
|
||||
QtTest.QTest.mouseClick(
|
||||
mode.server_status.copy_url_button, QtCore.Qt.LeftButton
|
||||
tab.get_mode().server_status.copy_url_button, QtCore.Qt.LeftButton
|
||||
)
|
||||
clipboard = self.gui.qtapp.clipboard()
|
||||
if public_mode:
|
||||
self.assertEqual(clipboard.text(), f"http://127.0.0.1:{self.gui.app.port}")
|
||||
clipboard = tab.common.gui.qtapp.clipboard()
|
||||
if tab.settings.get("general", "public"):
|
||||
self.assertEqual(clipboard.text(), f"http://127.0.0.1:{tab.app.port}")
|
||||
else:
|
||||
self.assertEqual(
|
||||
clipboard.text(),
|
||||
f"http://onionshare:{mode.server_status.web.password}@127.0.0.1:{self.gui.app.port}",
|
||||
f"http://onionshare:{tab.get_mode().server_status.web.password}@127.0.0.1:{tab.app.port}",
|
||||
)
|
||||
|
||||
def server_status_indicator_says_started(self, mode):
|
||||
def server_status_indicator_says_started(self, tab):
|
||||
"""Test that the Server Status indicator shows we are started"""
|
||||
if type(mode) == ReceiveMode:
|
||||
if type(tab.get_mode()) == ReceiveMode:
|
||||
self.assertEqual(
|
||||
mode.server_status_label.text(),
|
||||
tab.get_mode().server_status_label.text(),
|
||||
strings._("gui_status_indicator_receive_started"),
|
||||
)
|
||||
if type(mode) == ShareMode:
|
||||
if type(tab.get_mode()) == ShareMode:
|
||||
self.assertEqual(
|
||||
mode.server_status_label.text(),
|
||||
tab.get_mode().server_status_label.text(),
|
||||
strings._("gui_status_indicator_share_started"),
|
||||
)
|
||||
|
||||
def web_page(self, mode, string, public_mode):
|
||||
def web_page(self, tab, string):
|
||||
"""Test that the web page contains a string"""
|
||||
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/"
|
||||
if public_mode:
|
||||
url = f"http://127.0.0.1:{tab.app.port}/"
|
||||
if tab.settings.get("general", "public"):
|
||||
r = requests.get(url)
|
||||
else:
|
||||
r = requests.get(
|
||||
url, auth=requests.auth.HTTPBasicAuth("onionshare", mode.web.password)
|
||||
url,
|
||||
auth=requests.auth.HTTPBasicAuth(
|
||||
"onionshare", tab.get_mode().web.password
|
||||
),
|
||||
)
|
||||
|
||||
self.assertTrue(string in r.text)
|
||||
|
||||
def history_widgets_present(self, mode):
|
||||
def history_widgets_present(self, tab):
|
||||
"""Test that the relevant widgets are present in the history view after activity has taken place"""
|
||||
self.assertFalse(mode.history.empty.isVisible())
|
||||
self.assertTrue(mode.history.not_empty.isVisible())
|
||||
self.assertFalse(tab.get_mode().history.empty.isVisible())
|
||||
self.assertTrue(tab.get_mode().history.not_empty.isVisible())
|
||||
|
||||
def counter_incremented(self, mode, count):
|
||||
def counter_incremented(self, tab, count):
|
||||
"""Test that the counter has incremented"""
|
||||
self.assertEqual(mode.history.completed_count, count)
|
||||
self.assertEqual(tab.get_mode().history.completed_count, count)
|
||||
|
||||
def server_is_stopped(self, mode, stay_open):
|
||||
def server_is_stopped(self, tab):
|
||||
"""Test that the server stops when we click Stop"""
|
||||
if (
|
||||
type(mode) == ReceiveMode
|
||||
or (type(mode) == ShareMode and stay_open)
|
||||
or (type(mode) == WebsiteMode)
|
||||
type(tab.get_mode()) == ReceiveMode
|
||||
or (
|
||||
type(tab.get_mode()) == ShareMode
|
||||
and not tab.settings.get("share", "autostop_sharing")
|
||||
)
|
||||
or (type(tab.get_mode()) == WebsiteMode)
|
||||
):
|
||||
QtTest.QTest.mouseClick(
|
||||
mode.server_status.server_button, QtCore.Qt.LeftButton
|
||||
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
||||
)
|
||||
self.assertEqual(mode.server_status.status, 0)
|
||||
self.assertEqual(tab.get_mode().server_status.status, 0)
|
||||
|
||||
def web_server_is_stopped(self):
|
||||
def web_server_is_stopped(self, tab):
|
||||
"""Test that the web server also stopped"""
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
try:
|
||||
r = requests.get(f"http://127.0.0.1:{self.gui.app.port}/")
|
||||
r = requests.get(f"http://127.0.0.1:{tab.app.port}/")
|
||||
self.assertTrue(False)
|
||||
except requests.exceptions.ConnectionError:
|
||||
self.assertTrue(True)
|
||||
|
||||
def server_status_indicator_says_closed(self, mode, stay_open):
|
||||
def server_status_indicator_says_closed(self, tab):
|
||||
"""Test that the Server Status indicator shows we closed"""
|
||||
if type(mode) == ReceiveMode:
|
||||
if type(tab.get_mode()) == ReceiveMode:
|
||||
self.assertEqual(
|
||||
self.gui.receive_mode.server_status_label.text(),
|
||||
tab.get_mode().server_status_label.text(),
|
||||
strings._("gui_status_indicator_receive_stopped"),
|
||||
)
|
||||
if type(mode) == ShareMode:
|
||||
if stay_open:
|
||||
if type(tab.get_mode()) == ShareMode:
|
||||
if tab.settings.get("share", "autostop_sharing"):
|
||||
self.assertEqual(
|
||||
self.gui.share_mode.server_status_label.text(),
|
||||
tab.get_mode().server_status_label.text(),
|
||||
strings._("gui_status_indicator_share_stopped"),
|
||||
)
|
||||
else:
|
||||
self.assertEqual(
|
||||
self.gui.share_mode.server_status_label.text(),
|
||||
tab.get_mode().server_status_label.text(),
|
||||
strings._("closing_automatically"),
|
||||
)
|
||||
|
||||
def clear_all_history_items(self, mode, count):
|
||||
def clear_all_history_items(self, tab, count):
|
||||
if count == 0:
|
||||
QtTest.QTest.mouseClick(mode.history.clear_button, QtCore.Qt.LeftButton)
|
||||
self.assertEquals(len(mode.history.item_list.items.keys()), count)
|
||||
QtTest.QTest.mouseClick(
|
||||
tab.get_mode().history.clear_button, QtCore.Qt.LeftButton
|
||||
)
|
||||
self.assertEquals(len(tab.get_mode().history.item_list.items.keys()), count)
|
||||
|
||||
# Auto-stop timer tests
|
||||
def set_timeout(self, mode, timeout):
|
||||
def set_timeout(self, tab, timeout):
|
||||
"""Test that the timeout can be set"""
|
||||
timer = QtCore.QDateTime.currentDateTime().addSecs(timeout)
|
||||
mode.server_status.autostop_timer_widget.setDateTime(timer)
|
||||
self.assertTrue(mode.server_status.autostop_timer_widget.dateTime(), timer)
|
||||
tab.get_mode().server_status.autostop_timer_widget.setDateTime(timer)
|
||||
self.assertTrue(
|
||||
tab.get_mode().server_status.autostop_timer_widget.dateTime(), timer
|
||||
)
|
||||
|
||||
def autostop_timer_widget_hidden(self, mode):
|
||||
def autostop_timer_widget_hidden(self, tab):
|
||||
"""Test that the auto-stop timer widget is hidden when share has started"""
|
||||
self.assertFalse(mode.server_status.autostop_timer_container.isVisible())
|
||||
self.assertFalse(
|
||||
tab.get_mode().server_status.autostop_timer_container.isVisible()
|
||||
)
|
||||
|
||||
def server_timed_out(self, mode, wait):
|
||||
def server_timed_out(self, tab, wait):
|
||||
"""Test that the server has timed out after the timer ran out"""
|
||||
QtTest.QTest.qWait(wait)
|
||||
# We should have timed out now
|
||||
self.assertEqual(mode.server_status.status, 0)
|
||||
|
||||
# Hack to close an Alert dialog that would otherwise block tests
|
||||
def accept_dialog(self):
|
||||
window = self.gui.qtapp.activeWindow()
|
||||
if window:
|
||||
window.close()
|
||||
self.assertEqual(tab.get_mode().server_status.status, 0)
|
||||
|
||||
# Grouped tests follow from here
|
||||
|
||||
def run_all_common_setup_tests(self):
|
||||
self.gui_loaded()
|
||||
self.window_title_seen()
|
||||
self.settings_button_is_visible()
|
||||
self.server_status_bar_is_visible()
|
||||
|
@ -2,6 +2,7 @@ import pytest
|
||||
import os
|
||||
import requests
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
from PyQt5 import QtCore, QtTest
|
||||
|
||||
@ -12,110 +13,101 @@ class TestShare(GuiBaseTest):
|
||||
# Shared test methods
|
||||
|
||||
# Persistence tests
|
||||
def have_same_password(self, password):
|
||||
def have_same_password(self, tab, password):
|
||||
"""Test that we have the same password"""
|
||||
self.assertEqual(self.gui.share_mode.server_status.web.password, password)
|
||||
self.assertEqual(tab.get_mode().server_status.web.password, password)
|
||||
|
||||
# Share-specific tests
|
||||
|
||||
def file_selection_widget_has_files(self, num=2):
|
||||
def file_selection_widget_has_files(self, tab, num=2):
|
||||
"""Test that the number of items in the list is as expected"""
|
||||
self.assertEqual(
|
||||
self.gui.share_mode.server_status.file_selection.get_num_files(), num
|
||||
tab.get_mode().server_status.file_selection.get_num_files(), num
|
||||
)
|
||||
|
||||
def deleting_all_files_hides_delete_button(self):
|
||||
def deleting_all_files_hides_delete_button(self, tab):
|
||||
"""Test that clicking on the file item shows the delete button. Test that deleting the only item in the list hides the delete button"""
|
||||
rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(
|
||||
self.gui.share_mode.server_status.file_selection.file_list.item(0)
|
||||
rect = tab.get_mode().server_status.file_selection.file_list.visualItemRect(
|
||||
tab.get_mode().server_status.file_selection.file_list.item(0)
|
||||
)
|
||||
QtTest.QTest.mouseClick(
|
||||
self.gui.share_mode.server_status.file_selection.file_list.viewport(),
|
||||
tab.get_mode().server_status.file_selection.file_list.viewport(),
|
||||
QtCore.Qt.LeftButton,
|
||||
pos=rect.center(),
|
||||
)
|
||||
# Delete button should be visible
|
||||
self.assertTrue(
|
||||
self.gui.share_mode.server_status.file_selection.delete_button.isVisible()
|
||||
tab.get_mode().server_status.file_selection.delete_button.isVisible()
|
||||
)
|
||||
# Click delete, delete button should still be visible since we have one more file
|
||||
QtTest.QTest.mouseClick(
|
||||
self.gui.share_mode.server_status.file_selection.delete_button,
|
||||
tab.get_mode().server_status.file_selection.delete_button,
|
||||
QtCore.Qt.LeftButton,
|
||||
)
|
||||
|
||||
rect = self.gui.share_mode.server_status.file_selection.file_list.visualItemRect(
|
||||
self.gui.share_mode.server_status.file_selection.file_list.item(0)
|
||||
rect = tab.get_mode().server_status.file_selection.file_list.visualItemRect(
|
||||
tab.get_mode().server_status.file_selection.file_list.item(0)
|
||||
)
|
||||
QtTest.QTest.mouseClick(
|
||||
self.gui.share_mode.server_status.file_selection.file_list.viewport(),
|
||||
tab.get_mode().server_status.file_selection.file_list.viewport(),
|
||||
QtCore.Qt.LeftButton,
|
||||
pos=rect.center(),
|
||||
)
|
||||
self.assertTrue(
|
||||
self.gui.share_mode.server_status.file_selection.delete_button.isVisible()
|
||||
tab.get_mode().server_status.file_selection.delete_button.isVisible()
|
||||
)
|
||||
QtTest.QTest.mouseClick(
|
||||
self.gui.share_mode.server_status.file_selection.delete_button,
|
||||
tab.get_mode().server_status.file_selection.delete_button,
|
||||
QtCore.Qt.LeftButton,
|
||||
)
|
||||
|
||||
# No more files, the delete button should be hidden
|
||||
self.assertFalse(
|
||||
self.gui.share_mode.server_status.file_selection.delete_button.isVisible()
|
||||
tab.get_mode().server_status.file_selection.delete_button.isVisible()
|
||||
)
|
||||
|
||||
def add_a_file_and_delete_using_its_delete_widget(self):
|
||||
def add_a_file_and_delete_using_its_delete_widget(self, tab):
|
||||
"""Test that we can also delete a file by clicking on its [X] widget"""
|
||||
self.gui.share_mode.server_status.file_selection.file_list.add_file(
|
||||
"/etc/hosts"
|
||||
)
|
||||
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])
|
||||
QtTest.QTest.mouseClick(
|
||||
self.gui.share_mode.server_status.file_selection.file_list.item(
|
||||
0
|
||||
).item_button,
|
||||
tab.get_mode().server_status.file_selection.file_list.item(0).item_button,
|
||||
QtCore.Qt.LeftButton,
|
||||
)
|
||||
self.file_selection_widget_has_files(0)
|
||||
self.file_selection_widget_has_files(tab, 0)
|
||||
|
||||
def file_selection_widget_read_files(self):
|
||||
def file_selection_widget_read_files(self, tab):
|
||||
"""Re-add some files to the list so we can share"""
|
||||
self.gui.share_mode.server_status.file_selection.file_list.add_file(
|
||||
"/etc/hosts"
|
||||
)
|
||||
self.gui.share_mode.server_status.file_selection.file_list.add_file(
|
||||
"/tmp/test.txt"
|
||||
)
|
||||
self.file_selection_widget_has_files(2)
|
||||
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])
|
||||
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[1])
|
||||
self.file_selection_widget_has_files(tab, 2)
|
||||
|
||||
def add_large_file(self):
|
||||
def add_large_file(self, tab):
|
||||
"""Add a large file to the share"""
|
||||
size = 1024 * 1024 * 155
|
||||
with open("/tmp/large_file", "wb") as fout:
|
||||
fout.write(os.urandom(size))
|
||||
self.gui.share_mode.server_status.file_selection.file_list.add_file(
|
||||
tab.get_mode().server_status.file_selection.file_list.add_file(
|
||||
"/tmp/large_file"
|
||||
)
|
||||
|
||||
def add_delete_buttons_hidden(self):
|
||||
def add_delete_buttons_hidden(self, tab):
|
||||
"""Test that the add and delete buttons are hidden when the server starts"""
|
||||
self.assertFalse(
|
||||
self.gui.share_mode.server_status.file_selection.add_button.isVisible()
|
||||
tab.get_mode().server_status.file_selection.add_button.isVisible()
|
||||
)
|
||||
self.assertFalse(
|
||||
self.gui.share_mode.server_status.file_selection.delete_button.isVisible()
|
||||
tab.get_mode().server_status.file_selection.delete_button.isVisible()
|
||||
)
|
||||
|
||||
def download_share(self, public_mode):
|
||||
def download_share(self, tab):
|
||||
"""Test that we can download the share"""
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/download"
|
||||
if public_mode:
|
||||
url = f"http://127.0.0.1:{tab.app.port}/download"
|
||||
if tab.settings.get("general", "public"):
|
||||
r = requests.get(url)
|
||||
else:
|
||||
r = requests.get(
|
||||
url,
|
||||
auth=requests.auth.HTTPBasicAuth(
|
||||
"onionshare", self.gui.share_mode.server_status.web.password
|
||||
"onionshare", tab.get_mode().server_status.web.password
|
||||
),
|
||||
)
|
||||
|
||||
@ -127,30 +119,30 @@ class TestShare(GuiBaseTest):
|
||||
QtTest.QTest.qWait(2000)
|
||||
self.assertEqual("onionshare", zip.read("test.txt").decode("utf-8"))
|
||||
|
||||
def individual_file_is_viewable_or_not(self, public_mode, stay_open):
|
||||
"""Test whether an individual file is viewable (when in stay_open mode) and that it isn't (when not in stay_open mode)"""
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}"
|
||||
download_file_url = f"http://127.0.0.1:{self.gui.app.port}/test.txt"
|
||||
if public_mode:
|
||||
def individual_file_is_viewable_or_not(self, tab):
|
||||
"""Test whether an individual file is viewable (when in autostop_sharing is false) and that it isn't (when not in autostop_sharing is true)"""
|
||||
url = f"http://127.0.0.1:{tab.app.port}"
|
||||
download_file_url = f"http://127.0.0.1:{tab.app.port}/test.txt"
|
||||
if tab.settings.get("general", "public"):
|
||||
r = requests.get(url)
|
||||
else:
|
||||
r = requests.get(
|
||||
url,
|
||||
auth=requests.auth.HTTPBasicAuth(
|
||||
"onionshare", self.gui.share_mode.server_status.web.password
|
||||
"onionshare", tab.get_mode().server_status.web.password
|
||||
),
|
||||
)
|
||||
|
||||
if stay_open:
|
||||
if not tab.settings.get("share", "autostop_sharing"):
|
||||
self.assertTrue('a href="test.txt"' in r.text)
|
||||
|
||||
if public_mode:
|
||||
if tab.settings.get("general", "public"):
|
||||
r = requests.get(download_file_url)
|
||||
else:
|
||||
r = requests.get(
|
||||
download_file_url,
|
||||
auth=requests.auth.HTTPBasicAuth(
|
||||
"onionshare", self.gui.share_mode.server_status.web.password
|
||||
"onionshare", tab.get_mode().server_status.web.password
|
||||
),
|
||||
)
|
||||
|
||||
@ -162,210 +154,228 @@ class TestShare(GuiBaseTest):
|
||||
self.assertEqual("onionshare", f.read())
|
||||
else:
|
||||
self.assertFalse('a href="/test.txt"' in r.text)
|
||||
if public_mode:
|
||||
if tab.settings.get("general", "public"):
|
||||
r = requests.get(download_file_url)
|
||||
else:
|
||||
r = requests.get(
|
||||
download_file_url,
|
||||
auth=requests.auth.HTTPBasicAuth(
|
||||
"onionshare", self.gui.share_mode.server_status.web.password
|
||||
"onionshare", tab.get_mode().server_status.web.password
|
||||
),
|
||||
)
|
||||
self.assertEqual(r.status_code, 404)
|
||||
self.download_share(public_mode)
|
||||
self.download_share(tab)
|
||||
|
||||
QtTest.QTest.qWait(2000)
|
||||
|
||||
def hit_401(self, public_mode):
|
||||
def hit_401(self, tab):
|
||||
"""Test that the server stops after too many 401s, or doesn't when in public_mode"""
|
||||
url = f"http://127.0.0.1:{self.gui.app.port}/"
|
||||
url = f"http://127.0.0.1:{tab.app.port}/"
|
||||
|
||||
for _ in range(20):
|
||||
password_guess = self.gui.common.build_password()
|
||||
r = requests.get(
|
||||
requests.get(
|
||||
url, auth=requests.auth.HTTPBasicAuth("onionshare", password_guess)
|
||||
)
|
||||
|
||||
# A nasty hack to avoid the Alert dialog that blocks the rest of the test
|
||||
if not public_mode:
|
||||
if not tab.settings.get("general", "public"):
|
||||
QtCore.QTimer.singleShot(1000, self.accept_dialog)
|
||||
|
||||
# In public mode, we should still be running (no rate-limiting)
|
||||
if public_mode:
|
||||
self.web_server_is_running()
|
||||
if tab.settings.get("general", "public"):
|
||||
self.web_server_is_running(tab)
|
||||
# In non-public mode, we should be shut down (rate-limiting)
|
||||
else:
|
||||
self.web_server_is_stopped()
|
||||
|
||||
# Grouped tests follow from here
|
||||
|
||||
def run_all_share_mode_setup_tests(self):
|
||||
"""Tests in share mode prior to starting a share"""
|
||||
self.click_mode(self.gui.share_mode)
|
||||
self.file_selection_widget_has_files()
|
||||
self.history_is_not_visible(self.gui.share_mode)
|
||||
self.click_toggle_history(self.gui.share_mode)
|
||||
self.history_is_visible(self.gui.share_mode)
|
||||
self.deleting_all_files_hides_delete_button()
|
||||
self.add_a_file_and_delete_using_its_delete_widget()
|
||||
self.file_selection_widget_read_files()
|
||||
|
||||
def run_all_share_mode_started_tests(self, public_mode, startup_time=2000):
|
||||
"""Tests in share mode after starting a share"""
|
||||
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()
|
||||
self.server_is_started(self.gui.share_mode, startup_time)
|
||||
self.web_server_is_running()
|
||||
self.have_a_password(self.gui.share_mode, public_mode)
|
||||
self.url_description_shown(self.gui.share_mode)
|
||||
self.have_copy_url_button(self.gui.share_mode, public_mode)
|
||||
self.server_status_indicator_says_started(self.gui.share_mode)
|
||||
|
||||
def run_all_share_mode_download_tests(self, public_mode, stay_open):
|
||||
"""Tests in share mode after downloading a share"""
|
||||
self.web_page(self.gui.share_mode, "Total size", public_mode)
|
||||
self.download_share(public_mode)
|
||||
self.history_widgets_present(self.gui.share_mode)
|
||||
self.server_is_stopped(self.gui.share_mode, stay_open)
|
||||
self.web_server_is_stopped()
|
||||
self.server_status_indicator_says_closed(self.gui.share_mode, stay_open)
|
||||
self.add_button_visible(self.gui.share_mode)
|
||||
self.server_working_on_start_button_pressed(self.gui.share_mode)
|
||||
self.toggle_indicator_is_reset(self.gui.share_mode)
|
||||
self.server_is_started(self.gui.share_mode)
|
||||
self.history_indicator(self.gui.share_mode, public_mode)
|
||||
|
||||
def run_all_share_mode_individual_file_download_tests(self, public_mode, stay_open):
|
||||
"""Tests in share mode after downloading a share"""
|
||||
self.web_page(self.gui.share_mode, "Total size", public_mode)
|
||||
self.individual_file_is_viewable_or_not(public_mode, stay_open)
|
||||
self.history_widgets_present(self.gui.share_mode)
|
||||
self.server_is_stopped(self.gui.share_mode, stay_open)
|
||||
self.web_server_is_stopped()
|
||||
self.server_status_indicator_says_closed(self.gui.share_mode, stay_open)
|
||||
self.add_button_visible(self.gui.share_mode)
|
||||
self.server_working_on_start_button_pressed(self.gui.share_mode)
|
||||
self.server_is_started(self.gui.share_mode)
|
||||
self.history_indicator(self.gui.share_mode, public_mode)
|
||||
|
||||
def run_all_share_mode_tests(self, public_mode, stay_open):
|
||||
"""End-to-end share tests"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.run_all_share_mode_started_tests(public_mode)
|
||||
self.run_all_share_mode_download_tests(public_mode, stay_open)
|
||||
|
||||
def run_all_clear_all_button_tests(self, public_mode, stay_open):
|
||||
"""Test the Clear All history button"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.run_all_share_mode_started_tests(public_mode)
|
||||
self.individual_file_is_viewable_or_not(public_mode, stay_open)
|
||||
self.history_widgets_present(self.gui.share_mode)
|
||||
self.clear_all_history_items(self.gui.share_mode, 0)
|
||||
self.individual_file_is_viewable_or_not(public_mode, stay_open)
|
||||
self.clear_all_history_items(self.gui.share_mode, 2)
|
||||
|
||||
def run_all_share_mode_individual_file_tests(self, public_mode, stay_open):
|
||||
"""Tests in share mode when viewing an individual file"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.run_all_share_mode_started_tests(public_mode)
|
||||
self.run_all_share_mode_individual_file_download_tests(public_mode, stay_open)
|
||||
|
||||
def run_all_large_file_tests(self, public_mode, stay_open):
|
||||
"""Same as above but with a larger file"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.add_large_file()
|
||||
self.run_all_share_mode_started_tests(public_mode, startup_time=15000)
|
||||
self.assertTrue(self.gui.share_mode.filesize_warning.isVisible())
|
||||
self.server_is_stopped(self.gui.share_mode, stay_open)
|
||||
self.web_server_is_stopped()
|
||||
self.server_status_indicator_says_closed(self.gui.share_mode, stay_open)
|
||||
|
||||
def run_all_share_mode_persistent_tests(self, public_mode, stay_open):
|
||||
"""Same as end-to-end share tests but also test the password is the same on multiple shared"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.run_all_share_mode_started_tests(public_mode)
|
||||
password = self.gui.share_mode.server_status.web.password
|
||||
self.run_all_share_mode_download_tests(public_mode, stay_open)
|
||||
self.have_same_password(password)
|
||||
|
||||
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.run_all_share_mode_started_tests(public_mode)
|
||||
self.autostop_timer_widget_hidden(self.gui.share_mode)
|
||||
self.server_timed_out(self.gui.share_mode, 10000)
|
||||
self.web_server_is_stopped()
|
||||
|
||||
def run_all_share_mode_autostart_timer_tests(self, public_mode):
|
||||
"""Auto-start timer tests in share mode"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.set_autostart_timer(self.gui.share_mode, 5)
|
||||
self.server_working_on_start_button_pressed(self.gui.share_mode)
|
||||
self.autostart_timer_widget_hidden(self.gui.share_mode)
|
||||
self.server_status_indicator_says_scheduled(self.gui.share_mode)
|
||||
self.web_server_is_stopped()
|
||||
self.scheduled_service_started(self.gui.share_mode, 7000)
|
||||
self.web_server_is_running()
|
||||
|
||||
def run_all_share_mode_autostop_autostart_mismatch_tests(self, public_mode):
|
||||
"""Auto-stop timer tests in share mode"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.set_autostart_timer(self.gui.share_mode, 15)
|
||||
self.set_timeout(self.gui.share_mode, 5)
|
||||
QtCore.QTimer.singleShot(4000, self.accept_dialog)
|
||||
QtTest.QTest.mouseClick(
|
||||
self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton
|
||||
)
|
||||
self.server_is_stopped(self.gui.share_mode, False)
|
||||
|
||||
def run_all_share_mode_unreadable_file_tests(self):
|
||||
"""Attempt to share an unreadable file"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
QtCore.QTimer.singleShot(1000, self.accept_dialog)
|
||||
self.gui.share_mode.server_status.file_selection.file_list.add_file(
|
||||
"/tmp/nonexistent.txt"
|
||||
)
|
||||
self.file_selection_widget_has_files(2)
|
||||
self.web_server_is_stopped(tab)
|
||||
|
||||
# Auto-start timer tests
|
||||
def set_autostart_timer(self, mode, timer):
|
||||
|
||||
def set_autostart_timer(self, tab, mode, timer):
|
||||
"""Test that the timer can be set"""
|
||||
schedule = QtCore.QDateTime.currentDateTime().addSecs(timer)
|
||||
mode.server_status.autostart_timer_widget.setDateTime(schedule)
|
||||
self.assertTrue(mode.server_status.autostart_timer_widget.dateTime(), schedule)
|
||||
|
||||
def autostart_timer_widget_hidden(self, mode):
|
||||
def autostart_timer_widget_hidden(self, tab, mode):
|
||||
"""Test that the auto-start timer widget is hidden when share has started"""
|
||||
self.assertFalse(mode.server_status.autostart_timer_container.isVisible())
|
||||
|
||||
def scheduled_service_started(self, mode, wait):
|
||||
def scheduled_service_started(self, tab, 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)
|
||||
|
||||
def cancel_the_share(self, mode):
|
||||
def cancel_the_share(self, tab, 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_autostart_timer(mode, 10)
|
||||
self.server_working_on_start_button_pressed(tab)
|
||||
self.server_status_indicator_says_scheduled(tab)
|
||||
self.add_delete_buttons_hidden(tab)
|
||||
self.mode_settings_widget_is_hidden(tab)
|
||||
self.set_autostart_timer(tab, 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()
|
||||
self.server_is_stopped(tab)
|
||||
self.web_server_is_stopped(tab)
|
||||
|
||||
# Grouped tests follow from here
|
||||
|
||||
def run_all_share_mode_setup_tests(self, tab):
|
||||
"""Tests in share mode prior to starting a share"""
|
||||
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[0])
|
||||
tab.get_mode().server_status.file_selection.file_list.add_file(self.tmpfiles[1])
|
||||
self.file_selection_widget_has_files(tab, 2)
|
||||
self.history_is_not_visible(tab)
|
||||
self.click_toggle_history(tab)
|
||||
self.history_is_visible(tab)
|
||||
self.deleting_all_files_hides_delete_button(tab)
|
||||
self.add_a_file_and_delete_using_its_delete_widget(tab)
|
||||
self.file_selection_widget_read_files(tab)
|
||||
|
||||
def run_all_share_mode_started_tests(self, tab, startup_time=2000):
|
||||
"""Tests in share mode after starting a share"""
|
||||
self.server_working_on_start_button_pressed(tab)
|
||||
self.server_status_indicator_says_starting(tab)
|
||||
self.add_delete_buttons_hidden(tab)
|
||||
self.mode_settings_widget_is_hidden(tab)
|
||||
self.server_is_started(tab, startup_time)
|
||||
self.web_server_is_running(tab)
|
||||
self.have_a_password(tab)
|
||||
self.url_description_shown(tab)
|
||||
self.have_copy_url_button(tab)
|
||||
self.server_status_indicator_says_started(tab)
|
||||
|
||||
def run_all_share_mode_download_tests(self, tab):
|
||||
"""Tests in share mode after downloading a share"""
|
||||
tab.get_mode().server_status.file_selection.file_list.add_file(
|
||||
self.tmpfile_test
|
||||
)
|
||||
self.web_page(tab, "Total size")
|
||||
self.download_share(tab)
|
||||
self.history_widgets_present(tab)
|
||||
self.server_is_stopped(tab)
|
||||
self.web_server_is_stopped(tab)
|
||||
self.server_status_indicator_says_closed(tab)
|
||||
self.add_button_visible(tab)
|
||||
self.server_working_on_start_button_pressed(tab)
|
||||
self.toggle_indicator_is_reset(tab)
|
||||
self.server_is_started(tab)
|
||||
self.history_indicator(tab)
|
||||
|
||||
def run_all_share_mode_individual_file_download_tests(self, tab):
|
||||
"""Tests in share mode after downloading a share"""
|
||||
self.web_page(tab, "Total size")
|
||||
self.individual_file_is_viewable_or_not(tab)
|
||||
self.history_widgets_present(tab)
|
||||
self.server_is_stopped(tab)
|
||||
self.web_server_is_stopped(tab)
|
||||
self.server_status_indicator_says_closed(tab)
|
||||
self.add_button_visible(tab)
|
||||
self.server_working_on_start_button_pressed(tab)
|
||||
self.server_is_started(tab)
|
||||
self.history_indicator(tab)
|
||||
|
||||
def run_all_share_mode_tests(self, tab):
|
||||
"""End-to-end share tests"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.run_all_share_mode_started_tests(tab)
|
||||
self.run_all_share_mode_download_tests(tab)
|
||||
|
||||
def run_all_clear_all_button_tests(self, tab):
|
||||
"""Test the Clear All history button"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.run_all_share_mode_started_tests(tab)
|
||||
self.individual_file_is_viewable_or_not(tab)
|
||||
self.history_widgets_present(tab)
|
||||
self.clear_all_history_items(tab, 0)
|
||||
self.individual_file_is_viewable_or_not(tab)
|
||||
self.clear_all_history_items(tab, 2)
|
||||
|
||||
def run_all_share_mode_individual_file_tests(self, tab):
|
||||
"""Tests in share mode when viewing an individual file"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.run_all_share_mode_started_tests(tab)
|
||||
self.run_all_share_mode_individual_file_download_tests(tab)
|
||||
|
||||
def run_all_large_file_tests(self, tab):
|
||||
"""Same as above but with a larger file"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.add_large_file(tab)
|
||||
self.run_all_share_mode_started_tests(tab, startup_time=15000)
|
||||
self.assertTrue(tab.filesize_warning.isVisible())
|
||||
self.server_is_stopped(tab)
|
||||
self.web_server_is_stopped(tab)
|
||||
self.server_status_indicator_says_closed(tab)
|
||||
|
||||
def run_all_share_mode_persistent_tests(self, tab):
|
||||
"""Same as end-to-end share tests but also test the password is the same on multiple shared"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.run_all_share_mode_started_tests(tab)
|
||||
password = tab.get_mode().server_status.web.password
|
||||
self.run_all_share_mode_download_tests(tab)
|
||||
self.have_same_password(tab, password)
|
||||
|
||||
def run_all_share_mode_timer_tests(self, tab):
|
||||
"""Auto-stop timer tests in share mode"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.set_timeout(tab, 5)
|
||||
self.run_all_share_mode_started_tests(tab)
|
||||
self.autostop_timer_widget_hidden(tab)
|
||||
self.server_timed_out(tab, 10000)
|
||||
self.web_server_is_stopped(tab)
|
||||
|
||||
def run_all_share_mode_autostart_timer_tests(self, tab):
|
||||
"""Auto-start timer tests in share mode"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.set_autostart_timer(tab, 5)
|
||||
self.server_working_on_start_button_pressed(tab)
|
||||
self.autostart_timer_widget_hidden(tab)
|
||||
self.server_status_indicator_says_scheduled(tab)
|
||||
self.web_server_is_stopped(tab)
|
||||
self.scheduled_service_started(tab, 7000)
|
||||
self.web_server_is_running(tab)
|
||||
|
||||
def run_all_share_mode_autostop_autostart_mismatch_tests(self, tab):
|
||||
"""Auto-stop timer tests in share mode"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.set_autostart_timer(tab, 15)
|
||||
self.set_timeout(tab, 5)
|
||||
QtCore.QTimer.singleShot(4000, self.accept_dialog)
|
||||
QtTest.QTest.mouseClick(
|
||||
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
||||
)
|
||||
self.server_is_stopped(tab, False)
|
||||
|
||||
def run_all_share_mode_unreadable_file_tests(self, tab):
|
||||
"""Attempt to share an unreadable file"""
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
QtCore.QTimer.singleShot(1000, self.accept_dialog)
|
||||
tab.get_mode().server_status.file_selection.file_list.add_file(
|
||||
"/tmp/nonexistent.txt"
|
||||
)
|
||||
self.file_selection_widget_has_files(tab, 2)
|
||||
|
||||
# Tests
|
||||
|
||||
@pytest.mark.gui
|
||||
def test_common_tests(self):
|
||||
"""Run all common tests"""
|
||||
self.run_all_common_setup_tests()
|
||||
def test_tmp(self):
|
||||
tab = self.new_share_tab()
|
||||
self.run_all_share_mode_setup_tests(tab)
|
||||
self.run_all_share_mode_started_tests(tab)
|
||||
self.run_all_share_mode_download_tests(tab)
|
||||
self.run_all_share_mode_individual_file_download_tests(tab)
|
||||
self.run_all_share_mode_tests(tab)
|
||||
self.run_all_clear_all_button_tests(tab)
|
||||
self.run_all_share_mode_individual_file_tests(tab)
|
||||
self.run_all_large_file_tests(tab)
|
||||
self.run_all_share_mode_persistent_tests(tab)
|
||||
self.run_all_share_mode_timer_tests(tab)
|
||||
self.run_all_share_mode_autostart_timer_tests(tab)
|
||||
self.run_all_share_mode_autostop_autostart_mismatch_tests(tab)
|
||||
self.run_all_share_mode_unreadable_file_tests(tab)
|
||||
|
||||
|
@ -9,54 +9,6 @@ from .gui_base_test import GuiBaseTest
|
||||
class TestTabs(GuiBaseTest):
|
||||
# Shared test methods
|
||||
|
||||
def verify_new_tab(self, tab):
|
||||
# Make sure the new tab widget is showing, and no mode has been started
|
||||
self.assertTrue(tab.new_tab.isVisible())
|
||||
self.assertFalse(hasattr(tab, "share_mode"))
|
||||
self.assertFalse(hasattr(tab, "receive_mode"))
|
||||
self.assertFalse(hasattr(tab, "website_mode"))
|
||||
|
||||
def new_share_tab(self):
|
||||
tab = self.gui.tabs.widget(0)
|
||||
self.verify_new_tab(tab)
|
||||
|
||||
# Share files
|
||||
tab.share_button.click()
|
||||
self.assertFalse(tab.new_tab.isVisible())
|
||||
self.assertTrue(tab.share_mode.isVisible())
|
||||
|
||||
# Add files
|
||||
for filename in self.tmpfiles:
|
||||
tab.share_mode.server_status.file_selection.file_list.add_file(filename)
|
||||
|
||||
return tab
|
||||
|
||||
def new_receive_tab(self):
|
||||
tab = self.gui.tabs.widget(0)
|
||||
self.verify_new_tab(tab)
|
||||
|
||||
# Receive files
|
||||
tab.receive_button.click()
|
||||
self.assertFalse(tab.new_tab.isVisible())
|
||||
self.assertTrue(tab.receive_mode.isVisible())
|
||||
|
||||
return tab
|
||||
|
||||
def new_website_tab(self):
|
||||
tab = self.gui.tabs.widget(0)
|
||||
self.verify_new_tab(tab)
|
||||
|
||||
# Publish website
|
||||
tab.website_button.click()
|
||||
self.assertFalse(tab.new_tab.isVisible())
|
||||
self.assertTrue(tab.website_mode.isVisible())
|
||||
|
||||
# Add files
|
||||
for filename in self.tmpfiles:
|
||||
tab.website_mode.server_status.file_selection.file_list.add_file(filename)
|
||||
|
||||
return tab
|
||||
|
||||
def close_tab_with_active_server(self, tab):
|
||||
# Start the server
|
||||
self.assertEqual(
|
||||
@ -208,7 +160,7 @@ class TestTabs(GuiBaseTest):
|
||||
@pytest.mark.gui
|
||||
def test_07_close_share_tab_while_server_started_should_warn(self):
|
||||
"""Closing a share mode tab when the server is running should throw a warning"""
|
||||
tab = self.new_share_tab()
|
||||
tab = self.new_share_tab_with_files()
|
||||
self.close_tab_with_active_server(tab)
|
||||
|
||||
@pytest.mark.gui
|
||||
@ -220,13 +172,13 @@ class TestTabs(GuiBaseTest):
|
||||
@pytest.mark.gui
|
||||
def test_09_close_website_tab_while_server_started_should_warn(self):
|
||||
"""Closing a website mode tab when the server is running should throw a warning"""
|
||||
tab = self.new_website_tab()
|
||||
tab = self.new_website_tab_with_files()
|
||||
self.close_tab_with_active_server(tab)
|
||||
|
||||
@pytest.mark.gui
|
||||
def test_10_close_persistent_share_tab_shows_warning(self):
|
||||
"""Closing a share mode tab that's persistent should show a warning"""
|
||||
tab = self.new_share_tab()
|
||||
tab = self.new_share_tab_with_files()
|
||||
self.close_persistent_tab(tab)
|
||||
|
||||
@pytest.mark.gui
|
||||
@ -238,7 +190,7 @@ class TestTabs(GuiBaseTest):
|
||||
@pytest.mark.gui
|
||||
def test_12_close_persistent_website_tab_shows_warning(self):
|
||||
"""Closing a website mode tab that's persistent should show a warning"""
|
||||
tab = self.new_website_tab()
|
||||
tab = self.new_website_tab_with_files()
|
||||
self.close_persistent_tab(tab)
|
||||
|
||||
@pytest.mark.gui
|
||||
|
Loading…
Reference in New Issue
Block a user