This commit is contained in:
Tim 2020-06-26 14:40:45 +01:00
commit 149a189bfe
No known key found for this signature in database
GPG Key ID: 3D454289AF831A6D
12 changed files with 33 additions and 14 deletions

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
colorama==0.4.1
websocket-client==0.56.0

3
setup.cfg Normal file
View File

@ -0,0 +1,3 @@
[flake8]
max-line-length = 120
ignore = E402,W503,W504,D

View File

@ -40,3 +40,7 @@ def print_warn(text: str):
def print_info(text: str): def print_info(text: str):
print(Fore.MAGENTA + '[!] = ' + text) print(Fore.MAGENTA + '[!] = ' + text)
def print_debug(text: str):
print(Fore.CYAN + '[#] = ' + text)

View File

@ -28,8 +28,13 @@ 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
<<<<<<< HEAD
from test_api.apitest.logger import print_text, print_error, print_ok, print_info from test_api.apitest.logger import print_text, print_error, print_ok, print_info
=======
from test_api.apitest.logger import print_text, print_error, print_ok, print_info
# from test_api.apitest.logger import print_debug
>>>>>>> de2f630de03530dae811b691f625e645b76450e4
class RunTestsController(object): class RunTestsController(object):
@ -61,7 +66,11 @@ class RunTestsController(object):
print_error("Could not connect to WS! Exiting.") print_error("Could not connect to WS! Exiting.")
def on_message(self, message: str) -> None: def on_message(self, message: str) -> None:
<<<<<<< HEAD
print_info("Message returned") print_info("Message returned")
=======
# print_debug("Message returned")
>>>>>>> de2f630de03530dae811b691f625e645b76450e4
self.result_stage = message self.result_stage = message
self.compare_stage() self.compare_stage()
self.received = True self.received = True
@ -256,7 +265,7 @@ def search_and_live(rtc: RunTestsController, plugin: str, count: int) -> None:
random_service = [random.randint(1, limit) for itr in range(count)] random_service = [random.randint(1, limit) for itr in range(count)]
for pos in random_service: for pos in random_service:
item = items[pos - 1] item = items[pos - 1]
ret = requests.post(base_url + f'live', json=dict(id=item[0])) ret = requests.post(base_url + 'live', json=dict(id=item[0]))
assert ret.status_code == 204, f'{ret.status_code} returned from add' assert ret.status_code == 204, f'{ret.status_code} returned from add'
human_delay() human_delay()
@ -275,7 +284,7 @@ def search_and_add(rtc: RunTestsController, plugin: str, count: int) -> None:
assert ret.status_code == 200, f'{ret.status_code} returned from searcg' assert ret.status_code == 200, f'{ret.status_code} returned from searcg'
items = json.loads(ret.text) items = json.loads(ret.text)
if items: if items:
ret = requests.post(base_url + f'add', json=dict(id=items[0][0])) ret = requests.post(base_url + 'add', json=dict(id=items[0][0]))
assert ret.status_code == 204, f'{ret.status_code} returned from add' assert ret.status_code == 204, f'{ret.status_code} returned from add'
human_delay() human_delay()
else: else:
@ -297,7 +306,7 @@ def search_and_add(rtc: RunTestsController, plugin: str, count: int) -> None:
random_service = [random.randint(1, limit) for itr in range(count)] random_service = [random.randint(1, limit) for itr in range(count)]
for pos in random_service: for pos in random_service:
item = items[pos - 1] item = items[pos - 1]
ret = requests.post(base_url + f'add', json=dict(id=item[0])) ret = requests.post(base_url + 'add', json=dict(id=item[0]))
assert ret.status_code == 204, f'{ret.status_code} returned from add' assert ret.status_code == 204, f'{ret.status_code} returned from add'
human_delay() human_delay()
@ -319,13 +328,13 @@ def live_item(rtc: RunTestsController, plugin: str) -> None:
print_text(f'test_live_item - {plugin}') print_text(f'test_live_item - {plugin}')
base_url = f'http://{rtc.address}:{rtc.http_port}/api/v2/' base_url = f'http://{rtc.address}:{rtc.http_port}/api/v2/'
ret = requests.get(base_url + 'controller/live-item') ret = requests.get(base_url + 'controller/live-item')
assert ret.status_code == 200 assert ret.status_code == 200, f'{ret.status_code} returned from live_item'
i = 0 i = 0
for _ in json.loads(ret.text): for _ in json.loads(ret.text):
ret = requests.post(base_url + 'controller/show', json=dict(id=i)) ret = requests.post(base_url + 'controller/show', json=dict(id=i))
i += 1 i += 1
human_delay() human_delay()
assert ret.status_code == 204 assert ret.status_code == 204, f'{ret.status_code} returned from show'
if plugin in {'image'}: if plugin in {'image'}:
check_websocket_changes(rtc, 0, 0) check_websocket_changes(rtc, 0, 0)
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: