Remove print stmt and added assert error content

This commit is contained in:
Rebecca Law
2016-11-17 14:02:44 +00:00
parent bc434f1736
commit f5e3c6f63b
2 changed files with 14 additions and 8 deletions

View File

@@ -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)

View File

@@ -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 = {