mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
Remove print stmt and added assert error content
This commit is contained in:
@@ -42,4 +42,4 @@ def build_error_message(errors):
|
|||||||
def __format_message(e):
|
def __format_message(e):
|
||||||
s = e.message.split("'")
|
s = e.message.split("'")
|
||||||
msg = "{}{}".format(s[1], s[2])
|
msg = "{}{}".format(s[1], s[2])
|
||||||
return msg if not e.cause else "'{}' {}".format(e.path[0], e.cause.message)
|
return msg if not e.cause else "{} {}".format(e.path[0], e.cause.message)
|
||||||
|
|||||||
@@ -56,14 +56,19 @@ def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
|
|||||||
assert len(error.keys()) == 2
|
assert len(error.keys()) == 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('invalid_phone_number',
|
@pytest.mark.parametrize('invalid_phone_number, err_msg',
|
||||||
['08515111111', '07515111*11', 'notaphoneumber'])
|
[('08515111111', 'phone_number Not a UK mobile number'),
|
||||||
def test_post_sms_request_invalid_phone_number(invalid_phone_number):
|
('07515111*11', 'phone_number Must not contain letters or symbols'),
|
||||||
|
('notaphoneumber', 'phone_number Must not contain letters or symbols')])
|
||||||
|
def test_post_sms_request_invalid_phone_number(invalid_phone_number, err_msg):
|
||||||
j = {"phone_number": invalid_phone_number,
|
j = {"phone_number": invalid_phone_number,
|
||||||
"template_id": str(uuid.uuid4())
|
"template_id": str(uuid.uuid4())
|
||||||
}
|
}
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(j, post_sms_request)
|
validate(j, post_sms_request)
|
||||||
|
errors = json.loads(e.value.message).get('errors')
|
||||||
|
assert len(errors) == 1
|
||||||
|
assert {"error": "ValidationError", "message": err_msg} == errors[0]
|
||||||
|
|
||||||
|
|
||||||
def test_post_sms_request_invalid_phone_number_and_missing_template():
|
def test_post_sms_request_invalid_phone_number_and_missing_template():
|
||||||
@@ -71,9 +76,10 @@ def test_post_sms_request_invalid_phone_number_and_missing_template():
|
|||||||
}
|
}
|
||||||
with pytest.raises(ValidationError) as e:
|
with pytest.raises(ValidationError) as e:
|
||||||
validate(j, post_sms_request)
|
validate(j, post_sms_request)
|
||||||
error = json.loads(e.value.message)
|
errors = json.loads(e.value.message).get('errors')
|
||||||
print(error)
|
assert len(errors) == 2
|
||||||
assert len(error.get('errors')) == 2
|
assert {"error": "ValidationError", "message": "phone_number Not a UK mobile number"} in errors
|
||||||
|
assert {"error": "ValidationError", "message": "template_id is a required property"} in errors
|
||||||
|
|
||||||
|
|
||||||
valid_response = {
|
valid_response = {
|
||||||
|
|||||||
Reference in New Issue
Block a user