From aa43bd9e752f40e9523a13cdc065f399284639eb Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 13 Jan 2016 09:26:38 +0000 Subject: [PATCH] Add the new field to the application This commit replaces the previous `StringField` used for collecting mobile phone numbers with the `UKMobileNumber` field. This means changing a few of the preexisting tests to have more realistic mobile numbers so that they still pass. --- app/main/forms.py | 6 ++---- tests/app/main/views/test_code_not_received.py | 6 +++--- tests/app/main/views/test_register.py | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index 1229b61e4..0b18751c2 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -65,10 +65,8 @@ class UKMobileNumber(StringField): def mobile_number(): - mobile_number_regex = "^\\+44[\\d]{10}$" - return StringField('Mobile phone number', - validators=[DataRequired(message='Mobile number can not be empty'), - Regexp(regex=mobile_number_regex, message='Enter a +44 mobile number')]) + return UKMobileNumber('Mobile phone number', + validators=[DataRequired(message='Cannot be empty')]) def password(): diff --git a/tests/app/main/views/test_code_not_received.py b/tests/app/main/views/test_code_not_received.py index 367d138b4..af1081af4 100644 --- a/tests/app/main/views/test_code_not_received.py +++ b/tests/app/main/views/test_code_not_received.py @@ -67,7 +67,7 @@ def test_should_check_and_redirect_to_verify(notifications_admin, session['user_email'] = user.email_address verify_codes_dao.add_code(user.id, code='12345', code_type='sms') response = client.post(url_for('main.check_and_resend_text_code'), - data={'mobile_number': '+441234123412'}) + data={'mobile_number': '+447700900460'}) assert response.status_code == 302 assert response.location == url_for('main.verify', _external=True) @@ -103,11 +103,11 @@ def test_should_update_mobile_number_resend_code(notifications_admin, session['user_email'] = user.email_address verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms') response = client.post(url_for('main.check_and_resend_text_code'), - data={'mobile_number': '+443456789012'}) + data={'mobile_number': '+447700900460'}) assert response.status_code == 302 assert response.location == url_for('main.verify', _external=True) updated_user = users_dao.get_user_by_id(user.id) - assert updated_user.mobile_number == '+443456789012' + assert updated_user.mobile_number == '+44 7700 900 460' def test_should_render_verification_code_not_received(notifications_admin, diff --git a/tests/app/main/views/test_register.py b/tests/app/main/views/test_register.py index cdf021adc..c779b4c22 100644 --- a/tests/app/main/views/test_register.py +++ b/tests/app/main/views/test_register.py @@ -13,7 +13,7 @@ def test_process_register_creates_new_user(notifications_admin, notifications_ad response = notifications_admin.test_client().post('/register', data={'name': 'Some One Valid', 'email_address': 'someone@example.gov.uk', - 'mobile_number': '+441231231231', + 'mobile_number': '+4407700900460', 'password': 'validPassword!'}) assert response.status_code == 302 assert response.location == 'http://localhost/verify' @@ -31,7 +31,7 @@ def test_process_register_returns_400_when_mobile_number_is_invalid(notification 'password': 'validPassword!'}) assert response.status_code == 200 - assert 'Enter a +44 mobile number' in response.get_data(as_text=True) + assert 'Must be a UK mobile number (eg 07700 900460)' in response.get_data(as_text=True) def test_should_return_400_when_email_is_not_gov_uk(notifications_admin, @@ -55,7 +55,7 @@ def test_should_add_verify_codes_on_session(notifications_admin, notifications_a response = client.post('/register', data={'name': 'Test Codes', 'email_address': 'test_codes@example.gov.uk', - 'mobile_number': '+441234567890', + 'mobile_number': '+4407700900460', 'password': 'validPassword!'}) assert response.status_code == 302 assert 'notify_admin_session' in response.headers.get('Set-Cookie')