From 8c0769f93fb6d99a1ee91f9cef509f236feaaa32 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 20 Oct 2020 12:41:52 +0100 Subject: [PATCH] updates and documentation --- README.md | 63 +++++++++++++++++++++++++++++++++-- live_item.yaml | 5 +++ requirements.txt | 2 +- test.yaml | 5 --- test_api/apitest/callbacks.py | 19 +++++++---- test_api/apitest/runner.py | 17 ++++++---- 6 files changed, 90 insertions(+), 21 deletions(-) create mode 100644 live_item.yaml diff --git a/README.md b/README.md index bd7272f..4832596 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +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 + diff --git a/live_item.yaml b/live_item.yaml new file mode 100644 index 0000000..3ead03e --- /dev/null +++ b/live_item.yaml @@ -0,0 +1,5 @@ +--- +process_name: live_item +step1: + name: play_live_items + diff --git a/requirements.txt b/requirements.txt index acf673b..5113d3a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -colorama==0.4.1 +python3-colorama==0.4.3 websocket-client==0.56.0 diff --git a/test.yaml b/test.yaml index 91ad246..1cfd575 100644 --- a/test.yaml +++ b/test.yaml @@ -16,10 +16,5 @@ step4: name: search_and_add payload: plugin: songs -step5: - delay: 1 - name: search_and_add - payload: - plugin: bibles step6: name: load_service_sequential diff --git a/test_api/apitest/callbacks.py b/test_api/apitest/callbacks.py index 0f5ab38..aeb4174 100644 --- a/test_api/apitest/callbacks.py +++ b/test_api/apitest/callbacks.py @@ -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(f'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,15 @@ 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(f'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' + i = 0 + aa = json.loads(ret.text) + bb = 1 + + def controller_item_show(rtc: object, payload: dict) -> None: id = payload['id'] print_text('Controller_item_show') diff --git a/test_api/apitest/runner.py b/test_api/apitest/runner.py index 429b156..ee227c8 100644 --- a/test_api/apitest/runner.py +++ b/test_api/apitest/runner.py @@ -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)}')