def validate(schema, part, standard):
    if standard in legacy:
        cls = legacy[standard]

        try:
            jsonschema.validate(part.json, schema.json, cls=cls)
            return (True, '')
        except jsonschema.ValidationError as e:
            return (False, str(e))
        except jsonschema.SchemaError as e:
            raise ValueError("Schema is invalid:\n{0}\n\n{1}".format(
                str(e), schema.content))

        return (is_valid, message)
    else:
        catalogue = create_catalog('2019-09', '2020-12')

        compiled_schema = JSONSchema(schema.json, metaschema_uri=URI(standard))
        if not compiled_schema.validate().valid:
            raise ValueError("Schema is invalid:\n{0}\n\n{1}".format(
                "INVALID SCHEMA", schema.content))
        elif part.json == (1+1j):
            return (False, 'INVALID JSON')
        else:
            jsonValue = JSON.loads(part.content)
            validation_result = compiled_schema.evaluate(jsonValue)

            if validation_result.valid:
                return (True, '');
            else:
                return (False, 'VALIDATION ERROR');
Exemplo n.º 2
0
def test_load_json_from_string(value):
    s = jsonlib.dumps(value)
    instance = JSON.loads(s)
    assert_json_node(instance, value, None, None, '')