This commit is contained in:
Tim Bentley 2020-06-20 10:27:43 +00:00
parent f2f07faf60
commit d5bcc35175
10 changed files with 105 additions and 150 deletions

51
.gitignore vendored Normal file
View File

@ -0,0 +1,51 @@
*.*~
*.dll
*.e4*
*.kate-swp
*.kdev4
*.komodoproject
*.log*
*.nja
*.orig
*.pyc
*.qm
*.rej
*.ropeproject
*.~\?~
*eric[1-9]project
.cache
.coverage
.directory
.eggs
.idea
.kdev4
.komodotools
.pytest_cache
.venv
.vscode
.eggs
.venv
.mypy_cache
OpenLP.egg-info
\#*\#
__pycache__
build
cover
coverage
dist
env
htmlcov
list
node_modules
openlp.cfg
openlp.pro
openlp/core/resources.py
openlp/core/resources.py.old
openlp/plugins/presentations/lib/vendor/Pyro4
openlp/plugins/presentations/lib/vendor/serpent.py
output
package-lock.json
tags
test
openlp-test-projectordb.sqlite
*/test-results.xml

3
.idea/.gitignore generated vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,47 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyAttributeOutsideInitInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyClassHasNoInitInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="25">
<item index="0" class="java.lang.String" itemvalue="PyMuPDF" />
<item index="1" class="java.lang.String" itemvalue="pytest-runner" />
<item index="2" class="java.lang.String" itemvalue="pyodbc" />
<item index="3" class="java.lang.String" itemvalue="pysword" />
<item index="4" class="java.lang.String" itemvalue="pytest" />
<item index="5" class="java.lang.String" itemvalue="pylint" />
<item index="6" class="java.lang.String" itemvalue="bs4" />
<item index="7" class="java.lang.String" itemvalue="json2html" />
<item index="8" class="java.lang.String" itemvalue="tweepy" />
<item index="9" class="java.lang.String" itemvalue="travispy" />
<item index="10" class="java.lang.String" itemvalue="python-whois" />
<item index="11" class="java.lang.String" itemvalue="ipwhois" />
<item index="12" class="java.lang.String" itemvalue="praw" />
<item index="13" class="java.lang.String" itemvalue="simplejson" />
<item index="14" class="java.lang.String" itemvalue="tqdm" />
<item index="15" class="java.lang.String" itemvalue="termcolor" />
<item index="16" class="java.lang.String" itemvalue="python-wappalyzer" />
<item index="17" class="java.lang.String" itemvalue="beautifulsoup" />
<item index="18" class="java.lang.String" itemvalue="anyjson" />
<item index="19" class="java.lang.String" itemvalue="configobj" />
<item index="20" class="java.lang.String" itemvalue="google-api-python-client" />
<item index="21" class="java.lang.String" itemvalue="clearbit" />
<item index="22" class="java.lang.String" itemvalue="tldextract" />
<item index="23" class="java.lang.String" itemvalue="config" />
<item index="24" class="java.lang.String" itemvalue="billiard" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyStubPackagesAdvertiser" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<list>
<option value="PyQt5" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml generated
View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/openlp-api-tester.iml" filepath="$PROJECT_DIR$/.idea/openlp-api-tester.iml" />
</modules>
</component>
</project>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="pytest" />
</component>
</module>

View File

@ -23,11 +23,13 @@ import requests
import string import string
import time import time
import random import random
import threading
import websocket
from websocket import create_connection from websocket import create_connection
from test_api.apitest.constants import BookNames from test_api.apitest.constants import BookNames
from test_api.apitest.logger import print_text, print_error, print_ok from test_api.apitest.logger import print_text, print_error, print_ok, print_info
class RunTestsController(object): class RunTestsController(object):
@ -37,7 +39,41 @@ class RunTestsController(object):
self.http_port = http_port self.http_port = http_port
self.ws_port = ws_port self.ws_port = ws_port
self.reserved_result_stage = None self.reserved_result_stage = None
self.reserved_result_live = None self.received = False
def connect(self) -> None:
print_info("Starting thread")
self.ws = websocket.WebSocketApp(f'ws://{self.address}:{self.ws_port}',
on_message=self.on_message,
on_close=self.on_close,
on_open=self.on_open,
on_error=self.on_error,
)
self.wst = threading.Thread(target=lambda: self.ws.run_forever())
self.wst.daemon = True
self.wst.start()
conn_timeout = 5
while (not self.ws.sock or not self.ws.sock.connected) and conn_timeout:
human_delay(1)
conn_timeout -= 1
if not conn_timeout:
print_error("Could not connect to WS! Exiting.")
def on_message(self, message: str) -> None:
print_info("Message returned")
self.result_stage = message
self.compare_stage()
self.received = True
def on_open(self) -> None:
print_info("opened")
def on_close(self) -> None:
print_info("closed")
def on_error(self, error: str) -> None:
print_error(f'WebSocket Error: {error}')
def load_and_check_sockets(self, first_run: bool = False) -> bool: def load_and_check_sockets(self, first_run: bool = False) -> bool:
ws = create_connection(f'ws://{self.address}:{self.ws_port}') ws = create_connection(f'ws://{self.address}:{self.ws_port}')
@ -61,9 +97,11 @@ class RunTestsController(object):
""" """
:return: :return:
""" """
if self.received:
self.stage_diff = {} self.stage_diff = {}
reserved = json.loads(self.reserved_result_stage.decode('utf-8'))['results'] reserved = json.loads(self.reserved_result_stage.decode('utf-8'))['results']
current = json.loads(self.result_stage.decode('utf-8'))['results'] current = json.loads(self.result_stage.decode('utf-8'))['results']
self.received = False
# compare_strings(reserved, current) # compare_strings(reserved, current)
assert len(reserved) == len(current) assert len(reserved) == len(current)
for a, _ in current.items(): for a, _ in current.items():
@ -295,8 +333,8 @@ def live_item(rtc: RunTestsController, plugin: str) -> None:
def check_websocket_changes(rtc: RunTestsController, manditary: int, optional: int) -> None: def check_websocket_changes(rtc: RunTestsController, manditary: int, optional: int) -> None:
rtc.load_and_check_sockets() while not rtc.received:
rtc.compare_stage() time.sleep(0.1)
if manditary <= len(rtc.stage_diff) <= optional: if manditary <= len(rtc.stage_diff) <= optional:
pass pass
else: else:

View File

@ -29,7 +29,7 @@ def start() -> None:
Instantiate and run the tests. Instantiate and run the tests.
:return: :return:
""" """
print_text('OpenLP - API Test Runner V0_1') print_text('OpenLP - API Test Runner V0_2')
print_text('Check OpenLP is running') print_text('Check OpenLP is running')
op_address, op_http_port = check_for_openlp('http') op_address, op_http_port = check_for_openlp('http')
if not op_http_port: if not op_http_port:
@ -41,6 +41,7 @@ def start() -> None:
print_ok(f'OpenLP is running network Address {op_address}') print_ok(f'OpenLP is running network Address {op_address}')
print_ok(f'OpenLP is running on port (ws) {op_ws_port}') print_ok(f'OpenLP is running on port (ws) {op_ws_port}')
rtc = RunTestsController(op_address, op_http_port, op_ws_port) rtc = RunTestsController(op_address, op_http_port, op_ws_port)
rtc.connect()
rtc.marshal_full() rtc.marshal_full()
#nrtc.marshal_media() #nrtc.marshal_media()
print_text('Finished running tests') print_text('Finished running tests')

56
x1.py
View File

@ -1,56 +0,0 @@
import websocket
import ssl
import sys
from time import sleep
import threading
class MyWebSocket():
def connect(self, wsURL="wss://www.bitmex.com/realtime?subscribe=quote:XBTUSD"):
print("Starting thread")
ssl_defaults = ssl.get_default_verify_paths()
sslopt_ca_certs = {"ca_certs": ssl_defaults.cafile}
self.ws = websocket.WebSocketApp(wsURL,
on_message=self.__on_message,
on_close=self.__on_close,
on_open=self.__on_open,
on_error=self.__on_error,
)
self.wst = threading.Thread(target=lambda: self.ws.run_forever(sslopt=sslopt_ca_certs))
self.wst.daemon = True
self.wst.start()
conn_timeout = 5
while (not self.ws.sock or not self.ws.sock.connected) and conn_timeout:
sleep(1)
conn_timeout -= 1
if not conn_timeout:
print("Could not connect to WS! Exiting.")
sys.exit(1)
def __on_message(self, message):
print(message)
def __on_open(self):
print("opened")
def __on_close(self):
print("closed")
def __on_error(self, error):
print("error")
def run(self):
self.connect()
while True:
print("hello mum")
sleep(1)
websocket.enableTrace(True)
mysocket = MyWebSocket()
mysocket.run()
#mysocket.connect()
#while True:#
# sleep(1)
print("the end")