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 find(response, id=None, name=None): for controller in response.json(): if id != None and id != schedule.get("id"): print(schedule.get("id")) continue if name != None and name != schedule.get("name"): print(schedule.get("name")) continue return assert False, "controller not found in list"