mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-05 00:18:25 -04:00
Create dict for the fields in the error response.
This commit is contained in:
@@ -15,6 +15,8 @@ def build_error_message(errors, schema):
|
|||||||
for e in errors:
|
for e in errors:
|
||||||
field = "'{}' {}".format(e.path[0], e.schema.get('validationMessage')) if e.schema.get(
|
field = "'{}' {}".format(e.path[0], e.schema.get('validationMessage')) if e.schema.get(
|
||||||
'validationMessage') else e.message
|
'validationMessage') else e.message
|
||||||
|
s = field.split("'")
|
||||||
|
field = {s[1]: s[2].strip()}
|
||||||
fields.append(field)
|
fields.append(field)
|
||||||
message = {
|
message = {
|
||||||
"code": "1001",
|
"code": "1001",
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ def test_post_sms_json_schema_bad_uuid_and_missing_phone_number():
|
|||||||
error = json.loads(e.value.message)
|
error = json.loads(e.value.message)
|
||||||
assert "POST v2/notifications/sms" in error['message']
|
assert "POST v2/notifications/sms" in error['message']
|
||||||
assert len(error.get('fields')) == 2
|
assert len(error.get('fields')) == 2
|
||||||
assert "'phone_number' is a required property" in error['fields']
|
assert {"phone_number": "is a required property"} in error['fields']
|
||||||
assert "'template_id' not a valid UUID" in error['fields']
|
assert {"template_id": "not a valid UUID"} in error['fields']
|
||||||
assert error.get('code') == '1001'
|
assert error.get('code') == '1001'
|
||||||
assert error.get('link', None) is not None
|
assert error.get('link', None) is not None
|
||||||
|
|
||||||
@@ -48,9 +48,9 @@ def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
|
|||||||
error = json.loads(e.value.message)
|
error = json.loads(e.value.message)
|
||||||
assert "POST v2/notifications/sms" in error['message']
|
assert "POST v2/notifications/sms" in error['message']
|
||||||
assert len(error.get('fields')) == 1
|
assert len(error.get('fields')) == 1
|
||||||
assert error['fields'][0] == "'personalisation' should contain key value pairs"
|
assert error['fields'][0] == {"personalisation": "should contain key value pairs"}
|
||||||
assert error.get('code') == '1001'
|
assert error.get('code') == '1001'
|
||||||
assert error.get('link', None) is not None
|
assert error.get('link', None) == 'link to error documentation (not yet implemented)'
|
||||||
|
|
||||||
|
|
||||||
valid_response = {
|
valid_response = {
|
||||||
@@ -85,4 +85,8 @@ def test_post_sms_response_schema_missing_uri():
|
|||||||
del j["uri"]
|
del j["uri"]
|
||||||
with pytest.raises(ValidationError) as e:
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(j, post_sms_response)
|
validate(j, post_sms_response)
|
||||||
assert 'uri' in e.value.message
|
error = json.loads(e.value.message)
|
||||||
|
assert '1001' == error['code']
|
||||||
|
assert 'link to error documentation (not yet implemented)' == error['link']
|
||||||
|
assert 'Validation error occurred - response v2/notifications/sms' == error['message']
|
||||||
|
assert [{"uri": "is a required property"}] == error['fields']
|
||||||
|
|||||||
@@ -103,4 +103,4 @@ def test_post_sms_notification_returns_400_and_for_schema_problems(notify_api, s
|
|||||||
assert error_resp['code'] == '1001'
|
assert error_resp['code'] == '1001'
|
||||||
assert error_resp['message'] == 'Validation error occurred - POST v2/notifications/sms'
|
assert error_resp['message'] == 'Validation error occurred - POST v2/notifications/sms'
|
||||||
assert error_resp['link'] == "link to error documentation (not yet implemented)"
|
assert error_resp['link'] == "link to error documentation (not yet implemented)"
|
||||||
assert error_resp['fields'] == ["'template_id' is a required property"]
|
assert error_resp['fields'] == [{"template_id": "is a required property"}]
|
||||||
|
|||||||
Reference in New Issue
Block a user