Master update

This commit is contained in:
Tim Bentley 2020-10-04 19:00:31 +00:00
parent c74aaeda91
commit 4df94691e8
14 changed files with 79 additions and 161 deletions

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
########################################################################## ##########################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #

View File

@ -82,5 +82,4 @@ step17:
payload: payload:
plugin: bibles plugin: bibles
step18: step18:
delay: 0.1
name: load_service_sequential name: load_service_sequential

View File

@ -82,5 +82,4 @@ step17:
payload: payload:
plugin: bibles plugin: bibles
step18: step18:
delay: 0.1
name: load_service_random name: load_service_random

View File

@ -1,5 +1,5 @@
--- ---
process_name: test process process_name: play media
step1: step1:
max: 1 max: 1
min: 1 min: 1
@ -8,36 +8,14 @@ step2:
delay: 1 delay: 1
name: clear_preview_controller name: clear_preview_controller
step3: step3:
max: 1 delay: 10
min: 1
name: new_service
step4:
delay: 5
name: media_play
step5:
delay: 1
name: clear_preview_controller
step6:
max: 1
min: 1
name: new_service
step7:
delay: 1
name: search_and_add name: search_and_add
payload: payload:
plugin: media plugin: media
step8: step4:
delay: 5 name: load_service_sequential
name: media_play step5:
step9: delay: 30
delay: 5 name: flush_pending
step6:
name: media_pause name: media_pause
step10:
delay: 5
name: media_pause
step11:
delay: 5
name: media_play
step12:
delay: 5
name: media_stop

4
pause.yaml Normal file
View File

@ -0,0 +1,4 @@
---
process_name: Pause Media
step1:
name: media_pause

4
play.yaml Normal file
View File

@ -0,0 +1,4 @@
---
process_name: Play Media
step1:
name: media_play

4
stop.yaml Normal file
View File

@ -0,0 +1,4 @@
---
process_name: Stop Media
step1:
name: media_stop

View File

@ -20,7 +20,6 @@ step5:
delay: 1 delay: 1
name: search_and_add name: search_and_add
payload: payload:
plugin: songs plugin: bibles
step6: step6:
delay: 0.1
name: load_service_sequential name: load_service_sequential

View File

@ -1,24 +0,0 @@
import yaml
# ...
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('rargs', nargs='*', default=[])
a = parser.parse_args()
with open(a.rargs[0], 'r') as file:
# The FullLoader parameter handles the conversion from YAML
# scalar values to Python the dictionary format
xx = yaml.load(file)
print(yaml.dump(xx))
for x in xx:
print(x)
print(xx[x])
c = xx[x]
print(c)
if isinstance(c, str):
pass
else:
try:
print(c['delay'])
except KeyError:
pass

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
########################################################################## ##########################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
@ -67,7 +66,7 @@ def search_and_add(rtc: object, payload: dict) -> None:
while True: while True:
let = random.choice(string.ascii_letters) let = random.choice(string.ascii_letters)
ret = requests.get(rtc.base_url + f'plugins/{plugin}/search?text={let}') ret = requests.get(rtc.base_url + f'plugins/{plugin}/search?text={let}')
if ret.status_code == 200: if ret.status_code == 200 and ret.text != '[]\n':
break break
else: else:
let = random.choice(string.ascii_letters) let = random.choice(string.ascii_letters)
@ -104,6 +103,12 @@ def search_and_live(rtc: object, payload: dict) -> None:
assert ret.status_code == 204, f'{ret.status_code} returned from add' assert ret.status_code == 204, f'{ret.status_code} returned from add'
def flush_pending(rtc: object) -> None:
print_text('Flush pending to start of tasks')
pend = rtc.pending.popleft()
rtc.tasks.insert(0, pend)
def media_play(rtc: object) -> None: def media_play(rtc: object) -> None:
print_text('Media_play') print_text('Media_play')
ret = requests.post(rtc.base_url + 'media/play') ret = requests.post(rtc.base_url + 'media/play')
@ -113,38 +118,36 @@ def media_play(rtc: object) -> None:
def media_pause(rtc: object) -> None: def media_pause(rtc: object) -> None:
print_text('Media_pause') print_text('Media_pause')
ret = requests.post(rtc.base_url + 'media/pause') ret = requests.post(rtc.base_url + 'media/pause')
assert ret.status_code == 204, f'{ret.status_code} returned' assert ret.status_code == 400, f'{ret.status_code} returned'
def media_stop(rtc: object) -> None: def media_stop(rtc: object) -> None:
print_text('Media_stop') print_text('Media_stop')
ret = requests.post(rtc.base_url + 'media/stop') ret = requests.post(rtc.base_url + 'media/stop')
assert ret.status_code == 204, f'{ret.status_code} returned' assert ret.status_code == 400, f'{ret.status_code} returned'
def load_service_sequential(rtc: object) -> None: def load_service_sequential(rtc: object) -> None:
print_text('Load__service_sequential') print_text('Load_service_sequential')
items = requests.get(rtc.base_url + 'service/items') items = requests.get(rtc.base_url + 'service/items')
service = json.loads(items.text) service = json.loads(items.text)
# test sequentially # test sequentially
for item in service: for item in service:
if item['plugin'] == 'video': pl = {'max': 1, 'min': 1, 'name': 'service_item_show', 'payload': {'item': item}}
pass rtc.pending.append(Task(rtc, pl))
else:
pl = {'max': 1, 'min': 1, 'name': 'service_item_show', 'payload': {'item': item}}
rtc.pending.append(Task(rtc, pl))
def service_item_show(rtc: object, payload: dict) -> None: def service_item_show(rtc: object, payload: dict) -> None:
item = payload['item']
print_text('Service_item_show') print_text('Service_item_show')
item = payload['item']
title = item['title'] title = item['title']
id = item['id'] id = item['id']
print_text(f'test_service_song {title} {id}') print_text(f'test_service_item {title} {id}')
ret = requests.post(rtc.base_url + 'service/show', json=dict(uid=id)) ret = requests.post(rtc.base_url + 'service/show', json=dict(uid=id))
assert ret.status_code == 204, ret.status_code assert ret.status_code == 204, ret.status_code
pl = {'max': 1, 'min': 2, 'name': 'play_live_item', 'payload': {'item': item}} if not item['plugin'] == 'media':
rtc.tasks.append(Task(rtc, pl)) pl = {'max': 1, 'min': 2, 'delay': 0.5, 'name': 'play_live_item', 'payload': {'item': item}}
rtc.tasks.append(Task(rtc, pl))
def play_live_item(rtc: object, payload: dict) -> None: def play_live_item(rtc: object, payload: dict) -> None:
@ -155,7 +158,7 @@ def play_live_item(rtc: object, payload: dict) -> None:
assert ret.status_code == 200, f'{ret.status_code} returned from live_item' 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):
pl = {'max': 1, 'min': 2, 'delay': 0.2, 'name': 'controller_item_show', 'payload': {'id': i}} pl = {'max': 1, 'min': 2, 'delay': 0.5, 'name': 'controller_item_show', 'payload': {'id': i}}
rtc.tasks.append(Task(rtc, pl)) rtc.tasks.append(Task(rtc, pl))
i += 1 i += 1
assert ret.status_code == 200, f'{ret.status_code} returned from show' assert ret.status_code == 200, f'{ret.status_code} returned from show'

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
########################################################################## ##########################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
@ -21,16 +20,18 @@
import argparse import argparse
import threading import threading
import websocket import websocket
import time
import yaml import yaml
from collections import deque from collections import deque
from websocket import create_connection from websocket import create_connection
from test_api.apitest.logger import print_error, print_ok, print_info, print_debug
from test_api.apitest.callbacks import * # noqa E403 from test_api.apitest.callbacks import * # noqa E403
from test_api.apitest.logger import print_error, print_ok, print_info
# from test_api.apitest.logger import print_debug
from test_api.apitest.task import Task from test_api.apitest.task import Task
from test_api.apitest.task import human_delay
class RunTestsController(object): class RunTestsController(object):
@ -45,6 +46,7 @@ class RunTestsController(object):
self.received = False self.received = False
self.tasks = deque() self.tasks = deque()
self.pending = deque() self.pending = deque()
self.ws_data = deque()
self.base_url = f'http://{self.address}:{self.http_port}/api/v2/' self.base_url = f'http://{self.address}:{self.http_port}/api/v2/'
def connect(self) -> None: def connect(self) -> None:
@ -67,10 +69,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:
# print_debug("Message returned") print_debug(f"Message returned: {message}")
self.result_stage = message if not self.received:
self.compare_stage() self.reserved_result_stage = message
self.received = True else:
self.ws_data.append(message)
def on_open(self) -> None: def on_open(self) -> None:
print_info("Socket Listener Opened") print_info("Socket Listener Opened")
@ -82,6 +85,11 @@ class RunTestsController(object):
print_error(f'WebSocket Error: {error}') 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:
"""
Method to make connect to webspockets
:param first_run:
:return:
"""
ws = create_connection(f'ws://{self.address}:{self.ws_port}', ping_interval=None) ws = create_connection(f'ws://{self.address}:{self.ws_port}', ping_interval=None)
if first_run: if first_run:
print_text('Establishing Connection to State') print_text('Establishing Connection to State')
@ -105,7 +113,6 @@ class RunTestsController(object):
a = parser.parse_args() a = parser.parse_args()
with open(a.rargs[0], 'r') as file: with open(a.rargs[0], 'r') as file:
commands = yaml.load(file, Loader=yaml.FullLoader) commands = yaml.load(file, Loader=yaml.FullLoader)
for step in commands: for step in commands:
if step == 'process_name': if step == 'process_name':
print_info(f'Processing file {commands[step]}') print_info(f'Processing file {commands[step]}')
@ -117,19 +124,17 @@ 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'] # compare_strings(reserved, current)
self.received = False if len(reserved) > 0:
# compare_strings(reserved, current) assert len(reserved) == len(current)
if len(reserved) > 0: for a, _ in current.items():
assert len(reserved) == len(current) # compare_strings(reserved[a], current[a])
for a, _ in current.items(): if reserved[a] != current[a]:
# compare_strings(reserved[a], current[a]) self.stage_diff[a] = {'before': reserved[a], 'after': current[a]}
if reserved[a] != current[a]: self.reserved_result_stage = self.result_stage
self.stage_diff[a] = {'before': reserved[a], 'after': current[a]}
self.reserved_result_stage = self.result_stage
def process_queue(self): def process_queue(self):
while len(self.tasks) > 0: while len(self.tasks) > 0:
@ -141,7 +146,7 @@ class RunTestsController(object):
self.tasks.append(pend) self.tasks.append(pend)
def load_service_sequential(self) -> None: def load_service_sequential(self) -> None:
print_text('Load_and_process_service_sequential') print_text('Load_and_process_service_sequential - old')
items = requests.get(f'http://{self.address}:{self.http_port}/api/v2/service/items') items = requests.get(f'http://{self.address}:{self.http_port}/api/v2/service/items')
service = json.loads(items.text) service = json.loads(items.text)
# test sequentially # test sequentially
@ -152,7 +157,7 @@ class RunTestsController(object):
service_item_show(self, item) service_item_show(self, item)
def load_service_random(self) -> None: def load_service_random(self) -> None:
print_text('Load_and process_service_random') print_text('Load_and process_service_random - old')
items = requests.get(f'http://{self.address}:{self.http_port}/api/v2/service/items') items = requests.get(f'http://{self.address}:{self.http_port}/api/v2/service/items')
service = json.loads(items.text) service = json.loads(items.text)
limit = len(service) limit = len(service)
@ -162,17 +167,16 @@ class RunTestsController(object):
item = service[pos - 1] item = service[pos - 1]
service_item_show(self, item) service_item_show(self, item)
def check_websocket_changes(self, manditary: int, optional: int) -> None: def check_websocket_changes(self, manditory: int, optional: int) -> None:
count = 0 while len(self.ws_data) > 0:
while not self.received and count < 200: message = self.ws_data.popleft()
time.sleep(0.1) self.result_stage = message
count += 1 self.compare_stage()
self.compare_stage() if manditory <= len(self.stage_diff) <= manditory + optional:
if manditary <= len(self.stage_diff) <= manditary + optional: pass
pass else:
else: print(f'{manditory} stage field(s) must have changed and '
print(f'{manditary} stage field(s) must have changed and ' f'{optional} may change changed- {str(self.stage_diff)}')
f'{optional} may change changed- {str(self.stage_diff)}')
def compare_strings(a, b): def compare_strings(a, b):
@ -189,49 +193,3 @@ def compare_strings(a, b):
else: else:
if a != b: if a != b:
print('{} => {} are different'.format(a, b)) print('{} => {} are different'.format(a, b))
def human_delay(delay: int = 2) -> None:
time.sleep(delay)
def media_play(rtc: RunTestsController) -> None:
print_text('Media_play')
base_url = f'http://{rtc.address}:{rtc.http_port}/api/v2/'
ret = requests.post(base_url + 'media/play')
assert ret.status_code == 400, f'{ret.status_code} returned'
human_delay()
def media_pause(rtc: RunTestsController) -> None:
print_text('Media_pause')
base_url = f'http://{rtc.address}:{rtc.http_port}/api/v2/'
ret = requests.post(base_url + 'media/pause')
assert ret.status_code == 204, f'{ret.status_code} returned'
human_delay()
def media_stop(rtc: RunTestsController) -> None:
print_text('Media_stop')
base_url = f'http://{rtc.address}:{rtc.http_port}/api/v2/'
ret = requests.post(base_url + 'media/stop')
assert ret.status_code == 204, f'{ret.status_code} returned'
human_delay()
def new_service(rtc: RunTestsController) -> None:
print_text('New_service')
base_url = f'http://{rtc.address}:{rtc.http_port}/api/v2/'
ret = requests.get(base_url + 'service/new')
assert ret.status_code == 204, f'{ret.status_code} returned'
human_delay()
check_websocket_changes(rtc, 1, 1)
def check_websocket_changes(rtc: RunTestsController, manditary: int, optional: int) -> None:
while not rtc.received:
time.sleep(0.1)
if manditary <= len(rtc.stage_diff) <= optional:
pass
else:
print(f'{manditary} stage field(s) must have changed and {optional} may change changed- {str(rtc.stage_diff)}')

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
########################################################################## ##########################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
@ -48,7 +47,7 @@ class Task(object):
try: try:
human_delay(self.request['delay']) human_delay(self.request['delay'])
except KeyError: except KeyError:
pass human_delay(0.3)
try: try:
self.caller.check_websocket_changes(self.request['max'], self.request['min']) self.caller.check_websocket_changes(self.request['max'], self.request['min'])
except KeyError: except KeyError:

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
########################################################################## ##########################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #

View File

@ -1,6 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
########################################################################## ##########################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #