Change validation error message to a string from a dict.

This commit is contained in:
Rebecca Law
2016-11-10 16:30:51 +00:00
parent 7d763260ce
commit c758694b98
5 changed files with 11 additions and 10 deletions

View File

@@ -18,7 +18,7 @@ def build_error_message(errors, schema):
field = "'{}' {}".format(e.path[0], e.schema.get('validationMessage')) if e.schema.get(
'validationMessage') else e.message
s = field.split("'")
field = OrderedDict({"error": "ValidationError", "message": {s[1]: s[2].strip()}})
field = OrderedDict({"error": "ValidationError", "message": "{}{}".format(s[1], s[2])})
fields.append(field)
message = {
"status_code": 400,

View File

@@ -6,7 +6,7 @@ If the definition is specific to a version put it in a definition file in the ve
uuid = {
"type": "string",
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
"validationMessage": "not a valid UUID",
"validationMessage": "is not a valid UUID",
"code": "1001", # yet to be implemented
"link": "link to our error documentation not yet implemented"
}

View File

@@ -32,9 +32,9 @@ def test_post_sms_json_schema_bad_uuid_and_missing_phone_number():
assert error.get('status_code') == 400
assert len(error.get('errors')) == 2
assert {'error': 'ValidationError',
'message': {"phone_number": "is a required property"}} in error['errors']
'message': "phone_number is a required property"} in error['errors']
assert {'error': 'ValidationError',
'message': {"template_id": "not a valid UUID"}} in error['errors']
'message': "template_id is not a valid UUID"} in error['errors']
def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
@@ -49,7 +49,7 @@ def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
error = json.loads(e.value.message)
assert len(error.get('errors')) == 1
assert error['errors'] == [{'error': 'ValidationError',
'message': {"personalisation": "should contain key value pairs"}}]
'message': "personalisation should contain key value pairs"}]
assert error.get('status_code') == 400
assert len(error.keys()) == 2
@@ -89,4 +89,4 @@ def test_post_sms_response_schema_missing_uri():
error = json.loads(e.value.message)
assert error['status_code'] == 400
assert error['errors'] == [{'error': 'ValidationError',
'message': {"uri": "is a required property"}}]
'message': "uri is a required property"}]

View File

@@ -55,6 +55,7 @@ def test_post_sms_notification_returns_404_and_missing_template(notify_api, samp
assert response.headers['Content-type'] == 'application/json'
error_json = json.loads(response.get_data(as_text=True))
assert error_json['status_code'] == 400
assert error_json['errors'] == [{"error": "BadRequestError",
"message": 'Template not found'}]
@@ -98,7 +99,6 @@ def test_post_sms_notification_returns_400_and_for_schema_problems(notify_api, s
assert response.headers['Content-type'] == 'application/json'
error_resp = json.loads(response.get_data(as_text=True))
assert error_resp['status_code'] == 400
print(error_resp['errors'])
assert error_resp['errors'] == [{'error': 'ValidationError',
'message': {"template_id": "is a required property"}
'message': "template_id is a required property"
}]

View File

@@ -88,13 +88,14 @@ def test_validation_error(app_for_test):
response = client.get(url_for('v2_under_test.raising_validation_error'))
assert response.status_code == 400
error = json.loads(response.get_data(as_text=True))
print(error)
assert len(error.keys()) == 2
assert error['status_code'] == 400
assert len(error['errors']) == 2
assert {'error': 'ValidationError',
'message': {'phone_number': 'is a required property'}} in error['errors']
'message': "phone_number is a required property"} in error['errors']
assert {'error': 'ValidationError',
'message': {'template_id': 'not a valid UUID'}} in error['errors']
'message': "template_id is not a valid UUID"} in error['errors']
def test_data_errors(app_for_test):