This commit is contained in:
Tobias Reisinger 2020-06-16 22:05:44 +02:00
parent 0460b2e9f7
commit 176483d72f
59 changed files with 11 additions and 45 deletions

View file

@ -0,0 +1,45 @@
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"

View file

@ -0,0 +1,68 @@
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"

View file

@ -0,0 +1,96 @@
import json
def _verify_single(schedule):
assert isinstance(schedule.get("id"), str), "schedule ID is not a string"
assert isinstance(schedule.get("name"), str), "schedule name is not a string"
assert isinstance(schedule.get("periods"), list), "schedule periods is not a list"
for period in schedule.get("periods"):
assert isinstance(period, dict), "schedule periods contain a periods which is not a dict"
assert isinstance(period.get("start"), str), "schedule periods contain a periods with start not being a string"
assert isinstance(period.get("end"), str), "schedule periods contain a periods with end not being a string"
assert isinstance(schedule.get("tags"), list), "schedule tags is not a list"
for tag in schedule.get("tags"):
assert isinstance(tag, str), "schedule 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 schedule in response.json():
_verify_single(schedule)
def check_name(response, name):
assert response.json().get("name") == name, "schedule name check failed"
def check_id(response, id):
assert response.json().get("id") == id, "schedule id check failed"
def check_periods(response, periods):
periods_json = json.loads(periods.replace("'", "\""))
assert len(periods_json) == len(response.json().get("periods")), "periods in response and request have different lengths"
for request_period in periods_json:
found_in_response = False
for response_period in response.json().get("periods"):
if response_period.get("start") != request_period.get("start"):
continue
if response_period.get("end") != request_period.get("end"):
continue
found_in_response = True
if not found_in_response:
print(request_period)
assert False, "a period from the request was missing from the response"
def check_tag(response, tag):
for response_tag in response.json().get("tags"):
if response_tag == tag:
return
assert False, "tag not found in schedule,"
def compare_off(response):
assert response.json().get("id") == "off", "schedule off did not return id off"
assert len(response.json().get("periods")) == 0, "schedule off has periods"
def compare_on(response):
assert response.json().get("id") == "on", "schedule on did not return id on"
assert len(response.json().get("periods")) == 1, "schedule on has unexpected amount of periods"
assert response.json().get("periods")[0].get("start") == "00:00", "Schedule on has unexpected start"
assert response.json().get("periods")[0].get("end") == "23:59", "Schedule on has unexpected start"
def find(response, id=None, name=None, periods=None, tag=None):
if periods != None:
periods_json = json.loads(periods.replace("'", "\""))
for schedule 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
if periods != None:
if len(periods_json) != len(schedule.get("periods")):
continue
for request_period in periods_json:
found_in_response = False
for response_period in schedule.get("periods"):
if response_period.get("start") != request_period.get("start"):
continue
if response_period.get("end") != request_period.get("end"):
continue
found_in_response = True
if not found_in_response:
continue
if tag != None:
found_in_response = False
for response_tag in schedule.get("tags"):
if response_tag == tag:
found_in_response = True
if not found_in_response:
continue
return
assert False, "schedule not found in list"

View file

@ -0,0 +1,34 @@
import json
def _verify_single(tag):
assert isinstance(tag, str), "tag 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 tag in response.json():
_verify_single(tag)
#def find(response, name=None, number=None, controller_id=None, tag=None):
# print(response.json())
# for tag in response.json():
# if number != None and number != tag.get("number"):
# continue
#
# if name != None and name != tag.get("name"):
# continue
#
# if controller_id != None and controller_id != tag.get("controller_id"):
# continue
#
# if tag != None:
# found_in_response = False
# for response_tag in tag.get("tags"):
# if response_tag == tag:
# found_in_response = True
# if not found_in_response:
# continue
# return
# assert False, "tag not found in list"