From 114cfa6b171b5c0ec0341ffce893f8e1fc94f870 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 8 Mar 2016 17:46:00 +0000 Subject: [PATCH] Use the validation error message from the InvalidEmailError --- app/schemas.py | 12 ++++++------ tests/app/invite/test_invite_rest.py | 2 +- tests/app/notifications/test_rest.py | 2 +- tests/app/user/test_rest.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/schemas.py b/app/schemas.py index 36bd1995f..6fdb67eff 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -138,8 +138,8 @@ class EmailNotificationSchema(NotificationSchema): def validate_to(self, value): try: validate_email_address(value) - except InvalidEmailError: - raise ValidationError('Invalid email') + except InvalidEmailError as e: + raise ValidationError(e.message) class SmsTemplateNotificationSchema(SmsNotificationSchema): @@ -176,8 +176,8 @@ class InvitedUserSchema(BaseSchema): def validate_to(self, value): try: validate_email_address(value) - except InvalidEmailError: - raise ValidationError('Invalid email') + except InvalidEmailError as e: + raise ValidationError(e.message) class PermissionSchema(BaseSchema): @@ -204,8 +204,8 @@ class EmailDataSchema(ma.Schema): def validate_email(self, value): try: validate_email_address(value) - except InvalidEmailError: - raise ValidationError('Invalid email') + except InvalidEmailError as e: + raise ValidationError(e.message) user_schema = UserSchema() user_schema_load_json = UserSchema(load_json=True) diff --git a/tests/app/invite/test_invite_rest.py b/tests/app/invite/test_invite_rest.py index c6299c740..2731efc82 100644 --- a/tests/app/invite/test_invite_rest.py +++ b/tests/app/invite/test_invite_rest.py @@ -90,7 +90,7 @@ def test_create_invited_user_invalid_email(notify_api, sample_service, mocker): assert response.status_code == 400 json_resp = json.loads(response.get_data(as_text=True)) assert json_resp['result'] == 'error' - assert json_resp['message'] == {'email_address': ['Invalid email']} + assert json_resp['message'] == {'email_address': ['Not a valid email address']} app.celery.tasks.email_invited_user.apply_async.assert_not_called() diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index 5d8ed0b73..941e556a2 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -582,7 +582,7 @@ def test_should_reject_email_notification_with_bad_email(notify_api, sample_emai app.celery.tasks.send_email.apply_async.assert_not_called() assert response.status_code == 400 assert data['result'] == 'error' - assert data['message']['to'][0] == 'Invalid email' + assert data['message']['to'][0] == 'Not a valid email address' def test_should_reject_email_notification_with_template_id_that_cant_be_found( diff --git a/tests/app/user/test_rest.py b/tests/app/user/test_rest.py index 8dc51b6b2..466cf0c50 100644 --- a/tests/app/user/test_rest.py +++ b/tests/app/user/test_rest.py @@ -488,4 +488,4 @@ def test_send_user_reset_password_should_return_400_when_data_is_not_email_addre headers=[('Content-Type', 'application/json'), auth_header]) assert resp.status_code == 400 - assert json.loads(resp.get_data(as_text=True))['message'] == {'email': ['Invalid email']} + assert json.loads(resp.get_data(as_text=True))['message'] == {'email': ['Not a valid email address']}