From 02fa6dd558a9aaac6b325f7a4d8f6972fb71f5ca Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 28 Feb 2020 03:49:30 -0600 Subject: [PATCH] added first browser test, tests if circles opens out of ot the box --- requirements-dev.in | 1 + requirements-dev.txt | 10 ++++++ run_tests.sh | 10 +++++- src/onionrplugins/__init__.py | 5 +-- src/utils/identifyhome.py | 2 ++ tests/browser-tests/test-circles.py | 47 +++++++++++++++++++++++++++++ tests/runtime-result.txt | 2 +- 7 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 tests/browser-tests/test-circles.py diff --git a/requirements-dev.in b/requirements-dev.in index adf31e9c..42abf52e 100644 --- a/requirements-dev.in +++ b/requirements-dev.in @@ -1,2 +1,3 @@ pdoc3==0.7.4 pip-tools==4.5.0 +helium==3.0.1 diff --git a/requirements-dev.txt b/requirements-dev.txt index dcf2ee40..42d9d2aa 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,6 +8,8 @@ click==7.0 \ --hash=sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13 \ --hash=sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7 \ # via pip-tools +helium==3.0.1 \ + --hash=sha256:a7be1ad48702a38e11e9ee9b262459cde3c986d2dcbd79fcf8d6f5b54c5f5d9e mako==1.1.1 \ --hash=sha256:2984a6733e1d472796ceef37ad48c26f4a984bb18119bb2dbc37a44d8f6e75a4 \ # via pdoc3 @@ -55,10 +57,18 @@ pdoc3==0.7.4 \ pip-tools==4.5.0 \ --hash=sha256:144fbd764e88f761246f832370721dccabfefbbc4ce3aa8468f6802ac6519217 \ --hash=sha256:61455cfdaa183930eefd8259f393812d94005fb9f8249edb640ed1b66f678116 +selenium==3.141.0 \ + --hash=sha256:2d7131d7bc5a5b99a2d9b04aaf2612c411b03b8ca1b1ee8d3de5845a9be2cb3c \ + --hash=sha256:deaf32b60ad91a4611b98d8002757f29e6f2c2d5fcaf202e1c9ad06d6772300d \ + # via helium six==1.14.0 \ --hash=sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a \ --hash=sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c \ # via pip-tools +urllib3==1.25.8 \ + --hash=sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc \ + --hash=sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc \ + # via selenium # WARNING: The following packages were not pinned, but pip requires them to be # pinned when the requirements file includes hashes. Consider using the --allow-unsafe flag. diff --git a/run_tests.sh b/run_tests.sh index de78749d..9e23a84d 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -20,5 +20,13 @@ for f in tests/integration-tests/*.py; do python3 "$f" || close # if needed let "ran++" done -echo "ran $ran integration test tests." +echo "ran $ran integration tests." echo "total test time $SECONDS" +ran=0; + +for f in tests/browser-tests/*.py; do + python3 "$f" || close # if needed + let "ran++" +done +echo "ran $ran browser tests." +echo "total test time $SECONDS" \ No newline at end of file diff --git a/src/onionrplugins/__init__.py b/src/onionrplugins/__init__.py index 67aacd33..ad9825f0 100755 --- a/src/onionrplugins/__init__.py +++ b/src/onionrplugins/__init__.py @@ -78,7 +78,7 @@ def enable(name, start_event = True): else: enabled_plugins.append(name) config.set('plugins.enabled', enabled_plugins, savefile=True) - + if start_event is True: start(name) return True @@ -174,7 +174,7 @@ def import_module_from_file(full_path_to_module): module_name, module_ext = os.path.splitext(module_file) module_name = module_dir # Module name must be unique otherwise it will get written in other imports - + # Get module "spec" from filename spec = importlib.util.spec_from_file_location(module_name,full_path_to_module) @@ -215,6 +215,7 @@ def get_enabled_plugins(): ''' check() + config.reload() return list(config.get('plugins.enabled', list())) diff --git a/src/utils/identifyhome.py b/src/utils/identifyhome.py index d3ecde7c..31dafca7 100644 --- a/src/utils/identifyhome.py +++ b/src/utils/identifyhome.py @@ -4,6 +4,7 @@ Identify a data directory for Onionr """ import os import platform +import uuid """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,6 +28,7 @@ def identify_home() -> str: """ path = os.environ.get('ONIONR_HOME', None) + if path is not None and not os.getcwd().endswith('src') \ and 'test' not in path: path = 'src/' + path diff --git a/tests/browser-tests/test-circles.py b/tests/browser-tests/test-circles.py new file mode 100644 index 00000000..5e67ab26 --- /dev/null +++ b/tests/browser-tests/test-circles.py @@ -0,0 +1,47 @@ +from unittest.mock import patch +import sys, os +sys.path.append(".") +sys.path.append("src/") +import unittest, uuid +TEST_DIR = 'testdata/-%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' +os.environ["ONIONR_HOME"] = TEST_DIR + +from utils import createdirs + +from subprocess import Popen +import subprocess +from time import sleep + +from helium import start_firefox, click, Text + + +from onionrcommands.openwebinterface import get_url +from onionrutils import escapeansi +BROWSER_HEADLESS = os.getenv('ONIONR_TEST_HEADLESS') + +def start_onionr(): + testargs = ["onionr.py", "start"] + with patch.object(sys, 'argv', testargs): + parser.register() + + +class OnionrTests(unittest.TestCase): + def test_circles_home_load(self): + Popen(['./onionr.sh', 'start']) + while b'http' not in Popen(['./onionr.sh', 'url'], stdout=subprocess.PIPE).communicate()[0]: + sleep(1) + url = 'http' + escapeansi.escape_ANSI(Popen(['./onionr.sh', 'url'], stdout=subprocess.PIPE).communicate()[0].decode().split('http')[1]) + web_driver = start_firefox(url=url, headless=BROWSER_HEADLESS) + if Text('Get Started').exists(): + click('Get Started') + click('Circles') + if not Text('Circle Name').exists(): + Popen(['./onionr.sh', 'stop']).wait() + web_driver.quit() + raise ValueError + Popen(['./onionr.sh', 'stop']).wait() + web_driver.quit() + + + +unittest.main() \ No newline at end of file diff --git a/tests/runtime-result.txt b/tests/runtime-result.txt index 5ef70e2d..2ea789b4 100644 --- a/tests/runtime-result.txt +++ b/tests/runtime-result.txt @@ -1 +1 @@ -1582445602 \ No newline at end of file +1582883307 \ No newline at end of file