2018-09-22 03:47:38 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
import pytest
|
|
|
|
import json
|
|
|
|
|
2018-09-23 20:41:48 -04:00
|
|
|
from PyQt5 import QtWidgets
|
2018-09-22 03:47:38 -04:00
|
|
|
|
|
|
|
from onionshare.common import Common
|
|
|
|
from onionshare.web import Web
|
|
|
|
from onionshare import onion, strings
|
|
|
|
from onionshare_gui import *
|
|
|
|
|
2018-09-23 20:41:48 -04:00
|
|
|
from .commontests import CommonTests
|
|
|
|
|
2018-09-22 03:47:38 -04:00
|
|
|
class OnionShareGuiTest(unittest.TestCase):
|
|
|
|
'''Test the OnionShare GUI'''
|
|
|
|
slug = ''
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
'''Create the GUI'''
|
|
|
|
# Create our test file
|
|
|
|
testfile = open('/tmp/test.txt', 'w')
|
|
|
|
testfile.write('onionshare')
|
|
|
|
testfile.close()
|
|
|
|
common = Common()
|
|
|
|
common.define_css()
|
|
|
|
|
|
|
|
# Start the Onion
|
|
|
|
strings.load_strings(common)
|
|
|
|
|
|
|
|
testonion = onion.Onion(common)
|
|
|
|
global qtapp
|
|
|
|
qtapp = Application(common)
|
|
|
|
app = OnionShare(common, testonion, True, 0)
|
|
|
|
|
|
|
|
web = Web(common, False, True)
|
|
|
|
|
|
|
|
test_settings = {
|
|
|
|
"auth_password": "",
|
|
|
|
"auth_type": "no_auth",
|
|
|
|
"autoupdate_timestamp": "",
|
|
|
|
"close_after_first_download": True,
|
|
|
|
"connection_type": "bundled",
|
|
|
|
"control_port_address": "127.0.0.1",
|
|
|
|
"control_port_port": 9051,
|
|
|
|
"downloads_dir": "/tmp/OnionShare",
|
|
|
|
"hidservauth_string": "",
|
2018-09-27 20:34:46 -04:00
|
|
|
"no_bridges": True,
|
2018-09-22 03:47:38 -04:00
|
|
|
"private_key": "",
|
|
|
|
"public_mode": False,
|
|
|
|
"receive_allow_receiver_shutdown": True,
|
|
|
|
"save_private_key": True,
|
|
|
|
"shutdown_timeout": False,
|
|
|
|
"slug": "",
|
|
|
|
"socks_address": "127.0.0.1",
|
|
|
|
"socks_port": 9050,
|
|
|
|
"socket_file_path": "/var/run/tor/control",
|
|
|
|
"systray_notifications": True,
|
|
|
|
"tor_bridges_use_meek_lite_azure": False,
|
|
|
|
"tor_bridges_use_meek_lite_amazon": False,
|
|
|
|
"tor_bridges_use_custom_bridges": "",
|
|
|
|
"tor_bridges_use_obfs4": False,
|
|
|
|
"use_stealth": False,
|
|
|
|
"use_legacy_v2_onions": False,
|
|
|
|
"use_autoupdate": True,
|
|
|
|
"version": "1.3.1"
|
|
|
|
}
|
|
|
|
testsettings = '/tmp/testsettings.json'
|
|
|
|
open(testsettings, 'w').write(json.dumps(test_settings))
|
|
|
|
|
|
|
|
cls.gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], testsettings, True)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
'''Clean up after tests'''
|
|
|
|
os.remove('/tmp/test.txt')
|
|
|
|
|
|
|
|
@pytest.mark.run(order=1)
|
|
|
|
def test_gui_loaded(self):
|
2018-09-23 20:41:48 -04:00
|
|
|
CommonTests.test_gui_loaded(self)
|
2018-09-22 03:47:38 -04:00
|
|
|
|
|
|
|
@pytest.mark.run(order=2)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_windowTitle_seen(self):
|
|
|
|
CommonTests.test_windowTitle_seen(self)
|
2018-09-22 03:47:38 -04:00
|
|
|
|
|
|
|
@pytest.mark.run(order=3)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_settings_button_is_visible(self):
|
|
|
|
CommonTests.test_settings_button_is_visible(self)
|
2018-09-22 03:47:38 -04:00
|
|
|
|
|
|
|
@pytest.mark.run(order=4)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_server_status_bar_is_visible(self):
|
|
|
|
CommonTests.test_server_status_bar_is_visible(self)
|
2018-09-22 03:47:38 -04:00
|
|
|
|
|
|
|
@pytest.mark.run(order=6)
|
2018-09-29 21:24:11 -04:00
|
|
|
def test_info_widget_shows_less(self):
|
|
|
|
CommonTests.test_info_widget_shows_less(self, 'share')
|
|
|
|
|
|
|
|
@pytest.mark.run(order=7)
|
|
|
|
def test_history_is_not_visible(self):
|
|
|
|
CommonTests.test_history_is_not_visible(self, 'share')
|
|
|
|
|
|
|
|
@pytest.mark.run(order=8)
|
|
|
|
def test_click_toggle_history(self):
|
|
|
|
CommonTests.test_click_toggle_history(self, 'share')
|
|
|
|
|
|
|
|
@pytest.mark.run(order=9)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_history_is_visible(self):
|
|
|
|
CommonTests.test_history_is_visible(self, 'share')
|
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=10)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_server_working_on_start_button_pressed(self):
|
|
|
|
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
|
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=11)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_server_status_indicator_says_starting(self):
|
|
|
|
CommonTests.test_server_status_indicator_says_starting(self, 'share')
|
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=12)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_settings_button_is_hidden(self):
|
|
|
|
CommonTests.test_settings_button_is_hidden(self)
|
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=13)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_a_server_is_started(self):
|
|
|
|
CommonTests.test_a_server_is_started(self, 'share')
|
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=14)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_a_web_server_is_running(self):
|
|
|
|
CommonTests.test_a_web_server_is_running(self)
|
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=15)
|
2018-09-22 03:47:38 -04:00
|
|
|
def test_have_a_slug(self):
|
2018-09-23 20:41:48 -04:00
|
|
|
CommonTests.test_have_a_slug(self, 'share', False)
|
2018-09-22 03:47:38 -04:00
|
|
|
global slug
|
|
|
|
slug = self.gui.share_mode.server_status.web.slug
|
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=16)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_server_status_indicator_says_started(self):
|
|
|
|
CommonTests.test_server_status_indicator_says_started(self, 'share')
|
2018-09-22 03:47:38 -04:00
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=17)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_server_is_stopped(self):
|
|
|
|
CommonTests.test_server_is_stopped(self, 'share', True)
|
2018-09-22 03:47:38 -04:00
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=18)
|
2018-09-22 03:47:38 -04:00
|
|
|
def test_web_service_is_stopped(self):
|
2018-09-23 20:41:48 -04:00
|
|
|
CommonTests.test_web_service_is_stopped(self)
|
2018-09-22 03:47:38 -04:00
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=19)
|
2018-09-23 20:41:48 -04:00
|
|
|
def test_server_status_indicator_says_closed(self):
|
|
|
|
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
|
2018-09-22 03:47:38 -04:00
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=20)
|
2018-09-22 03:47:38 -04:00
|
|
|
def test_server_started_again(self):
|
2018-09-23 20:41:48 -04:00
|
|
|
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
|
|
|
|
CommonTests.test_server_status_indicator_says_starting(self, 'share')
|
|
|
|
CommonTests.test_a_server_is_started(self, 'share')
|
2018-09-22 03:47:38 -04:00
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=21)
|
2018-09-22 03:47:38 -04:00
|
|
|
def test_have_same_slug(self):
|
|
|
|
'''Test that we have the same slug'''
|
|
|
|
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
|
|
|
|
|
2018-09-29 21:24:11 -04:00
|
|
|
@pytest.mark.run(order=22)
|
2018-09-22 03:47:38 -04:00
|
|
|
def test_server_is_stopped_again(self):
|
2018-09-23 20:41:48 -04:00
|
|
|
CommonTests.test_server_is_stopped(self, 'share', True)
|
|
|
|
CommonTests.test_web_service_is_stopped(self)
|
|
|
|
|
2018-09-22 03:47:38 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|