mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Add better workaround for blocking QDialogs. Add unreadable file test and reinstate tor connection killed test
This commit is contained in:
parent
dbbc9c0c82
commit
c79eedd626
@ -303,6 +303,11 @@ class GuiBaseTest(object):
|
||||
# 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()
|
||||
|
||||
# 'Grouped' tests follow from here
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import os
|
||||
import requests
|
||||
from PyQt5 import QtTest
|
||||
from PyQt5 import QtCore, QtTest
|
||||
from .GuiBaseTest import GuiBaseTest
|
||||
|
||||
class GuiReceiveTest(GuiBaseTest):
|
||||
@ -24,8 +24,7 @@ class GuiReceiveTest(GuiBaseTest):
|
||||
path = 'http://127.0.0.1:{}/upload'.format(self.gui.app.port)
|
||||
response = requests.post(path, files=files)
|
||||
|
||||
# A nasty hack to avoid the Alert dialog that blocks the rest of the test
|
||||
self.gui.qtapp.exit()
|
||||
QtCore.QTimer.singleShot(1000, self.accept_dialog)
|
||||
self.assertTrue('Error uploading, please inform the OnionShare user' in response.text)
|
||||
|
||||
def upload_dir_permissions(self, mode=0o755):
|
||||
|
@ -13,9 +13,9 @@ class GuiShareTest(GuiBaseTest):
|
||||
|
||||
# Share-specific tests
|
||||
|
||||
def file_selection_widget_has_files(self):
|
||||
'''Test that the number of items in the list is 2'''
|
||||
self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2)
|
||||
def file_selection_widget_has_files(self, 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)
|
||||
|
||||
|
||||
def deleting_all_files_hides_delete_button(self):
|
||||
@ -40,14 +40,14 @@ class GuiShareTest(GuiBaseTest):
|
||||
'''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')
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.file_selection.file_list.item(0).item_button, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 0)
|
||||
self.file_selection_widget_has_files(0)
|
||||
|
||||
|
||||
def file_selection_widget_readd_files(self):
|
||||
'''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.assertEqual(self.gui.share_mode.server_status.file_selection.get_num_files(), 2)
|
||||
self.file_selection_widget_has_files(2)
|
||||
|
||||
|
||||
def add_large_file(self):
|
||||
@ -102,7 +102,7 @@ class GuiShareTest(GuiBaseTest):
|
||||
|
||||
# A nasty hack to avoid the Alert dialog that blocks the rest of the test
|
||||
if not public_mode:
|
||||
self.gui.qtapp.exit()
|
||||
QtCore.QTimer.singleShot(1000, self.accept_dialog)
|
||||
|
||||
# In public mode, we should still be running (no rate-limiting)
|
||||
if public_mode:
|
||||
@ -195,3 +195,10 @@ class GuiShareTest(GuiBaseTest):
|
||||
self.server_timed_out(self.gui.share_mode, 10000)
|
||||
self.web_server_is_stopped()
|
||||
|
||||
|
||||
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)
|
||||
|
@ -162,3 +162,12 @@ class TorGuiBaseTest(GuiBaseTest):
|
||||
def hidserv_auth_string(self):
|
||||
'''Test the validity of the HidservAuth string'''
|
||||
self.assertRegex(self.gui.app.auth_string, r'HidServAuth {} [a-zA-Z1-9]'.format(self.gui.app.onion_host))
|
||||
|
||||
|
||||
|
||||
# Miscellaneous tests
|
||||
def tor_killed_statusbar_message_shown(self, mode):
|
||||
'''Test that the status bar message shows Tor was disconnected'''
|
||||
self.gui.app.onion.c = None
|
||||
QtTest.QTest.qWait(1000)
|
||||
self.assertTrue(mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))
|
||||
|
31
tests/local_onionshare_share_mode_timer_too_short_test.py
Normal file
31
tests/local_onionshare_share_mode_timer_too_short_test.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
from PyQt5 import QtCore, QtTest
|
||||
|
||||
from .GuiShareTest import GuiShareTest
|
||||
|
||||
class LocalShareModeTimerTooShortTest(unittest.TestCase, GuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"public_mode": False,
|
||||
"shutdown_timeout": True,
|
||||
}
|
||||
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTooShortTest')
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
GuiShareTest.tear_down()
|
||||
|
||||
def test_gui(self):
|
||||
self.run_all_common_setup_tests()
|
||||
self.run_all_share_mode_setup_tests()
|
||||
# Set a low timeout
|
||||
self.set_timeout(self.gui.share_mode, 2)
|
||||
QtTest.QTest.qWait(3000)
|
||||
QtCore.QTimer.singleShot(4000, self.accept_dialog)
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
self.assertEqual(self.gui.share_mode.server_status.status, 0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
22
tests/local_onionshare_share_mode_unreadable_file_test.py
Normal file
22
tests/local_onionshare_share_mode_unreadable_file_test.py
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
|
||||
from .GuiShareTest import GuiShareTest
|
||||
|
||||
class LocalShareModeUnReadableFileTest(unittest.TestCase, GuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
}
|
||||
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeUnReadableFileTest')
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
GuiShareTest.tear_down()
|
||||
|
||||
def test_gui(self):
|
||||
self.run_all_common_setup_tests()
|
||||
self.run_all_share_mode_unreadable_file_tests()
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
25
tests/onionshare_share_mode_tor_connection_killed_test.py
Normal file
25
tests/onionshare_share_mode_tor_connection_killed_test.py
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from .TorGuiShareTest import TorGuiShareTest
|
||||
|
||||
class ShareModeTorConnectionKilledTest(unittest.TestCase, TorGuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
}
|
||||
cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTorConnectionKilledTest')
|
||||
|
||||
@pytest.mark.tor
|
||||
def test_gui(self):
|
||||
self.run_all_common_setup_tests()
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.run_all_share_mode_started_tests(False)
|
||||
self.tor_killed_statusbar_message_shown(self.gui.share_mode)
|
||||
self.server_is_stopped(self.gui.share_mode, False)
|
||||
self.web_server_is_stopped()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user