controller/tests/tavern_utils/validate_relay.py
Tobias Reisinger 2af71a8d84 Readd tests
Just copied from old version. Most will fail and run_tests.sh is not
working.
2022-04-03 01:36:18 +02:00

68 lines
2.6 KiB
Python

import json
import validate_schedule
def _verify_single(relay):
assert isinstance(relay.get("number"), int), "relay number is not an integer"
assert isinstance(relay.get("name"), str), "relay name is not a string"
assert isinstance(relay.get("controller_id"), str), "relay controller_id is not a string"
assert isinstance(relay.get("active_schedule"), dict), "relay active_schedule is not a dict"
validate_schedule._verify_single(relay.get("active_schedule"))
assert isinstance(relay.get("schedules"), list), "relay schedules is not a list"
assert len(relay.get("schedules")) == 7, "relay schedule have a length unequal to 7"
for schedule in relay.get("schedules"):
assert isinstance(relay, dict), "relay schedules contain a schedule which is not a dict"
validate_schedule._verify_single(schedule)
assert isinstance(relay.get("tags"), list), "relay tags is not a list"
for tag in relay.get("tags"):
assert isinstance(tag, str), "relay tags contain a tag which is not a string"
def single(response):
_verify_single(response.json())
def multiple(response):
assert isinstance(response.json(), list), "response is not a list"
for relay in response.json():
_verify_single(relay)
def relay_count(response, relay_count):
assert len(response.json()) == relay_count, "response has invalid length"
def check_number(response, number):
assert response.json().get("number") == number, "relay number check failed"
def check_name(response, name):
assert response.json().get("name") == name, "relay name check failed"
def check_controller_id(response, controller_id):
assert response.json().get("controller_id") == controller_id, "relay controller_id check failed"
def check_tag(response, tag):
for response_tag in response.json().get("tags"):
if response_tag == tag:
return
assert False, "tag not found in relay,"
def find(response, name=None, number=None, controller_id=None, tag=None):
print(response.json())
for relay in response.json():
if number != None and number != relay.get("number"):
continue
if name != None and name != relay.get("name"):
continue
if controller_id != None and controller_id != relay.get("controller_id"):
continue
if tag != None:
found_in_response = False
for response_tag in relay.get("tags"):
if response_tag == tag:
found_in_response = True
if not found_in_response:
continue
return
assert False, "relay not found in list"