Beispiel #1
0
def _test_schema(schema, response):
    start_t = time()

    if isinstance(schema, type):
        assert isinstance(response, schema)
    else:
        assert isinstance(response, type(schema))

    if response and isinstance(response, list):
        schema = schema[0]  # schema describe only one element
        for element in response:
            assert isinstance(element, type(schema))
            for key, value in element.items():
                try:
                    assert isinstance(value, schema[key])
                except AssertionError as err:
                    logging.debug("param::%s", key)
                    raise err
            # check missing keys (difference between schema and response)
            if element.keys() != schema.keys():
                if len(element.keys()) > len(schema.keys()):
                    missed_keys = set(element.keys()) - set(schema.keys())
                else:
                    missed_keys = set(schema.keys()) - set(element.keys())
                logging.warning("missed keys::%s", missed_keys)
    elif response and isinstance(response, dict):
        for key, value in response.items():
            _test_schema(schema[key], value)

    logging.info("Test run takes: %s seconds", time() - start_t)
Beispiel #2
0
def test_staffOfGroup():
    logging.warning("Group id may be deactivated in few years!")
    _test_schema(schema=RESPONSE_SCHEMA['staffOfGroup'],
                 response=ruz.staff_of_group(group_id=TRUSTED_GROUP_ID))
Beispiel #3
0
def test_schedule():
    logging.warning("Trusted emails may be deactivated in few years!")
    _test_schema(schema=RESPONSE_SCHEMA['schedule'],
                 response=ruz.person_lessons(email=TRUSTED_EMAILS['student']))