core/tests/tavern_utils/validate_controller.py

46 lines
1.7 KiB
Python
Raw Normal View History

import json
import validate_relay
def _verify_single(controller):
assert isinstance(controller.get("id"), str), "controller id is not a string"
assert isinstance(controller.get("name"), str), "controller name is not a string"
assert isinstance(controller.get("relay_count"), int), "controller relay_count is not an integer"
assert isinstance(controller.get("relays"), list), "controller relays is not a list"
assert len(controller.get("relays")) == controller.get("relay_count"), "controller relay have a length unequal to relay_count"
for relay in controller.get("relays"):
assert isinstance(relay, dict), "controller relays contain a relay which is not a dict"
validate_relay._verify_single(relay)
assert relay.get("controller_id") == controller.get("id")
def single(response):
_verify_single(response.json())
def multiple(response):
assert isinstance(response.json(), list), "response is not a list"
for controller in response.json():
_verify_single(controller)
def check_id(response, id):
assert response.json().get("id") == id, "controller id check failed"
def check_name(response, name):
assert response.json().get("name") == name, "controller name check failed"
def check_ip(response, ip):
assert response.json().get("ip") == ip, "controller ip check failed"
def find(response, id=None, name=None):
print(response.json())
for controller in response.json():
if id != None and id != controller.get("id"):
print(controller.get("id"))
continue
if name != None and name != controller.get("name"):
print(controller.get("name"))
continue
return
assert False, "controller not found in list"