Oct 2020 - Fixes

This commit is contained in:
Tim Bentley 2020-10-20 14:09:08 +00:00
parent 43b715b935
commit d036f2d25e
5 changed files with 88 additions and 16 deletions

View File

@ -1,7 +1,66 @@
OpenLP API tester.
# OpenLP API tester.
A commandline utility to access a running OpenLP instance via it's API's and test all functionality.
It will find OpenLP on the network via ZeroConf and then using the API's build and run a service.
After each command the results are tested to make sure the WebSockets have changed.
After each command the results are tested to make sure the WebSockets have changed.
Tests are mastered in JSON files and run using the framework.
## Test Structure
```
process_name: test process
step1:
max: 1
min: 1
name: clear_live_controller
step2:
delay: 1
name: clear_preview_controller
step3:
max: 1
min: 1
name: new_service
step4:
delay: 1
name: search_and_add
payload:
plugin: songs
step6:
name: load_service_sequential
```
* process_name
A unique name for the run
* step 1
The step number, needs to be unique and in order!
* delay
How long to wait after a call has been made. Default is 2 seconds for all calls.
* max
How long to wait after a call has been made. Default is 2 seconds for all calls.
* min
How long to wait after a call has been made. Default is 2 seconds for all calls.
* payload
How long to wait after a call has been made. Default is 2 seconds for all calls.
* name
The step name (function name) to be called to run the step.
## Commands
## Adding API's and Internals

4
live_item.yaml Normal file
View File

@ -0,0 +1,4 @@
---
process_name: live_item
step1:
name: play_live_items

View File

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

View File

@ -146,15 +146,13 @@ def service_item_show(rtc: object, payload: dict) -> None:
ret = requests.post(rtc.base_url + 'service/show', json=dict(uid=id))
assert ret.status_code == 204, ret.status_code
if not item['plugin'] == 'media':
pl = {'max': 1, 'min': 2, 'delay': 0.5, 'name': 'play_live_item', 'payload': {'item': item}}
pl = {'max': 1, 'min': 2, 'delay': 0.5, 'name': 'play_live_items', 'payload': {'item': item}}
rtc.tasks.append(Task(rtc, pl))
def play_live_item(rtc: object, payload: dict) -> None:
item = payload['item']
plugin = item['plugin']
print_text(f'Play_live_item - {plugin}')
ret = requests.get(rtc.base_url + 'controller/live-item')
def play_live_items(rtc: object) -> None:
print_text('Play_live_items')
ret = requests.get(rtc.base_url + 'controller/live-items')
assert ret.status_code == 200, f'{ret.status_code} returned from live_item'
i = 0
for _ in json.loads(ret.text):
@ -164,6 +162,14 @@ def play_live_item(rtc: object, payload: dict) -> None:
assert ret.status_code == 200, f'{ret.status_code} returned from show'
def play_live_item(rtc: object) -> None:
print_text('Play_live_item')
ret = requests.get(rtc.base_url + 'controller/live-item')
assert ret.status_code == 200, f'{ret.status_code} returned from live_item'
aa = json.loads(ret.text)
print_text(aa)
def controller_item_show(rtc: object, payload: dict) -> None:
id = payload['id']
print_text('Controller_item_show')

View File

@ -75,18 +75,21 @@ class RunTestsController(object):
else:
self.ws_data.append(message)
def on_open(self) -> None:
@staticmethod
def on_open() -> None:
print_info("Socket Listener Opened")
def on_close(self) -> None:
@staticmethod
def on_close() -> None:
print_info("Socket Listener Closed")
def on_error(self, error: str) -> None:
@staticmethod
def on_error(error: str) -> None:
print_error(f'WebSocket Error: {error}')
def load_and_check_sockets(self, first_run: bool = False) -> bool:
"""
Method to make connect to webspockets
Method to make connect to websockets
:param first_run:
:return:
"""
@ -167,15 +170,15 @@ class RunTestsController(object):
item = service[pos - 1]
service_item_show(self, item)
def check_websocket_changes(self, manditory: int, optional: int) -> None:
def check_websocket_changes(self, mandatory: int, optional: int) -> None:
while len(self.ws_data) > 0:
message = self.ws_data.popleft()
self.result_stage = message
self.compare_stage()
if manditory <= len(self.stage_diff) <= manditory + optional:
if mandatory <= len(self.stage_diff) <= mandatory + optional:
pass
else:
print(f'{manditory} stage field(s) must have changed and '
print(f'{mandatory} stage field(s) must have changed and '
f'{optional} may change changed- {str(self.stage_diff)}')