mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-26 15:59:48 -05:00
Finished test_autostart_timer, and changed more clicks to use .click()
This commit is contained in:
parent
4834e9352f
commit
09104c6a67
@ -136,14 +136,14 @@ class GuiBaseTest(unittest.TestCase):
|
|||||||
def click_toggle_history(self, tab):
|
def click_toggle_history(self, tab):
|
||||||
"""Test that we can toggle Download or Upload history by clicking the toggle button"""
|
"""Test that we can toggle Download or Upload history by clicking the toggle button"""
|
||||||
currently_visible = tab.get_mode().history.isVisible()
|
currently_visible = tab.get_mode().history.isVisible()
|
||||||
QtTest.QTest.mouseClick(tab.get_mode().toggle_history, QtCore.Qt.LeftButton)
|
tab.get_mode().toggle_history.click()
|
||||||
self.assertEqual(tab.get_mode().history.isVisible(), not currently_visible)
|
self.assertEqual(tab.get_mode().history.isVisible(), not currently_visible)
|
||||||
|
|
||||||
def history_indicator(self, tab, 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"""
|
"""Test that we can make sure the history is toggled off, do an action, and the indiciator works"""
|
||||||
# Make sure history is toggled off
|
# Make sure history is toggled off
|
||||||
if tab.get_mode().history.isVisible():
|
if tab.get_mode().history.isVisible():
|
||||||
QtTest.QTest.mouseClick(tab.get_mode().toggle_history, QtCore.Qt.LeftButton)
|
tab.get_mode().toggle_history.click()
|
||||||
self.assertFalse(tab.get_mode().history.isVisible())
|
self.assertFalse(tab.get_mode().history.isVisible())
|
||||||
|
|
||||||
# Indicator should not be visible yet
|
# Indicator should not be visible yet
|
||||||
@ -186,7 +186,7 @@ class GuiBaseTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Toggle history back on, indicator should be hidden again
|
# Toggle history back on, indicator should be hidden again
|
||||||
QtTest.QTest.mouseClick(tab.get_mode().toggle_history, QtCore.Qt.LeftButton)
|
tab.get_mode().toggle_history.click()
|
||||||
self.assertFalse(tab.get_mode().toggle_history.indicator_label.isVisible())
|
self.assertFalse(tab.get_mode().toggle_history.indicator_label.isVisible())
|
||||||
|
|
||||||
def history_is_not_visible(self, tab):
|
def history_is_not_visible(self, tab):
|
||||||
@ -200,9 +200,7 @@ class GuiBaseTest(unittest.TestCase):
|
|||||||
def server_working_on_start_button_pressed(self, tab):
|
def server_working_on_start_button_pressed(self, tab):
|
||||||
"""Test we can start the service"""
|
"""Test we can start the service"""
|
||||||
# Should be in SERVER_WORKING state
|
# Should be in SERVER_WORKING state
|
||||||
QtTest.QTest.mouseClick(
|
tab.get_mode().server_status.server_button.click()
|
||||||
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
|
||||||
)
|
|
||||||
self.assertEqual(tab.get_mode().server_status.status, 1)
|
self.assertEqual(tab.get_mode().server_status.status, 1)
|
||||||
|
|
||||||
def toggle_indicator_is_reset(self, tab):
|
def toggle_indicator_is_reset(self, tab):
|
||||||
@ -258,9 +256,7 @@ class GuiBaseTest(unittest.TestCase):
|
|||||||
"""Test that the Copy URL button is shown and that the clipboard is correct"""
|
"""Test that the Copy URL button is shown and that the clipboard is correct"""
|
||||||
self.assertTrue(tab.get_mode().server_status.copy_url_button.isVisible())
|
self.assertTrue(tab.get_mode().server_status.copy_url_button.isVisible())
|
||||||
|
|
||||||
QtTest.QTest.mouseClick(
|
tab.get_mode().server_status.copy_url_button.click()
|
||||||
tab.get_mode().server_status.copy_url_button, QtCore.Qt.LeftButton
|
|
||||||
)
|
|
||||||
clipboard = tab.common.gui.qtapp.clipboard()
|
clipboard = tab.common.gui.qtapp.clipboard()
|
||||||
if tab.settings.get("general", "public"):
|
if tab.settings.get("general", "public"):
|
||||||
self.assertEqual(clipboard.text(), f"http://127.0.0.1:{tab.app.port}")
|
self.assertEqual(clipboard.text(), f"http://127.0.0.1:{tab.app.port}")
|
||||||
@ -318,17 +314,15 @@ class GuiBaseTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
or (type(tab.get_mode()) == WebsiteMode)
|
or (type(tab.get_mode()) == WebsiteMode)
|
||||||
):
|
):
|
||||||
QtTest.QTest.mouseClick(
|
tab.get_mode().server_status.server_button.click()
|
||||||
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
|
||||||
)
|
|
||||||
self.assertEqual(tab.get_mode().server_status.status, 0)
|
self.assertEqual(tab.get_mode().server_status.status, 0)
|
||||||
|
|
||||||
def web_server_is_stopped(self, tab):
|
def web_server_is_stopped(self, tab):
|
||||||
"""Test that the web server also stopped"""
|
"""Test that the web server also stopped"""
|
||||||
QtTest.QTest.qWait(2000)
|
QtTest.QTest.qWait(200)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.get(f"http://127.0.0.1:{tab.app.port}/")
|
requests.get(f"http://127.0.0.1:{tab.app.port}/")
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
@ -354,9 +348,7 @@ class GuiBaseTest(unittest.TestCase):
|
|||||||
|
|
||||||
def clear_all_history_items(self, tab, count):
|
def clear_all_history_items(self, tab, count):
|
||||||
if count == 0:
|
if count == 0:
|
||||||
QtTest.QTest.mouseClick(
|
tab.get_mode().history.clear_button.click()
|
||||||
tab.get_mode().history.clear_button, QtCore.Qt.LeftButton
|
|
||||||
)
|
|
||||||
self.assertEquals(len(tab.get_mode().history.item_list.items.keys()), count)
|
self.assertEquals(len(tab.get_mode().history.item_list.items.keys()), count)
|
||||||
|
|
||||||
# Auto-stop timer tests
|
# Auto-stop timer tests
|
||||||
|
@ -40,10 +40,7 @@ class TestShare(GuiBaseTest):
|
|||||||
tab.get_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
|
# Click delete, delete button should still be visible since we have one more file
|
||||||
QtTest.QTest.mouseClick(
|
tab.get_mode().server_status.file_selection.delete_button.click()
|
||||||
tab.get_mode().server_status.file_selection.delete_button,
|
|
||||||
QtCore.Qt.LeftButton,
|
|
||||||
)
|
|
||||||
rect = tab.get_mode().server_status.file_selection.file_list.visualItemRect(
|
rect = tab.get_mode().server_status.file_selection.file_list.visualItemRect(
|
||||||
tab.get_mode().server_status.file_selection.file_list.item(0)
|
tab.get_mode().server_status.file_selection.file_list.item(0)
|
||||||
)
|
)
|
||||||
@ -55,10 +52,7 @@ class TestShare(GuiBaseTest):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
tab.get_mode().server_status.file_selection.delete_button.isVisible()
|
tab.get_mode().server_status.file_selection.delete_button.isVisible()
|
||||||
)
|
)
|
||||||
QtTest.QTest.mouseClick(
|
tab.get_mode().server_status.file_selection.delete_button.click()
|
||||||
tab.get_mode().server_status.file_selection.delete_button,
|
|
||||||
QtCore.Qt.LeftButton,
|
|
||||||
)
|
|
||||||
|
|
||||||
# No more files, the delete button should be hidden
|
# No more files, the delete button should be hidden
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
@ -68,10 +62,9 @@ class TestShare(GuiBaseTest):
|
|||||||
def add_a_file_and_delete_using_its_delete_widget(self, tab):
|
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"""
|
"""Test that we can also delete a file by clicking on its [X] widget"""
|
||||||
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[0])
|
||||||
QtTest.QTest.mouseClick(
|
tab.get_mode().server_status.file_selection.file_list.item(
|
||||||
tab.get_mode().server_status.file_selection.file_list.item(0).item_button,
|
0
|
||||||
QtCore.Qt.LeftButton,
|
).item_button.click()
|
||||||
)
|
|
||||||
self.file_selection_widget_has_files(tab, 0)
|
self.file_selection_widget_has_files(tab, 0)
|
||||||
|
|
||||||
def file_selection_widget_read_files(self, tab):
|
def file_selection_widget_read_files(self, tab):
|
||||||
@ -116,7 +109,7 @@ class TestShare(GuiBaseTest):
|
|||||||
f.write(r.content)
|
f.write(r.content)
|
||||||
|
|
||||||
zip = zipfile.ZipFile(tmp_file.name)
|
zip = zipfile.ZipFile(tmp_file.name)
|
||||||
QtTest.QTest.qWait(2000)
|
QtTest.QTest.qWait(50)
|
||||||
self.assertEqual("onionshare", zip.read("test.txt").decode("utf-8"))
|
self.assertEqual("onionshare", zip.read("test.txt").decode("utf-8"))
|
||||||
|
|
||||||
def individual_file_is_viewable_or_not(self, tab):
|
def individual_file_is_viewable_or_not(self, tab):
|
||||||
@ -166,7 +159,7 @@ class TestShare(GuiBaseTest):
|
|||||||
self.assertEqual(r.status_code, 404)
|
self.assertEqual(r.status_code, 404)
|
||||||
self.download_share(tab)
|
self.download_share(tab)
|
||||||
|
|
||||||
QtTest.QTest.qWait(2000)
|
QtTest.QTest.qWait(50)
|
||||||
|
|
||||||
def hit_401(self, tab):
|
def hit_401(self, tab):
|
||||||
"""Test that the server stops after too many 401s, or doesn't when in public_mode"""
|
"""Test that the server stops after too many 401s, or doesn't when in public_mode"""
|
||||||
@ -180,7 +173,7 @@ class TestShare(GuiBaseTest):
|
|||||||
|
|
||||||
# A nasty hack to avoid the Alert dialog that blocks the rest of the test
|
# A nasty hack to avoid the Alert dialog that blocks the rest of the test
|
||||||
if not tab.settings.get("general", "public"):
|
if not tab.settings.get("general", "public"):
|
||||||
QtCore.QTimer.singleShot(1000, self.accept_dialog)
|
QtCore.QTimer.singleShot(0, self.accept_dialog)
|
||||||
|
|
||||||
# In public mode, we should still be running (no rate-limiting)
|
# In public mode, we should still be running (no rate-limiting)
|
||||||
if tab.settings.get("general", "public"):
|
if tab.settings.get("general", "public"):
|
||||||
@ -206,13 +199,13 @@ class TestShare(GuiBaseTest):
|
|||||||
tab.get_mode().mode_settings_widget.autostart_timer_widget.isVisible()
|
tab.get_mode().mode_settings_widget.autostart_timer_widget.isVisible()
|
||||||
)
|
)
|
||||||
|
|
||||||
def scheduled_service_started(self, tab, mode, wait):
|
def scheduled_service_started(self, tab, wait):
|
||||||
"""Test that the server has timed out after the timer ran out"""
|
"""Test that the server has timed out after the timer ran out"""
|
||||||
QtTest.QTest.qWait(wait)
|
QtTest.QTest.qWait(wait)
|
||||||
# We should have started now
|
# We should have started now
|
||||||
self.assertEqual(tab.get_mode().server_status.status, 2)
|
self.assertEqual(tab.get_mode().server_status.status, 2)
|
||||||
|
|
||||||
def cancel_the_share(self, tab, mode):
|
def cancel_the_share(self, tab):
|
||||||
"""Test that we can cancel a share before it's started up """
|
"""Test that we can cancel a share before it's started up """
|
||||||
self.server_working_on_start_button_pressed(tab)
|
self.server_working_on_start_button_pressed(tab)
|
||||||
self.server_status_indicator_says_scheduled(tab)
|
self.server_status_indicator_says_scheduled(tab)
|
||||||
@ -222,7 +215,7 @@ class TestShare(GuiBaseTest):
|
|||||||
QtTest.QTest.mousePress(
|
QtTest.QTest.mousePress(
|
||||||
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
||||||
)
|
)
|
||||||
QtTest.QTest.qWait(2000)
|
QtTest.QTest.qWait(50)
|
||||||
QtTest.QTest.mouseRelease(
|
QtTest.QTest.mouseRelease(
|
||||||
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
tab.get_mode().server_status.server_button, QtCore.Qt.LeftButton
|
||||||
)
|
)
|
||||||
@ -339,7 +332,7 @@ class TestShare(GuiBaseTest):
|
|||||||
def run_all_share_mode_unreadable_file_tests(self, tab):
|
def run_all_share_mode_unreadable_file_tests(self, tab):
|
||||||
"""Attempt to share an unreadable file"""
|
"""Attempt to share an unreadable file"""
|
||||||
self.run_all_share_mode_setup_tests(tab)
|
self.run_all_share_mode_setup_tests(tab)
|
||||||
QtCore.QTimer.singleShot(1000, self.accept_dialog)
|
QtCore.QTimer.singleShot(0, self.accept_dialog)
|
||||||
tab.get_mode().server_status.file_selection.file_list.add_file(
|
tab.get_mode().server_status.file_selection.file_list.add_file(
|
||||||
"/tmp/nonexistent.txt"
|
"/tmp/nonexistent.txt"
|
||||||
)
|
)
|
||||||
@ -353,18 +346,16 @@ class TestShare(GuiBaseTest):
|
|||||||
If autostart timer is after autostop timer, a warning should be thrown
|
If autostart timer is after autostop timer, a warning should be thrown
|
||||||
"""
|
"""
|
||||||
tab = self.new_share_tab()
|
tab = self.new_share_tab()
|
||||||
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
||||||
|
tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()
|
||||||
|
tab.get_mode().mode_settings_widget.autostop_timer_checkbox.click()
|
||||||
|
|
||||||
def accept_dialog():
|
def accept_dialog():
|
||||||
window = tab.common.gui.qtapp.activeWindow()
|
window = tab.common.gui.qtapp.activeWindow()
|
||||||
if window:
|
if window:
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
|
||||||
tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()
|
|
||||||
tab.get_mode().mode_settings_widget.autostop_timer_checkbox.click()
|
|
||||||
|
|
||||||
self.run_all_common_setup_tests()
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
self.run_all_share_mode_setup_tests(tab)
|
self.run_all_share_mode_setup_tests(tab)
|
||||||
self.set_autostart_timer(tab, 15)
|
self.set_autostart_timer(tab, 15)
|
||||||
self.set_timeout(tab, 5)
|
self.set_timeout(tab, 5)
|
||||||
@ -380,15 +371,23 @@ class TestShare(GuiBaseTest):
|
|||||||
Autostart timer should automatically start
|
Autostart timer should automatically start
|
||||||
"""
|
"""
|
||||||
tab = self.new_share_tab()
|
tab = self.new_share_tab()
|
||||||
|
tab.get_mode().mode_settings_widget.toggle_advanced_button.click()
|
||||||
|
tab.get_mode().mode_settings_widget.autostart_timer_checkbox.click()
|
||||||
|
|
||||||
self.run_all_common_setup_tests()
|
self.run_all_common_setup_tests()
|
||||||
|
|
||||||
self.run_all_share_mode_setup_tests(tab)
|
self.run_all_share_mode_setup_tests(tab)
|
||||||
self.set_autostart_timer(tab, 5)
|
self.set_autostart_timer(tab, 2)
|
||||||
self.server_working_on_start_button_pressed(tab)
|
self.server_working_on_start_button_pressed(tab)
|
||||||
self.autostart_timer_widget_hidden(tab)
|
self.autostart_timer_widget_hidden(tab)
|
||||||
self.server_status_indicator_says_scheduled(tab)
|
self.server_status_indicator_says_scheduled(tab)
|
||||||
self.web_server_is_stopped(tab)
|
self.web_server_is_stopped(tab)
|
||||||
self.scheduled_service_started(tab, 7000)
|
self.scheduled_service_started(tab, 2200)
|
||||||
self.web_server_is_running(tab)
|
self.web_server_is_running(tab)
|
||||||
|
QtTest.QTest.qWait(200)
|
||||||
|
tab.get_mode().server_status.server_button.click()
|
||||||
|
QtTest.QTest.qWait(200)
|
||||||
|
self.server_is_stopped(tab)
|
||||||
|
self.web_server_is_stopped(tab)
|
||||||
|
|
||||||
self.close_all_tabs()
|
self.close_all_tabs()
|
||||||
|
Loading…
Reference in New Issue
Block a user