MCPcopy Create free account
hub / github.com/alephdata/aleph / validate

Function validate

aleph/views/util.py:58–81  ·  view source on GitHub ↗

Validate the data inside a request against a schema.

(data, schema)

Source from the content-addressed store, hash-verified

56
57
58def validate(data, schema):
59 """Validate the data inside a request against a schema."""
60 validator = get_validator(schema)
61 errors = {}
62 for error in validator.iter_errors(data):
63 path = ".".join((str(c) for c in error.path))
64 if path not in errors:
65 errors[path] = error.message
66 else:
67 errors[path] += "; " + error.message
68 log.info("ERROR [%s]: %s", path, error.message)
69
70 if not len(errors):
71 return data
72
73 resp = jsonify(
74 {
75 "status": "error",
76 "errors": errors,
77 "message": gettext("Error during data validation"),
78 },
79 status=400,
80 )
81 raise BadRequest(response=resp)
82
83
84def clean_object(data):

Callers 15

_load_metadataFunction · 0.90
test_role_schemaMethod · 0.90
test_notificationsMethod · 0.90
test_exports_indexMethod · 0.90
test_entityset_crudMethod · 0.90
test_indexMethod · 0.90
test_viewMethod · 0.90
test_update_validMethod · 0.90
test_statusMethod · 0.90

Calls 2

get_validatorFunction · 0.90
jsonifyFunction · 0.85

Tested by 15

test_role_schemaMethod · 0.72
test_notificationsMethod · 0.72
test_exports_indexMethod · 0.72
test_entityset_crudMethod · 0.72
test_indexMethod · 0.72
test_viewMethod · 0.72
test_update_validMethod · 0.72
test_statusMethod · 0.72
test_indexMethod · 0.72