Skip to content

Commit

Permalink
[OpenDataServices/cove#895] Add error_id to new ValidationError
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Oct 8, 2019
1 parent 9222f25 commit a296836
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libcove/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ def oneOf_draft4(validator, oneOf, instance, schema):
yield err
return
else:
yield ValidationError(
err = ValidationError(
"This array should contain either entirely embedded releases or "
"linked releases. Embedded releases contain an 'id' whereas linked "
"releases do not. Your releases contain a mixture."
)
err.error_id = 'releases_both_embedded_and_linked'
yield err
break

all_errors.extend(errs)
Expand Down Expand Up @@ -694,6 +696,7 @@ def get_schema_validation_errors(json_data, schema_obj, schema_name, cell_src_ma
('header', header),
('header_extra', header_extra),
('null_clause', null_clause),
('error_id', e.error_id if hasattr(e, 'error_id') else None),
])
validation_errors[json.dumps(unique_validator_key)].append(value)
return dict(validation_errors)
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def test_validation_invalid_record_package():

assert validation_error_jsons == [
{
'error_id': None,
"message": "'date' is missing but required within 'releases'",
"message_safe": "<code>date</code> is missing but required within <code>releases</code>",
"validator": "required",
Expand All @@ -247,6 +248,7 @@ def test_validation_invalid_record_package():
"values": [{"path": "records/2/releases/0"}],
},
{
'error_id': None,
"message": "'date' is missing but required within 'releases'",
"message_safe": "<code>date</code> is missing but required within <code>releases</code>",
"validator": "required",
Expand All @@ -262,6 +264,7 @@ def test_validation_invalid_record_package():
],
},
{
'error_id': None,
"message": "'initiationType' is missing but required within 'releases'",
"message_safe": "<code>initiationType</code> is missing but required within <code>releases</code>",
"validator": "required",
Expand All @@ -274,6 +277,7 @@ def test_validation_invalid_record_package():
"values": [{"path": "records/2/releases/0"}],
},
{
'error_id': None,
"message": "'ocid' is missing but required within 'releases'",
"message_safe": "<code>ocid</code> is missing but required within <code>releases</code>",
"validator": "required",
Expand All @@ -286,6 +290,7 @@ def test_validation_invalid_record_package():
"values": [{"path": "records/2/releases/0"}],
},
{
'error_id': None,
"message": "'releases' is not a JSON array",
"message_safe": "<code>releases</code> is not a JSON array",
"validator": "type",
Expand All @@ -302,6 +307,7 @@ def test_validation_invalid_record_package():
],
},
{
'error_id': None,
"message": "'tag' is missing but required within 'releases'",
"message_safe": "<code>tag</code> is missing but required within <code>releases</code>",
"validator": "required",
Expand All @@ -314,6 +320,7 @@ def test_validation_invalid_record_package():
"values": [{"path": "records/2/releases/0"}],
},
{
'error_id': None,
"message": "'url' is missing but required within 'releases'",
"message_safe": "<code>url</code> is missing but required within <code>releases</code>",
"validator": "required",
Expand All @@ -326,6 +333,7 @@ def test_validation_invalid_record_package():
"values": [{"path": "records/1/releases/0"}],
},
{
'error_id': 'releases_both_embedded_and_linked',
"message": "This array should contain either entirely embedded releases or linked releases. "
"Embedded releases contain an 'id' whereas linked releases do not. "
"Your releases contain a mixture.",
Expand All @@ -342,6 +350,7 @@ def test_validation_invalid_record_package():
"values": [{"path": "records/4/releases"}, {"path": "records/5/releases"}],
},
{
'error_id': None,
"message": "[] is too short",
"message_safe": "<code>[]</code> is too short. "
"You must supply at least one value, or remove the item entirely (unless it’s required).",
Expand Down

0 comments on commit a296836

Please sign in to comment.