Beginning to move the Tor tests into tests_gui and inheriting what we can from the local tests to avoid code reuse. Add --runtor flag in pytest to run these

This commit is contained in:
Miguel Jacq 2018-10-12 18:53:03 +11:00
parent 7d8a47a53a
commit b758ac4d0a
No known key found for this signature in database
GPG key ID: EEA4341C6D97A0B6
37 changed files with 544 additions and 1968 deletions

View file

@ -20,4 +20,4 @@ before_script:
# run CLI tests and local GUI tests
script:
- pytest --cov=onionshare tests/
- xvfb-run pytest tests_gui_local/
- xvfb-run pytest tests_gui/ -vvv

View file

@ -120,7 +120,7 @@ class GuiBaseTest(object):
if public_mode:
url = "http://127.0.0.1:{}/download".format(self.gui.app.port)
else:
url = "http://127.0.0.1:{}/{}/download".format(self.gui.app.port, self.gui.share_mode.web.slug)
url = "http://127.0.0.1:{}/{}/download".format(self.gui.app.port, mode.web.slug)
r = requests.get(url)
QtTest.QTest.qWait(2000)

View file

@ -125,11 +125,11 @@ class GuiShareTest(GuiBaseTest):
self.url_description_shown(self.gui.share_mode)
self.have_copy_url_button(self.gui.share_mode)
self.server_status_indicator_says_started(self.gui.share_mode)
self.web_page(self.gui.share_mode, 'Total size', public_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)

154
tests_gui/TorGuiBaseTest.py Normal file
View file

@ -0,0 +1,154 @@
import json
import os
import requests
import shutil
import socket
import socks
from PyQt5 import QtCore, QtTest
from onionshare import strings
from onionshare.common import Common
from onionshare.settings import Settings
from onionshare.onion import Onion
from onionshare.web import Web
from onionshare_gui import Application, OnionShare, OnionShareGui
from onionshare_gui.mode.share_mode import ShareMode
from onionshare_gui.mode.receive_mode import ReceiveMode
from .GuiBaseTest import GuiBaseTest
class TorGuiBaseTest(GuiBaseTest):
@staticmethod
def set_up(test_settings, settings_filename):
'''Create GUI with given settings'''
# Create our test file
testfile = open('/tmp/test.txt', 'w')
testfile.write('onionshare')
testfile.close()
common = Common()
common.settings = Settings(common)
common.define_css()
strings.load_strings(common)
# Get all of the settings in test_settings
test_settings['connection_type'] = 'automatic'
test_settings['downloads_dir'] = '/tmp/OnionShare'
for key, val in common.settings.default_settings.items():
if key not in test_settings:
test_settings[key] = val
# Start the Onion
testonion = Onion(common)
global qtapp
qtapp = Application(common)
app = OnionShare(common, testonion, False, 0)
web = Web(common, False, False)
open('/tmp/{}.json'.format(settings_filename), 'w').write(json.dumps(test_settings))
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], '/tmp/{}.json'.format(settings_filename), False)
return gui
def history_indicator(self, mode, public_mode):
'''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())
# Indicator should not be visible yet
self.assertFalse(mode.toggle_history.indicator_label.isVisible())
# Set up connecting to the onion
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
if type(mode) == ReceiveMode:
# Upload a file
files = {'file[]': open('/tmp/test.txt', 'rb')}
if not public_mode:
path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, mode.web.slug)
else:
path = 'http://{}/upload'.format(self.gui.app.onion_host)
response = session.post(path, files=files)
QtTest.QTest.qWait(4000)
if type(mode) == ShareMode:
# Download files
if public_mode:
path = "http://{}/download".format(self.gui.app.onion_host)
else:
path = "http://{}/{}/download".format(self.gui.app.onion_host, mode.web.slug)
response = session.get(path)
QtTest.QTest.qWait(4000)
# 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(), "1")
# 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())
def a_server_is_started(self, mode):
'''Test that the server has started (overriding from local tests to wait for longer)'''
QtTest.QTest.qWait(45000)
# Should now be in SERVER_STARTED state
self.assertEqual(mode.server_status.status, 2)
def have_an_onion_service(self):
'''Test that we have a valid Onion URL'''
self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion')
def web_page(self, mode, string, public_mode):
'''Test that the web page contains a string'''
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
socks.set_default_proxy(socks.SOCKS5, socks_address, socks_port)
s = socks.socksocket()
s.settimeout(60)
s.connect((self.gui.app.onion_host, 80))
if not public_mode:
path = '/{}'.format(mode.server_status.web.slug)
else:
path = '/'
http_request = 'GET {} HTTP/1.0\r\n'.format(path)
http_request += 'Host: {}\r\n'.format(self.gui.app.onion_host)
http_request += '\r\n'
s.sendall(http_request.encode('utf-8'))
with open('/tmp/webpage', 'wb') as file_to_write:
while True:
data = s.recv(1024)
if not data:
break
file_to_write.write(data)
file_to_write.close()
f = open('/tmp/webpage')
self.assertTrue(string in f.read())
f.close()
def cancel_the_share(self, mode):
'''Test that we can cancel this share before it's started up '''
QtTest.QTest.mousePress(self.gui.mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(1000)
QtTest.QTest.mouseRelease(self.gui.mode.server_status.server_button, QtCore.Qt.LeftButton)
self.assertEqual(self.gui.mode.server_status.status, 0)
# Stealth tests
def copy_have_hidserv_auth_button(self, mode):
'''Test that the Copy HidservAuth button is shown'''
self.assertTrue(mode.server_status.copy_hidservauth_button.isVisible())
def hidserv_auth_string(self):
'''Test the validity of the HidservAuth string'''
self.assertRegex(self.gui.app.auth_string, r'HidServAuth %s [a-zA-Z1-9]' % 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.cleanup(stop_tor=True)
QtTest.QTest.qWait(2500)
self.assertTrue(mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))

View file

@ -0,0 +1,51 @@
import os
import requests
from PyQt5 import QtTest
from .TorGuiBaseTest import TorGuiBaseTest
class TorGuiReceiveTest(TorGuiBaseTest):
def upload_file(self, public_mode, expected_file):
'''Test that we can upload the file'''
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
files = {'file[]': open('/tmp/test.txt', 'rb')}
if not public_mode:
path = 'http://{}/{}/upload'.format(self.gui.app.onion_host, self.gui.receive_mode.web.slug)
else:
path = 'http://{}/upload'.format(self.gui.app.onion_host)
response = session.post(path, files=files)
QtTest.QTest.qWait(4000)
self.assertTrue(os.path.isfile(expected_file))
def run_all_receive_mode_tests(self, public_mode, receive_allow_receiver_shutdown):
self.click_mode(self.gui.receive_mode)
self.history_is_not_visible(self.gui.receive_mode)
self.click_toggle_history(self.gui.receive_mode)
self.history_is_visible(self.gui.receive_mode)
self.server_working_on_start_button_pressed(self.gui.receive_mode)
self.server_status_indicator_says_starting(self.gui.receive_mode)
self.settings_button_is_hidden()
self.a_server_is_started(self.gui.receive_mode)
self.a_web_server_is_running()
self.have_an_onion_service()
self.have_a_slug(self.gui.receive_mode, public_mode)
self.url_description_shown(self.gui.receive_mode)
self.have_copy_url_button(self.gui.receive_mode)
self.server_status_indicator_says_started(self.gui.receive_mode)
self.web_page(self.gui.receive_mode, 'Select the files you want to send, then click', public_mode)
self.upload_file(public_mode, '/tmp/OnionShare/test.txt')
self.history_widgets_present(self.gui.receive_mode)
self.counter_incremented(self.gui.receive_mode, 1)
self.upload_file(public_mode, '/tmp/OnionShare/test-2.txt')
self.counter_incremented(self.gui.receive_mode, 2)
self.history_indicator(self.gui.receive_mode, public_mode)
self.server_is_stopped(self.gui.receive_mode, False)
self.web_service_is_stopped()
self.server_status_indicator_says_closed(self.gui.receive_mode, False)
self.server_working_on_start_button_pressed(self.gui.receive_mode)
self.a_server_is_started(self.gui.receive_mode)
self.history_indicator(self.gui.receive_mode, public_mode)

View file

@ -0,0 +1,70 @@
import requests
import socks
import zipfile
from PyQt5 import QtCore, QtTest
from .TorGuiBaseTest import TorGuiBaseTest
from .GuiShareTest import GuiShareTest
class TorGuiShareTest(TorGuiBaseTest, GuiShareTest):
def download_share(self, public_mode):
# Set up connecting to the onion
(socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
session = requests.session()
session.proxies = {}
session.proxies['http'] = 'socks5h://{}:{}'.format(socks_address, socks_port)
# Download files
if public_mode:
path = "http://{}/download".format(self.gui.app.onion_host)
else:
path = "http://{}/{}/download".format(self.gui.app.onion_host, self.gui.share_mode.web.slug)
response = session.get(path, stream=True)
QtTest.QTest.qWait(4000)
if response.status_code == 200:
with open('/tmp/download.zip', 'wb') as file_to_write:
for chunk in response.iter_content(chunk_size=128):
file_to_write.write(chunk)
file_to_write.close()
zip = zipfile.ZipFile('/tmp/download.zip')
QtTest.QTest.qWait(4000)
self.assertEquals('onionshare', zip.read('test.txt').decode('utf-8'))
# Persistence tests
def have_same_onion(self, onion):
'''Test that we have the same onion'''
self.assertEqual(self.gui.app.onion_host, onion)
def run_all_share_mode_started_tests(self, public_mode):
"""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.a_server_is_started(self.gui.share_mode)
self.a_web_server_is_running()
self.have_an_onion_service()
self.have_a_slug(self.gui.share_mode, public_mode)
self.url_description_shown(self.gui.share_mode)
self.have_copy_url_button(self.gui.share_mode)
self.server_status_indicator_says_started(self.gui.share_mode)
def run_all_share_mode_persistent_tests(self, public_mode, stay_open):
"""Same as end-to-end share tests but also test the slug is the same on multiple shared"""
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(public_mode)
slug = self.gui.share_mode.server_status.web.slug
onion = self.gui.app.onion_host
self.run_all_share_mode_download_tests(public_mode, stay_open)
self.have_same_onion(onion)
self.have_same_slug(slug)
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.timeout_widget_hidden(self.gui.share_mode)
self.server_timed_out(self.gui.share_mode, 10000)
self.web_service_is_stopped()

View file

@ -10,6 +10,22 @@ import pytest
from onionshare import common, web, settings
def pytest_addoption(parser):
parser.addoption(
"--runtor", action="store_true", default=False, help="run tor tests"
)
def pytest_collection_modifyitems(config, items):
if config.getoption("--runtor"):
# --runtor given in cli: do not skip tor tests
return
skip_tor = pytest.mark.skip(reason="need --runtor option to run")
for item in items:
if "tor" in item.keywords:
item.add_marker(skip_tor)
@pytest.fixture
def temp_dir_1024():
""" Create a temporary directory that has a single file of a

View file

@ -4,14 +4,14 @@ import unittest
from .GuiReceiveTest import GuiReceiveTest
class ReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest):
class LocalReceiveModePublicModeTest(unittest.TestCase, GuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
"receive_allow_receiver_shutdown": True
}
cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModePublicModeTest')
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModePublicModeTest')
@pytest.mark.run(order=1)
def test_run_all_common_setup_tests(self):

View file

@ -4,13 +4,13 @@ import unittest
from .GuiReceiveTest import GuiReceiveTest
class ReceiveModeTest(unittest.TestCase, GuiReceiveTest):
class LocalReceiveModeTest(unittest.TestCase, GuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
"receive_allow_receiver_shutdown": True
}
cls.gui = GuiReceiveTest.set_up(test_settings, 'ReceiveModeTest')
cls.gui = GuiReceiveTest.set_up(test_settings, 'LocalReceiveModeTest')
@pytest.mark.run(order=1)
def test_run_all_common_setup_tests(self):

View file

@ -4,13 +4,13 @@ import unittest
from .GuiShareTest import GuiShareTest
class ShareModePublicModeTest(unittest.TestCase, GuiShareTest):
class LocalShareModePublicModeTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
}
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePublicModeTest')
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePublicModeTest')
@pytest.mark.run(order=1)
def test_run_all_common_setup_tests(self):

View file

@ -4,13 +4,13 @@ import unittest
from .GuiShareTest import GuiShareTest
class ShareModeStayOpenTest(unittest.TestCase, GuiShareTest):
class LocalShareModeStayOpenTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": False,
}
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest')
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeStayOpenTest')
@pytest.mark.run(order=1)
def test_run_all_common_setup_tests(self):

View file

@ -4,12 +4,12 @@ import unittest
from .GuiShareTest import GuiShareTest
class ShareModeTest(unittest.TestCase, GuiShareTest):
class LocalShareModeTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTest')
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTest')
@pytest.mark.run(order=1)
def test_run_all_common_setup_tests(self):

View file

@ -4,7 +4,7 @@ import unittest
from .GuiShareTest import GuiShareTest
class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest):
class LocalShareModePersistentSlugTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
@ -13,7 +13,7 @@ class ShareModePersistentSlugTest(unittest.TestCase, GuiShareTest):
"save_private_key": True,
"close_after_first_download": False,
}
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest')
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModePersistentSlugTest')
@pytest.mark.run(order=1)
def test_run_all_common_setup_tests(self):

View file

@ -4,14 +4,14 @@ import unittest
from .GuiShareTest import GuiShareTest
class ShareModeTimerTest(unittest.TestCase, GuiShareTest):
class LocalShareModeTimerTest(unittest.TestCase, GuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": False,
"shutdown_timeout": True,
}
cls.gui = GuiShareTest.set_up(test_settings, 'ShareModeTimerTest')
cls.gui = GuiShareTest.set_up(test_settings, 'LocalShareModeTimerTest')
@pytest.mark.run(order=1)
def test_run_all_common_setup_tests(self):

View file

@ -0,0 +1,27 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiReceiveTest import TorGuiReceiveTest
class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
"receive_allow_receiver_shutdown": True
}
cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest')
@pytest.mark.run(order=1)
@pytest.mark.tor
def test_run_all_common_setup_tests(self):
self.run_all_common_setup_tests()
@pytest.mark.run(order=2)
@pytest.mark.tor
def test_run_all_receive_mode_tests(self):
self.run_all_receive_mode_tests(True, True)
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiReceiveTest import TorGuiReceiveTest
class ReceiveModeTest(unittest.TestCase, TorGuiReceiveTest):
@classmethod
def setUpClass(cls):
test_settings = {
"receive_allow_receiver_shutdown": True
}
cls.gui = TorGuiReceiveTest.set_up(test_settings, 'ReceiveModeTest')
@pytest.mark.run(order=1)
@pytest.mark.tor
def test_run_all_common_setup_tests(self):
self.run_all_common_setup_tests()
@pytest.mark.run(order=2)
@pytest.mark.tor
def test_run_all_receive_mode_tests(self):
self.run_all_receive_mode_tests(False, True)
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModePublicModeTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"public_mode": True,
}
cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePublicModeTest')
@pytest.mark.run(order=1)
@pytest.mark.tor
def test_run_all_common_setup_tests(self):
self.run_all_common_setup_tests()
@pytest.mark.run(order=2)
@pytest.mark.tor
def test_run_all_share_mode_tests(self):
self.run_all_share_mode_tests(True, False)
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeStayOpenTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"close_after_first_download": False,
}
cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStayOpenTest')
@pytest.mark.run(order=1)
@pytest.mark.tor
def test_run_all_common_setup_tests(self):
self.run_all_common_setup_tests()
@pytest.mark.run(order=2)
@pytest.mark.tor
def test_run_all_share_mode_tests(self):
self.run_all_share_mode_tests(False, True)
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
}
cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeTest')
@pytest.mark.run(order=1)
@pytest.mark.tor
def test_run_all_common_setup_tests(self):
self.run_all_common_setup_tests()
@pytest.mark.run(order=2)
@pytest.mark.tor
def test_run_all_share_mode_tests(self):
self.run_all_share_mode_tests(False, False)
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,30 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class LocalShareModePersistentSlugTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"use_legacy_v2_onions": True,
"public_mode": False,
"slug": "",
"save_private_key": True,
"close_after_first_download": False,
}
cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModePersistentSlugTest')
@pytest.mark.run(order=1)
@pytest.mark.tor
def test_run_all_common_setup_tests(self):
self.run_all_common_setup_tests()
@pytest.mark.run(order=2)
@pytest.mark.tor
def test_run_all_share_mode_tests(self):
self.run_all_share_mode_persistent_tests(False, True)
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,34 @@
#!/usr/bin/env python3
import pytest
import unittest
from .TorGuiShareTest import TorGuiShareTest
class ShareModeStealthTest(unittest.TestCase, TorGuiShareTest):
@classmethod
def setUpClass(cls):
test_settings = {
"use_legacy_v2_onions": True,
"use_stealth": True,
}
cls.gui = TorGuiShareTest.set_up(test_settings, 'ShareModeStealthTest')
@pytest.mark.run(order=1)
def test_run_all_common_setup_tests(self):
self.run_all_common_setup_tests()
@pytest.mark.run(order=2)
def test_run_share_mode_setup_tests(self):
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(False)
@pytest.mark.run(order=3)
def test_copy_have_hidserv_auth_button(self):
self.copy_have_hidserv_auth_button(self.gui.share_mode)
@pytest.mark.run(order=4)
def test_hidserv_auth_string(self):
self.hidserv_auth_string()
if __name__ == "__main__":
unittest.main()

View file

@ -0,0 +1,42 @@
#!/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.run(order=1)
@pytest.mark.tor
def test_run_all_common_setup_tests(self):
self.run_all_common_setup_tests()
@pytest.mark.run(order=2)
@pytest.mark.tor
def test_run_share_mode_setup_tests(self):
self.run_all_share_mode_setup_tests()
self.run_all_share_mode_started_tests(False)
@pytest.mark.run(order=3)
@pytest.mark.tor
def test_tor_killed_statusbar_message_shown(self):
self.tor_killed_statusbar_message_shown(self.gui.share_mode)
@pytest.mark.run(order=4)
@pytest.mark.tor
def test_server_is_stopped(self):
self.server_is_stopped(self.gui.share_mode, False)
@pytest.mark.run(order=5)
@pytest.mark.tor
def test_web_service_is_stopped(self):
self.web_service_is_stopped()
if __name__ == "__main__":
unittest.main()

View file

@ -1,61 +0,0 @@
import os
import requests
import socket
import socks
import zipfile
from PyQt5 import QtCore, QtTest
from onionshare import strings
from tests_gui_local import CommonTests as LocalCommonTests
class CommonTests(LocalCommonTests):
def test_a_server_is_started(self, mode):
'''Test that the server has started (overriding from local tests to wait for longer)'''
QtTest.QTest.qWait(45000)
# Should now be in SERVER_STARTED state
if mode == 'receive':
self.assertEqual(self.gui.receive_mode.server_status.status, 2)
if mode == 'share':
self.assertEqual(self.gui.share_mode.server_status.status, 2)
def test_have_an_onion_service(self):
'''Test that we have a valid Onion URL'''
self.assertRegex(self.gui.app.onion_host, r'[a-z2-7].onion')
def test_cancel_the_share(self, mode):
'''Test that we can cancel this share before it's started up '''
if mode == 'share':
QtTest.QTest.mousePress(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(1000)
QtTest.QTest.mouseRelease(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
self.assertEqual(self.gui.share_mode.server_status.status, 0)
if mode == 'receive':
QtTest.QTest.mousePress(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton)
QtTest.QTest.qWait(1000)
QtTest.QTest.mouseRelease(self.gui.receive_mode.server_status.server_button, QtCore.Qt.LeftButton)
self.assertEqual(self.gui.receive_mode.server_status.status, 0)
# Stealth tests
def test_copy_have_hidserv_auth_button(self, mode):
'''Test that the Copy HidservAuth button is shown'''
if mode == 'share':
self.assertTrue(self.gui.share_mode.server_status.copy_hidservauth_button.isVisible())
if mode == 'receive':
self.assertTrue(self.gui.receive_mode.server_status.copy_hidservauth_button.isVisible())
def test_hidserv_auth_string(self):
'''Test the validity of the HidservAuth string'''
self.assertRegex(self.gui.app.auth_string, r'HidServAuth %s [a-zA-Z1-9]' % self.gui.app.onion_host)
# Miscellaneous tests
def test_tor_killed_statusbar_message_shown(self, mode):
'''Test that the status bar message shows Tor was disconnected'''
self.gui.app.onion.cleanup(stop_tor=True)
QtTest.QTest.qWait(2500)
if mode == 'share':
self.assertTrue(self.gui.share_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))
if mode == 'receive':
self.assertTrue(self.gui.receive_mode.status_bar.currentMessage(), strings._('gui_tor_connection_lost'))

View file

@ -1,163 +0,0 @@
import sys
# Force tests to look for resources in the source code tree
sys.onionshare_dev_mode = True
import os
import shutil
import tempfile
import pytest
from onionshare import common, web, settings, strings
@pytest.fixture
def temp_dir_1024():
""" Create a temporary directory that has a single file of a
particular size (1024 bytes).
"""
tmp_dir = tempfile.mkdtemp()
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
with open(tmp_file, 'wb') as f:
f.write(b'*' * 1024)
return tmp_dir
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture
def temp_dir_1024_delete():
""" Create a temporary directory that has a single file of a
particular size (1024 bytes). The temporary directory (including
the file inside) will be deleted after fixture usage.
"""
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
with open(tmp_file, 'wb') as f:
f.write(b'*' * 1024)
yield tmp_dir
@pytest.fixture
def temp_file_1024():
""" Create a temporary file of a particular size (1024 bytes). """
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
tmp_file.write(b'*' * 1024)
return tmp_file.name
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture
def temp_file_1024_delete():
"""
Create a temporary file of a particular size (1024 bytes).
The temporary file will be deleted after fixture usage.
"""
with tempfile.NamedTemporaryFile() as tmp_file:
tmp_file.write(b'*' * 1024)
tmp_file.flush()
yield tmp_file.name
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture(scope='session')
def custom_zw():
zw = web.share_mode.ZipWriter(
common.Common(),
zip_filename=common.Common.random_string(4, 6),
processed_size_callback=lambda _: 'custom_callback'
)
yield zw
zw.close()
os.remove(zw.zip_filename)
# pytest > 2.9 only needs @pytest.fixture
@pytest.yield_fixture(scope='session')
def default_zw():
zw = web.share_mode.ZipWriter(common.Common())
yield zw
zw.close()
tmp_dir = os.path.dirname(zw.zip_filename)
shutil.rmtree(tmp_dir)
@pytest.fixture
def locale_en(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8'))
@pytest.fixture
def locale_fr(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8'))
@pytest.fixture
def locale_invalid(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8'))
@pytest.fixture
def locale_ru(monkeypatch):
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8'))
@pytest.fixture
def platform_darwin(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Darwin')
@pytest.fixture # (scope="session")
def platform_linux(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Linux')
@pytest.fixture
def platform_windows(monkeypatch):
monkeypatch.setattr('platform.system', lambda: 'Windows')
@pytest.fixture
def sys_argv_sys_prefix(monkeypatch):
monkeypatch.setattr('sys.argv', [sys.prefix])
@pytest.fixture
def sys_frozen(monkeypatch):
monkeypatch.setattr('sys.frozen', True, raising=False)
@pytest.fixture
def sys_meipass(monkeypatch):
monkeypatch.setattr(
'sys._MEIPASS', os.path.expanduser('~'), raising=False)
@pytest.fixture # (scope="session")
def sys_onionshare_dev_mode(monkeypatch):
monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False)
@pytest.fixture
def time_time_100(monkeypatch):
monkeypatch.setattr('time.time', lambda: 100)
@pytest.fixture
def time_strftime(monkeypatch):
monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00')
@pytest.fixture
def common_obj():
_common = common.Common()
_common.settings = settings.Settings(_common)
strings.load_strings(_common)
return _common
@pytest.fixture
def settings_obj(sys_onionshare_dev_mode, platform_linux):
_common = common.Common()
_common.version = 'DUMMY_VERSION_1.2.3'
return settings.Settings(_common)

View file

@ -1,190 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@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, False, 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": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
os.remove('/tmp/OnionShare/test.txt')
os.remove('/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=6)
def test_click_mode(self):
CommonTests.test_click_mode(self, 'receive')
@pytest.mark.run(order=6)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'receive')
@pytest.mark.run(order=7)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'receive')
@pytest.mark.run(order=8)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'receive')
@pytest.mark.run(order=8)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'receive')
@pytest.mark.run(order=9)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'receive')
@pytest.mark.run(order=10)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=11)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'receive')
@pytest.mark.run(order=12)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=14)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'receive', False)
@pytest.mark.run(order=15)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=20)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'receive')
@pytest.mark.run(order=21)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'receive')
@pytest.mark.run(order=22)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'receive')
@pytest.mark.run(order=23)
def test_web_page(self):
CommonTests.test_web_page(self, 'receive', 'Select the files you want to send, then click', False)
@pytest.mark.run(order=24)
def test_upload_file(self):
CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test.txt')
@pytest.mark.run(order=25)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'receive')
@pytest.mark.run(order=26)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, 'receive', 1)
@pytest.mark.run(order=27)
def test_upload_same_file_is_renamed(self):
CommonTests.test_upload_file(self, False, '/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=28)
def test_upload_count_incremented_again(self):
CommonTests.test_counter_incremented(self, 'receive', 2)
@pytest.mark.run(order=29)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'receive', False)
@pytest.mark.run(order=30)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=31)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'receive', False)
if __name__ == "__main__":
unittest.main()

View file

@ -1,190 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@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, False, 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": "",
"no_bridges": True,
"private_key": "",
"public_mode": True,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
os.remove('/tmp/OnionShare/test.txt')
os.remove('/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_click_mode(self):
CommonTests.test_click_mode(self, 'receive')
@pytest.mark.run(order=6)
def test_history_is_not_visible(self):
CommonTests.test_history_is_not_visible(self, 'receive')
@pytest.mark.run(order=7)
def test_click_toggle_history(self):
CommonTests.test_click_toggle_history(self, 'receive')
@pytest.mark.run(order=8)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'receive')
@pytest.mark.run(order=9)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'receive')
@pytest.mark.run(order=10)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'receive')
@pytest.mark.run(order=11)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=12)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'receive')
@pytest.mark.run(order=13)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=14)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'receive', True)
@pytest.mark.run(order=15)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=20)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'receive')
@pytest.mark.run(order=21)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'receive')
@pytest.mark.run(order=22)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'receive')
@pytest.mark.run(order=23)
def test_web_page(self):
CommonTests.test_web_page(self, 'receive', 'Select the files you want to send, then click', True)
@pytest.mark.run(order=24)
def test_upload_file(self):
CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test.txt')
@pytest.mark.run(order=25)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'receive')
@pytest.mark.run(order=26)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, 'receive', 1)
@pytest.mark.run(order=27)
def test_upload_same_file_is_renamed(self):
CommonTests.test_upload_file(self, True, '/tmp/OnionShare/test-2.txt')
@pytest.mark.run(order=28)
def test_upload_count_incremented_again(self):
CommonTests.test_counter_incremented(self, 'receive', 2)
@pytest.mark.run(order=29)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'receive', False)
@pytest.mark.run(order=30)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=31)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'receive', False)
if __name__ == "__main__":
unittest.main()

View file

@ -1,193 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@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, False, 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": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
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)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=11)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=12)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=13)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=14)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=15)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=16)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=17)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=18)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=19)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=20)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=21)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=22)
def test_web_page(self):
CommonTests.test_web_page(self, 'share', 'Total size', False)
@pytest.mark.run(order=23)
def test_download_share(self):
CommonTests.test_download_share(self, False)
@pytest.mark.run(order=24)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'share')
@pytest.mark.run(order=25)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=26)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=27)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'share', False)
@pytest.mark.run(order=28)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
if __name__ == "__main__":
unittest.main()

View file

@ -1,201 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@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, False, 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": "",
"no_bridges": True,
"private_key": "",
"public_mode": True,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
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)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', True)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_web_page(self):
CommonTests.test_web_page(self, 'share', 'Total size', True)
@pytest.mark.run(order=25)
def test_download_share(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=26)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'share')
@pytest.mark.run(order=27)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=28)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=29)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'share', False)
@pytest.mark.run(order=30)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
if __name__ == "__main__":
unittest.main()

View file

@ -1,213 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@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, False, 0)
web = Web(common, False, True)
test_settings = {
"auth_password": "",
"auth_type": "no_auth",
"autoupdate_timestamp": "",
"close_after_first_download": False,
"connection_type": "bundled",
"control_port_address": "127.0.0.1",
"control_port_port": 9051,
"downloads_dir": "/tmp/OnionShare",
"hidservauth_string": "",
"no_bridges": True,
"private_key": "",
"public_mode": True,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
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)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', True)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_web_page(self):
CommonTests.test_web_page(self, 'share', 'Total size', True)
@pytest.mark.run(order=25)
def test_download_share(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=26)
def test_history_widgets_present(self):
CommonTests.test_history_widgets_present(self, 'share')
@pytest.mark.run(order=27)
def test_counter_incremented(self):
CommonTests.test_counter_incremented(self, 'share', 1)
@pytest.mark.run(order=28)
def test_download_share_again(self):
CommonTests.test_download_share(self, True)
@pytest.mark.run(order=29)
def test_counter_incremented_again(self):
CommonTests.test_counter_incremented(self, 'share', 2)
@pytest.mark.run(order=30)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', True)
@pytest.mark.run(order=31)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=32)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
@pytest.mark.run(order=33)
def test_add_button_visible(self):
CommonTests.test_add_button_visible(self)
if __name__ == "__main__":
unittest.main()

View file

@ -1,185 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
slug = ''
onion_host = ''
@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, False, 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": "",
"no_bridges": True,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=6)
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)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=11)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=12)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=13)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=14)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=15)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
global slug
slug = self.gui.share_mode.server_status.web.slug
@pytest.mark.run(order=16)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
global onion_host
onion_host = self.gui.app.onion_host
@pytest.mark.run(order=17)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=18)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', True)
@pytest.mark.run(order=19)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
@pytest.mark.run(order=20)
def test_server_status_indicator_says_closed(self):
CommonTests.test_server_status_indicator_says_closed(self, 'share', True)
@pytest.mark.run(order=21)
def test_server_started_again(self):
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')
@pytest.mark.run(order=22)
def test_have_same_slug(self):
'''Test that we have the same slug'''
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
@pytest.mark.run(order=23)
def test_have_same_onion(self):
'''Test that we have the same onion'''
self.assertEqual(self.gui.app.onion_host, onion_host)
@pytest.mark.run(order=24)
def test_server_is_stopped_again(self):
CommonTests.test_server_is_stopped(self, 'share', True)
CommonTests.test_web_service_is_stopped(self)
if __name__ == "__main__":
unittest.main()

View file

@ -1,180 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@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, False, 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": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"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": True,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
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)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_copy_have_hidserv_auth_button(self):
CommonTests.test_copy_have_hidserv_auth_button(self, 'share')
@pytest.mark.run(order=25)
def test_hidserv_auth_string(self):
CommonTests.test_hidserv_auth_string(self)
if __name__ == "__main__":
unittest.main()

View file

@ -1,185 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@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, False, 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": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
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)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_tor_killed_statusbar_message_shown(self):
CommonTests.test_tor_killed_statusbar_message_shown(self, 'share')
@pytest.mark.run(order=25)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=26)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
if __name__ == "__main__":
unittest.main()

View file

@ -1,185 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import unittest
import pytest
import json
from PyQt5 import QtWidgets
from onionshare.common import Common
from onionshare.web import Web
from onionshare import onion, strings
from onionshare_gui import *
from .commontests import CommonTests
class OnionShareGuiTest(unittest.TestCase):
'''Test the OnionShare GUI'''
@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, False, 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": "",
"no_bridges": True,
"private_key": "",
"public_mode": False,
"receive_allow_receiver_shutdown": True,
"save_private_key": False,
"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, False)
@classmethod
def tearDownClass(cls):
'''Clean up after tests'''
os.remove('/tmp/test.txt')
@pytest.mark.run(order=1)
def test_gui_loaded(self):
CommonTests.test_gui_loaded(self)
@pytest.mark.run(order=2)
def test_windowTitle_seen(self):
CommonTests.test_windowTitle_seen(self)
@pytest.mark.run(order=3)
def test_settings_button_is_visible(self):
CommonTests.test_settings_button_is_visible(self)
@pytest.mark.run(order=4)
def test_server_status_bar_is_visible(self):
CommonTests.test_server_status_bar_is_visible(self)
@pytest.mark.run(order=5)
def test_file_selection_widget_has_a_file(self):
CommonTests.test_file_selection_widget_has_a_file(self)
@pytest.mark.run(order=6)
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)
def test_history_is_visible(self):
CommonTests.test_history_is_visible(self, 'share')
@pytest.mark.run(order=10)
def test_deleting_only_file_hides_delete_button(self):
CommonTests.test_deleting_only_file_hides_delete_button(self)
@pytest.mark.run(order=11)
def test_add_a_file_and_delete_using_its_delete_widget(self):
CommonTests.test_add_a_file_and_delete_using_its_delete_widget(self)
@pytest.mark.run(order=12)
def test_file_selection_widget_readd_files(self):
CommonTests.test_file_selection_widget_readd_files(self)
@pytest.mark.run(order=13)
def test_server_working_on_start_button_pressed(self):
CommonTests.test_server_working_on_start_button_pressed(self, 'share')
@pytest.mark.run(order=14)
def test_server_status_indicator_says_starting(self):
CommonTests.test_server_status_indicator_says_starting(self, 'share')
@pytest.mark.run(order=15)
def test_add_delete_buttons_hidden(self):
CommonTests.test_add_delete_buttons_hidden(self)
@pytest.mark.run(order=16)
def test_settings_button_is_hidden(self):
CommonTests.test_settings_button_is_hidden(self)
@pytest.mark.run(order=17)
def test_a_server_is_started(self):
CommonTests.test_a_server_is_started(self, 'share')
@pytest.mark.run(order=18)
def test_a_web_server_is_running(self):
CommonTests.test_a_web_server_is_running(self)
@pytest.mark.run(order=19)
def test_have_a_slug(self):
CommonTests.test_have_a_slug(self, 'share', False)
@pytest.mark.run(order=20)
def test_have_an_onion(self):
CommonTests.test_have_an_onion_service(self)
@pytest.mark.run(order=21)
def test_url_description_shown(self):
CommonTests.test_url_description_shown(self, 'share')
@pytest.mark.run(order=22)
def test_have_copy_url_button(self):
CommonTests.test_have_copy_url_button(self, 'share')
@pytest.mark.run(order=23)
def test_server_status_indicator_says_started(self):
CommonTests.test_server_status_indicator_says_started(self, 'share')
@pytest.mark.run(order=24)
def test_tor_killed_statusbar_message_shown(self):
CommonTests.test_tor_killed_statusbar_message_shown(self, 'share')
@pytest.mark.run(order=25)
def test_server_is_stopped(self):
CommonTests.test_server_is_stopped(self, 'share', False)
@pytest.mark.run(order=26)
def test_web_service_is_stopped(self):
CommonTests.test_web_service_is_stopped(self)
if __name__ == "__main__":
unittest.main()

View file

@ -1,5 +0,0 @@
#!/bin/bash
for test in `ls -1 | egrep ^onionshare_`; do
pytest $test -vvv || exit 1
done