2020-05-28 00:12:39 +00:00
|
|
|
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"
|
|
|
|
|
2020-05-31 22:45:08 +00:00
|
|
|
def check_ip(response, ip):
|
|
|
|
assert response.json().get("ip") == ip, "controller ip check failed"
|
|
|
|
|
2020-05-28 00:12:39 +00:00
|
|
|
def find(response, id=None, name=None):
|
2020-05-31 22:45:08 +00:00
|
|
|
print(response.json())
|
2020-05-28 00:12:39 +00:00
|
|
|
for controller in response.json():
|
2020-05-31 22:45:08 +00:00
|
|
|
if id != None and id != controller.get("id"):
|
|
|
|
print(controller.get("id"))
|
2020-05-28 00:12:39 +00:00
|
|
|
continue
|
|
|
|
|
2020-05-31 22:45:08 +00:00
|
|
|
if name != None and name != controller.get("name"):
|
|
|
|
print(controller.get("name"))
|
2020-05-28 00:12:39 +00:00
|
|
|
continue
|
|
|
|
return
|
|
|
|
assert False, "controller not found in list"
|
|
|
|
|