From b775b6063313ad0db515fc8c129592ccee011f87 Mon Sep 17 00:00:00 2001 From: Adam Shimali Date: Mon, 21 Mar 2016 14:00:05 +0000 Subject: [PATCH] In registration flow then request resend of sms should redirect to verify not two-factor. --- app/main/views/code_not_received.py | 5 +++- .../views/verification-not-received.html | 2 +- .../app/main/views/test_code_not_received.py | 27 ++++++++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/main/views/code_not_received.py b/app/main/views/code_not_received.py index 36fcfc8dc..c7c94b457 100644 --- a/app/main/views/code_not_received.py +++ b/app/main/views/code_not_received.py @@ -41,4 +41,7 @@ def check_and_resend_verification_code(): # TODO there needs to be a way to generate a new session id user = user_api_client.get_user_by_email(session['user_details']['email']) user_api_client.send_verify_code(user.id, 'sms', user.mobile_number) - return redirect(url_for('main.two_factor')) + if user.state == 'pending': + return redirect(url_for('main.verify')) + else: + return redirect(url_for('main.two_factor')) diff --git a/app/templates/views/verification-not-received.html b/app/templates/views/verification-not-received.html index 412f62625..da577cceb 100644 --- a/app/templates/views/verification-not-received.html +++ b/app/templates/views/verification-not-received.html @@ -16,7 +16,7 @@

- Resend verification code + Resend verification code

diff --git a/tests/app/main/views/test_code_not_received.py b/tests/app/main/views/test_code_not_received.py index 92be74682..87fbc9dce 100644 --- a/tests/app/main/views/test_code_not_received.py +++ b/tests/app/main/views/test_code_not_received.py @@ -97,10 +97,10 @@ def test_should_render_verification_code_not_received(app_, 'speak to your service manager to reset the number.' in response.get_data(as_text=True) -def test_check_and_redirect_to_two_factor(app_, - api_user_active, - mock_get_user_by_email, - mock_send_verify_code): +def test_check_and_redirect_to_two_factor_if_user_active(app_, + api_user_active, + mock_get_user_by_email, + mock_send_verify_code): with app_.test_request_context(): with app_.test_client() as client: with client.session_transaction() as session: @@ -112,6 +112,25 @@ def test_check_and_redirect_to_two_factor(app_, assert response.location == url_for('main.two_factor', _external=True) +def test_check_and_redirect_to_verify_if_user_pending(app_, + mocker, + api_user_pending, + mock_get_user_pending, + mock_send_verify_code): + + mocker.patch('app.user_api_client.get_user_by_email', return_value=api_user_pending) + + with app_.test_request_context(): + with app_.test_client() as client: + with client.session_transaction() as session: + session['user_details'] = { + 'id': api_user_pending.id, + 'email': api_user_pending.email_address} + response = client.get(url_for('main.check_and_resend_verification_code')) + assert response.status_code == 302 + assert response.location == url_for('main.verify', _external=True) + + def test_should_create_new_code_for_user(app_, api_user_active, mock_get_user_by_email,