summaryrefslogtreecommitdiff
path: root/tests/SettingsGuiBaseTest.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/SettingsGuiBaseTest.py')
-rw-r--r--tests/SettingsGuiBaseTest.py158
1 files changed, 125 insertions, 33 deletions
diff --git a/tests/SettingsGuiBaseTest.py b/tests/SettingsGuiBaseTest.py
index 35bdd9c6..1aa6da25 100644
--- a/tests/SettingsGuiBaseTest.py
+++ b/tests/SettingsGuiBaseTest.py
@@ -23,17 +23,17 @@ class OnionStub(object):
class SettingsGuiBaseTest(object):
@staticmethod
def set_up():
- '''Create the GUI'''
+ """Create the GUI"""
# Default settings for the settings GUI tests
test_settings = {
- "no_bridges": False,
- "tor_bridges_use_custom_bridges": "Bridge 1.2.3.4:56 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 5.6.7.8:910 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 11.12.13.14:1516 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n",
+ "no_bridges": False,
+ "tor_bridges_use_custom_bridges": "Bridge 1.2.3.4:56 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 5.6.7.8:910 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\nBridge 11.12.13.14:1516 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n",
}
# Create our test file
- testfile = open('/tmp/test.txt', 'w')
- testfile.write('onionshare')
+ testfile = open("/tmp/test.txt", "w")
+ testfile.write("onionshare")
testfile.close()
common = Common()
@@ -51,22 +51,22 @@ class SettingsGuiBaseTest(object):
if key not in test_settings:
test_settings[key] = val
- open('/tmp/settings.json', 'w').write(json.dumps(test_settings))
+ open("/tmp/settings.json", "w").write(json.dumps(test_settings))
- gui = SettingsDialog(common, testonion, qtapp, '/tmp/settings.json', True)
+ gui = SettingsDialog(common, testonion, qtapp, "/tmp/settings.json", True)
return gui
@staticmethod
def tear_down():
- '''Clean up after tests'''
- os.remove('/tmp/settings.json')
+ """Clean up after tests"""
+ os.remove("/tmp/settings.json")
def run_settings_gui_tests(self):
self.gui.show()
# Window is shown
self.assertTrue(self.gui.isVisible())
- self.assertEqual(self.gui.windowTitle(), strings._('gui_settings_window_title'))
+ self.assertEqual(self.gui.windowTitle(), strings._("gui_settings_window_title"))
# Check for updates button is hidden
self.assertFalse(self.gui.check_for_updates_button.isVisible())
@@ -74,13 +74,21 @@ class SettingsGuiBaseTest(object):
# public mode is off
self.assertFalse(self.gui.public_mode_checkbox.isChecked())
# enable public mode
- QtTest.QTest.mouseClick(self.gui.public_mode_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.public_mode_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.public_mode_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.public_mode_checkbox.height() / 2),
+ )
self.assertTrue(self.gui.public_mode_checkbox.isChecked())
# autostop timer is off
self.assertFalse(self.gui.autostop_timer_checkbox.isChecked())
# enable autostop timer
- QtTest.QTest.mouseClick(self.gui.autostop_timer_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.autostop_timer_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.autostop_timer_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.autostop_timer_checkbox.height() / 2),
+ )
self.assertTrue(self.gui.autostop_timer_checkbox.isChecked())
# legacy mode checkbox and related widgets
@@ -96,32 +104,70 @@ class SettingsGuiBaseTest(object):
self.assertFalse(self.gui.hidservauth_copy_button.isVisible())
# enable legacy mode
- QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.use_legacy_v2_onions_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(
+ 2, self.gui.use_legacy_v2_onions_checkbox.height() / 2
+ ),
+ )
self.assertTrue(self.gui.use_legacy_v2_onions_checkbox.isChecked())
self.assertTrue(self.gui.save_private_key_checkbox.isVisible())
self.assertTrue(self.gui.use_stealth_widget.isVisible())
# enable persistent mode
- QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.save_private_key_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(
+ 2, self.gui.save_private_key_checkbox.height() / 2
+ ),
+ )
self.assertTrue(self.gui.save_private_key_checkbox.isChecked())
# enable stealth mode
- QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.stealth_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.stealth_checkbox.height() / 2),
+ )
self.assertTrue(self.gui.stealth_checkbox.isChecked())
# now that stealth is enabled, we can't turn off legacy mode
self.assertFalse(self.gui.use_legacy_v2_onions_checkbox.isEnabled())
# disable stealth, persistence
- QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2))
- QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.save_private_key_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(
+ 2, self.gui.save_private_key_checkbox.height() / 2
+ ),
+ )
+ QtTest.QTest.mouseClick(
+ self.gui.stealth_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.stealth_checkbox.height() / 2),
+ )
# legacy mode checkbox is enabled again
self.assertTrue(self.gui.use_legacy_v2_onions_checkbox.isEnabled())
# uncheck legacy mode
- QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.use_legacy_v2_onions_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(
+ 2, self.gui.use_legacy_v2_onions_checkbox.height() / 2
+ ),
+ )
# legacy options hidden again
self.assertTrue(self.gui.save_private_key_widget.isVisible())
self.assertFalse(self.gui.use_stealth_widget.isVisible())
# re-enable legacy mode
- QtTest.QTest.mouseClick(self.gui.use_legacy_v2_onions_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.use_legacy_v2_onions_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.use_legacy_v2_onions_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(
+ 2, self.gui.use_legacy_v2_onions_checkbox.height() / 2
+ ),
+ )
else:
# legacy mode setting is hidden
@@ -131,8 +177,16 @@ class SettingsGuiBaseTest(object):
self.assertTrue(self.gui.use_stealth_widget.isVisible())
# enable them all again so that we can see the setting stick in settings.json
- QtTest.QTest.mouseClick(self.gui.save_private_key_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.save_private_key_checkbox.height()/2))
- QtTest.QTest.mouseClick(self.gui.stealth_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.stealth_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.save_private_key_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.save_private_key_checkbox.height() / 2),
+ )
+ QtTest.QTest.mouseClick(
+ self.gui.stealth_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.stealth_checkbox.height() / 2),
+ )
else:
# None of the onion settings should appear
self.assertFalse(self.gui.use_legacy_v2_onions_checkbox.isVisible())
@@ -144,12 +198,17 @@ class SettingsGuiBaseTest(object):
# stay open toggled off, on
self.assertTrue(self.gui.close_after_first_download_checkbox.isChecked())
- QtTest.QTest.mouseClick(self.gui.close_after_first_download_checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.close_after_first_download_checkbox.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.close_after_first_download_checkbox,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(
+ 2, self.gui.close_after_first_download_checkbox.height() / 2
+ ),
+ )
self.assertFalse(self.gui.close_after_first_download_checkbox.isChecked())
# receive mode
- self.gui.data_dir_lineedit.setText('/tmp/OnionShareSettingsTest')
-
+ self.gui.data_dir_lineedit.setText("/tmp/OnionShareSettingsTest")
# bundled mode is enabled
self.assertTrue(self.gui.connection_type_bundled_radio.isEnabled())
@@ -161,7 +220,11 @@ class SettingsGuiBaseTest(object):
self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked())
# switch to obfs4
- QtTest.QTest.mouseClick(self.gui.tor_bridges_use_obfs4_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_obfs4_radio.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.tor_bridges_use_obfs4_radio,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.tor_bridges_use_obfs4_radio.height() / 2),
+ )
self.assertTrue(self.gui.tor_bridges_use_obfs4_radio.isChecked())
# custom bridges are hidden
@@ -175,7 +238,11 @@ class SettingsGuiBaseTest(object):
self.assertFalse(self.gui.connection_type_socket_file_radio.isChecked())
# enable automatic mode
- QtTest.QTest.mouseClick(self.gui.connection_type_automatic_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_automatic_radio.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.connection_type_automatic_radio,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.connection_type_automatic_radio.height() / 2),
+ )
self.assertTrue(self.gui.connection_type_automatic_radio.isChecked())
# bundled is off
self.assertFalse(self.gui.connection_type_bundled_radio.isChecked())
@@ -187,7 +254,13 @@ class SettingsGuiBaseTest(object):
self.assertFalse(self.gui.authenticate_password_radio.isVisible())
# enable control port mode
- QtTest.QTest.mouseClick(self.gui.connection_type_control_port_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_control_port_radio.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.connection_type_control_port_radio,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(
+ 2, self.gui.connection_type_control_port_radio.height() / 2
+ ),
+ )
self.assertTrue(self.gui.connection_type_control_port_radio.isChecked())
# automatic is off
self.assertFalse(self.gui.connection_type_automatic_radio.isChecked())
@@ -196,7 +269,13 @@ class SettingsGuiBaseTest(object):
self.assertTrue(self.gui.authenticate_password_radio.isVisible())
# enable socket mode
- QtTest.QTest.mouseClick(self.gui.connection_type_socket_file_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_socket_file_radio.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.connection_type_socket_file_radio,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(
+ 2, self.gui.connection_type_socket_file_radio.height() / 2
+ ),
+ )
self.assertTrue(self.gui.connection_type_socket_file_radio.isChecked())
# control port is off
self.assertFalse(self.gui.connection_type_control_port_radio.isChecked())
@@ -205,20 +284,30 @@ class SettingsGuiBaseTest(object):
self.assertTrue(self.gui.authenticate_password_radio.isVisible())
# re-enable bundled mode
- QtTest.QTest.mouseClick(self.gui.connection_type_bundled_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.connection_type_bundled_radio.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.connection_type_bundled_radio,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.connection_type_bundled_radio.height() / 2),
+ )
# go back to custom bridges
- QtTest.QTest.mouseClick(self.gui.tor_bridges_use_custom_radio, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2,self.gui.tor_bridges_use_custom_radio.height()/2))
+ QtTest.QTest.mouseClick(
+ self.gui.tor_bridges_use_custom_radio,
+ QtCore.Qt.LeftButton,
+ pos=QtCore.QPoint(2, self.gui.tor_bridges_use_custom_radio.height() / 2),
+ )
self.assertTrue(self.gui.tor_bridges_use_custom_radio.isChecked())
self.assertTrue(self.gui.tor_bridges_use_custom_textbox.isVisible())
self.assertFalse(self.gui.tor_bridges_use_obfs4_radio.isChecked())
- self.gui.tor_bridges_use_custom_textbox.setPlainText('94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\n148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\n93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3')
+ self.gui.tor_bridges_use_custom_textbox.setPlainText(
+ "94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\n148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\n93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3"
+ )
# Test that the Settings Dialog can save the settings and close itself
QtTest.QTest.mouseClick(self.gui.save_button, QtCore.Qt.LeftButton)
self.assertFalse(self.gui.isVisible())
# Test our settings are reflected in the settings json
- with open('/tmp/settings.json') as f:
+ with open("/tmp/settings.json") as f:
data = json.load(f)
self.assertTrue(data["public_mode"])
@@ -238,4 +327,7 @@ class SettingsGuiBaseTest(object):
self.assertFalse(data["close_after_first_download"])
self.assertEqual(data["connection_type"], "bundled")
self.assertFalse(data["tor_bridges_use_obfs4"])
- self.assertEqual(data["tor_bridges_use_custom_bridges"], "Bridge 94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\nBridge 148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\nBridge 93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3\n")
+ self.assertEqual(
+ data["tor_bridges_use_custom_bridges"],
+ "Bridge 94.242.249.2:83 E25A95F1DADB739F0A83EB0223A37C02FD519306\nBridge 148.251.90.59:7510 019F727CA6DCA6CA5C90B55E477B7D87981E75BC\nBridge 93.80.47.217:41727 A6A0D497D98097FCFE91D639548EE9E34C15CDD3\n",
+ )