From 5acab3887169e1e0eaf13346a4f6c04e1d30f7a7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 21 Aug 2021 15:16:29 +0000 Subject: [PATCH] Jan2021 --- .gitlab-ci.yml | 2 +- README.md | 40 ++++-- alert.yaml | 13 -- blank.yaml | 13 -- openlp-apitest.code-workspace | 7 + requirements.txt | 2 +- scripts/alert.yaml | 6 + scripts/blank.yaml | 26 ++++ .../full_run_rand.yaml | 0 .../full_run_seq.yaml | 0 live_item.yaml => scripts/live_item.yaml | 0 media.yaml => scripts/media.yaml | 0 pause.yaml => scripts/pause.yaml | 0 play.yaml => scripts/play.yaml | 0 stop.yaml => scripts/stop.yaml | 0 test.yaml => scripts/test.yaml | 0 scripts/themes.yaml | 4 + test_api/apitest/callbacks.py | 130 +++++++++++++++++- test_api/apitest/logger.py | 12 +- test_api/apitest/runner.py | 3 +- test_api/apitest/task.py | 5 + test_api/apitest/zero.py | 3 +- test_api/runner.py | 4 +- 23 files changed, 220 insertions(+), 50 deletions(-) delete mode 100644 alert.yaml delete mode 100644 blank.yaml create mode 100644 openlp-apitest.code-workspace create mode 100644 scripts/alert.yaml create mode 100644 scripts/blank.yaml rename full_run_rand.yaml => scripts/full_run_rand.yaml (100%) rename full_run_seq.yaml => scripts/full_run_seq.yaml (100%) rename live_item.yaml => scripts/live_item.yaml (100%) rename media.yaml => scripts/media.yaml (100%) rename pause.yaml => scripts/pause.yaml (100%) rename play.yaml => scripts/play.yaml (100%) rename stop.yaml => scripts/stop.yaml (100%) rename test.yaml => scripts/test.yaml (100%) create mode 100644 scripts/themes.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d0797f4..e2b1cc4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,4 +9,4 @@ lint-yaml: image: python:latest script: - pip install yamllint - - yamllint *.yaml \ No newline at end of file + - yamllint scripts/*.yaml \ No newline at end of file diff --git a/README.md b/README.md index 4832596..a9a35e1 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,18 @@ # OpenLP API tester. -A commandline utility to access a running OpenLP instance via it's API's and test all functionality. +A command line 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. +This harness will find a running OpenLP instance 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. +The API's need to be configured as insecure as this is not being tested. + Tests are mastered in JSON files and run using the framework. -## Test Structure +The bible test framework is random so some bible references will not be correct and therefore will not load! The chapter and verse numbers are random numbers!! + +## Sample Test Structure ``` process_name: test process step1: @@ -38,29 +42,43 @@ step6: The step number, needs to be unique and in order! - * delay + * delay (optional) - How long to wait after a call has been made. Default is 2 seconds for all calls. + How long to wait after a call has been made. Default is 0.3 seconds for all calls. - * max + * max (optional) - How long to wait after a call has been made. Default is 2 seconds for all calls. + Max number of fields which will change on the Web Sockets interface. - * min + * min (optional) - How long to wait after a call has been made. Default is 2 seconds for all calls. + Max number of fields which will change on the Web Sockets interface. * payload - How long to wait after a call has been made. Default is 2 seconds for all calls. + Json to support addition information to the call. * name The step name (function name) to be called to run the step. -## Commands +## Commands and Payloads +| Rule Name | Payload | +|--------------------------|------------------------------| +| trigger_alert | text: | +| search_and_add | plugin: | +| search_and_live | plugin: | +| service_item_show | item: item_id| +| play_live_item | ?????| +| controller_item_next |?????| +| controller_item_previous |???????| ## Adding API's and Internals +API's and their handers are defining in the callback.py file. This should be the only file that needs to change when adding new API's + +The test scripts are in the scripts directory and are a pre defined set of tests. + + diff --git a/alert.yaml b/alert.yaml deleted file mode 100644 index 3d3ca45..0000000 --- a/alert.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -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 diff --git a/blank.yaml b/blank.yaml deleted file mode 100644 index 3d3ca45..0000000 --- a/blank.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -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 diff --git a/openlp-apitest.code-workspace b/openlp-apitest.code-workspace new file mode 100644 index 0000000..362d7c2 --- /dev/null +++ b/openlp-apitest.code-workspace @@ -0,0 +1,7 @@ +{ + "folders": [ + { + "path": "." + } + ] +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5113d3a..be8a8cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ python3-colorama==0.4.3 -websocket-client==0.56.0 +websocket-client==0.57.0 diff --git a/scripts/alert.yaml b/scripts/alert.yaml new file mode 100644 index 0000000..d1f7e61 --- /dev/null +++ b/scripts/alert.yaml @@ -0,0 +1,6 @@ +--- +process_name: Show basic alert process +step1: + payload: + text: Show some text + name: trigger_alert diff --git a/scripts/blank.yaml b/scripts/blank.yaml new file mode 100644 index 0000000..75a4ee3 --- /dev/null +++ b/scripts/blank.yaml @@ -0,0 +1,26 @@ +--- +process_name: Test Display hiding +step1: + delay: 1 + name: display_hide +step2: + delay: 1 + name: display_show +step3: + delay: 1 + name: display_blank +step4: + delay: 1 + name: display_show +step5: + delay: 1 + name: display_theme +step6: + delay: 1 + name: display_show +step7: + delay: 1 + name: display_desktop +step8: + delay: 1 + name: display_show diff --git a/full_run_rand.yaml b/scripts/full_run_rand.yaml similarity index 100% rename from full_run_rand.yaml rename to scripts/full_run_rand.yaml diff --git a/full_run_seq.yaml b/scripts/full_run_seq.yaml similarity index 100% rename from full_run_seq.yaml rename to scripts/full_run_seq.yaml diff --git a/live_item.yaml b/scripts/live_item.yaml similarity index 100% rename from live_item.yaml rename to scripts/live_item.yaml diff --git a/media.yaml b/scripts/media.yaml similarity index 100% rename from media.yaml rename to scripts/media.yaml diff --git a/pause.yaml b/scripts/pause.yaml similarity index 100% rename from pause.yaml rename to scripts/pause.yaml diff --git a/play.yaml b/scripts/play.yaml similarity index 100% rename from play.yaml rename to scripts/play.yaml diff --git a/stop.yaml b/scripts/stop.yaml similarity index 100% rename from stop.yaml rename to scripts/stop.yaml diff --git a/test.yaml b/scripts/test.yaml similarity index 100% rename from test.yaml rename to scripts/test.yaml diff --git a/scripts/themes.yaml b/scripts/themes.yaml new file mode 100644 index 0000000..b463e16 --- /dev/null +++ b/scripts/themes.yaml @@ -0,0 +1,4 @@ +--- +process_name: themes +step1: + name: loop_theme_default diff --git a/test_api/apitest/callbacks.py b/test_api/apitest/callbacks.py index cdadcda..f93493d 100644 --- a/test_api/apitest/callbacks.py +++ b/test_api/apitest/callbacks.py @@ -167,7 +167,7 @@ def play_live_items(rtc: object) -> None: 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): + for _ in json.loads(ret.text)['slides']: pl = {'max': 1, 'min': 2, 'delay': 0.5, 'name': 'controller_item_show', 'payload': {'id': i}} rtc.tasks.append(Task(rtc, pl)) i += 1 @@ -187,3 +187,131 @@ def controller_item_show(rtc: object, payload: dict) -> None: print_text('Controller_item_show') ret = requests.post(rtc.base_url + 'controller/show', json=dict(id=int(id))) assert ret.status_code == 204, ret.status_code + + +def controller_item_next(rtc: object, payload: dict) -> None: + print_text('Controller_item_next') + ret = requests.post(rtc.base_url + 'controller/progress', json=dict(action='next')) + assert ret.status_code == 204, ret.status_code + + +def controller_item_previous(rtc: object, payload: dict) -> None: + print_text('Controller_item_previous') + ret = requests.post(rtc.base_url + 'controller/progress', json=dict(action='previous')) + assert ret.status_code == 204, ret.status_code + + +def trigger_alert(rtc: object, payload: dict) -> None: + p_text = payload['text'] + print_text('trigger_alert') + ret = requests.post(rtc.base_url + 'plugins/alerts', json=dict(text=p_text)) + assert ret.status_code == 204, ret.status_code + + +def get_plugins(rtc: object) -> None: + print_text('get_plugins') + ret = requests.get(rtc.base_url + 'plugins') + assert ret.status_code == 204, ret.status_code + + +def get_system(rtc: object) -> None: + print_text('get_system') + ret = requests.get(rtc.base_url + 'system') + assert ret.status_code == 204, ret.status_code + + +def get_live_image(rtc: object) -> None: + print_text('get_live_image') + ret = requests.get(rtc.base_url + 'live-image') + assert ret.status_code == 204, ret.status_code + + +def loop_theme_default(rtc: object) -> None: + print_text('loop_theme_default') + items = get_themes(rtc) + for item in json.loads(items.text): + print(item) + # items = requests.get(rtc.base_url + 'service/items') + # service = json.loads(items.text) + # limit = len(service) + # random_service = [random.randint(1, limit) for itr in range(limit)] + # # test sequentially + # for item in random_service: + # pl = {'max': 1, 'min': 1, 'name': 'service_item_show', 'payload': {'item': item}} + # rtc.pending.append(Task(rtc, pl)) + + +def get_themes(rtc: object) -> str: + print_text('get_themes') + ret = requests.get(rtc.base_url + 'controller/themes') + assert ret.status_code == 200, ret.status_code + return ret.text + + +def get_default_theme(rtc: object) -> None: + print_text('get_default_theme') + ret = requests.get(rtc.base_url + 'controller/theme') + assert ret.status_code == 204, ret.status_code + + +def get_themes_name(rtc: object, payload: dict) -> None: + t_name = payload['theme_name'] + print_text('get_themes_name') + ret = requests.get(rtc.base_url + f'themes/{t_name}') + assert ret.status_code == 204, ret.status_code + + +def get_live_theme(rtc: object) -> None: + print_text('get_live_theme') + ret = requests.get(rtc.base_url + 'live_theme') + assert ret.status_code == 204, ret.status_code + + +def get_theme_level(rtc: object) -> None: + print_text('get_theme_level') + ret = requests.get(rtc.base_url + 'theme_level') + assert ret.status_code == 204, ret.status_code + + +def set_theme_level(rtc: object, payload: dict) -> None: + t_level = payload['theme_level'] + print_text('set_theme_level') + ret = requests.post(rtc.base_url + 'theme_level', json=dict(level=t_level)) + assert ret.status_code == 204, ret.status_code + + +def set_theme(rtc: object, payload: dict) -> None: + t_level = payload['theme_level'] + print_text('set_theme_level') + ret = requests.post(rtc.base_url + 'theme_level', json=dict(level=t_level)) + assert ret.status_code == 204, ret.status_code + + +def display_hide(rtc: object) -> None: + print_text('display_hide') + ret = requests.post(rtc.base_url + 'core/display', json=dict(display='hide')) + assert ret.status_code == 204, ret.status_code + + +def display_show(rtc: object) -> None: + print_text('display_show') + ret = requests.post(rtc.base_url + 'core/display', json=dict(display='show')) + assert ret.status_code == 204, ret.status_code + + +def display_blank(rtc: object) -> None: + print_text('display_blank') + ret = requests.post(rtc.base_url + 'core/display', json=dict(display='blank')) + assert ret.status_code == 204, ret.status_code + + +def display_theme(rtc: object) -> None: + print_text('display_theme') + ret = requests.post(rtc.base_url + 'core/display', json=dict(display='theme')) + assert ret.status_code == 204, ret.status_code + + +def display_desktop(rtc: object) -> None: + print_text('display_desktop') + ret = requests.post(rtc.base_url + 'core/display', json=dict(display='desktop')) + assert ret.status_code == 204, ret.status_code diff --git a/test_api/apitest/logger.py b/test_api/apitest/logger.py index fe9a49c..81e8536 100644 --- a/test_api/apitest/logger.py +++ b/test_api/apitest/logger.py @@ -23,24 +23,24 @@ init(autoreset=True) def print_text(text: str): - print(Fore.LIGHTMAGENTA_EX + '[*] = ' + text) + print(Fore.LIGHTMAGENTA_EX + f'[*] {text}') def print_error(text: str): - print(Fore.RED + '[-] = ' + text) + print(Fore.RED + f'[-] {text}') def print_ok(text: str): - print(Fore.GREEN + '[_] = ' + text) + print(Fore.GREEN + f'[_] {text}') def print_warn(text: str): - print(Fore.YELLOW + '[?] = ' + text) + print(Fore.YELLOW + f'[?] {text}') def print_info(text: str): - print(Fore.MAGENTA + '[!] = ' + text) + print(Fore.MAGENTA + f'[!] {text}') def print_debug(text: str): - print(Fore.CYAN + '[#] = ' + text) + print(Fore.CYAN + f'[#] {text}') diff --git a/test_api/apitest/runner.py b/test_api/apitest/runner.py index c21befc..ff11004 100644 --- a/test_api/apitest/runner.py +++ b/test_api/apitest/runner.py @@ -116,7 +116,8 @@ class RunTestsController(object): parser = argparse.ArgumentParser() parser.add_argument('rargs', nargs='*', default=[]) a = parser.parse_args() - with open(a.rargs[0], 'r') as file: + f_open = f'{a.rargs[0]}' + with open(f_open, 'r') as file: commands = yaml.load(file, Loader=yaml.FullLoader) for step in commands: if step == 'process_name': diff --git a/test_api/apitest/task.py b/test_api/apitest/task.py index 2e9f5cd..89f676b 100644 --- a/test_api/apitest/task.py +++ b/test_api/apitest/task.py @@ -23,6 +23,11 @@ from test_api.apitest.callbacks import * # noqa E403 def human_delay(delay: int = 2) -> None: + """ + Delay time in Seconds + :param delay: + :return: + """ time.sleep(delay) diff --git a/test_api/apitest/zero.py b/test_api/apitest/zero.py index aa96a89..12a07cd 100644 --- a/test_api/apitest/zero.py +++ b/test_api/apitest/zero.py @@ -36,8 +36,9 @@ def check_for_openlp(type: str) -> str: def add_service(self, zeroconf: Zeroconf, type: str, name: str): info = zeroconf.get_service_info(type, name) - print_info(f'Service {name} added, service info: {info}') + # print_info(f'Service {name} added, service info: {info}') if info.name.startswith("OpenLP"): + print_info(f'Service {name} found') self.port = str(info.port) self.address = socket.inet_ntoa(info.addresses[0]) diff --git a/test_api/runner.py b/test_api/runner.py index 270b5ca..7adc814 100644 --- a/test_api/runner.py +++ b/test_api/runner.py @@ -27,11 +27,11 @@ def start() -> None: Instantiate and run the tests. :return: """ - print_text('OpenLP - API Test Runner V0_2') + print_text('OpenLP - API Test Runner V0_3') print_text('Check OpenLP is running') op_address, op_http_port = check_for_openlp('http') if not op_http_port: - print_error('OpenLP is not running ') + print_error('OpenLP is not running - aborting') return else: print_ok(f'OpenLP is running on port (http) {op_http_port}')