From 0bf39c75d9748aace1838a0af2756363967e2413 Mon Sep 17 00:00:00 2001 From: Martyn Inglis Date: Wed, 28 Sep 2016 09:34:16 +0100 Subject: [PATCH] Fixed bug where there was an error when try and change email. - it tried to send a verify code which no longer is applicable - one stage of process removed and tests update properly Flow is: - Change email - Confirm with password - Done --- app/main/views/user_profile.py | 33 ++------------- tests/app/main/views/test_user_profile.py | 51 ++++------------------- 2 files changed, 11 insertions(+), 73 deletions(-) diff --git a/app/main/views/user_profile.py b/app/main/views/user_profile.py index 298711957..796e9cb65 100644 --- a/app/main/views/user_profile.py +++ b/app/main/views/user_profile.py @@ -82,9 +82,10 @@ def user_profile_email_authenticate(): return redirect('main.user_profile_email') if form.validate_on_submit(): - session[NEW_EMAIL_PASSWORD_CONFIRMED] = True - user_api_client.send_verify_code(current_user.id, 'email', session[NEW_EMAIL]) - return redirect(url_for('.user_profile_email_confirm')) + current_user.email_address = session[NEW_EMAIL] + del session[NEW_EMAIL] + user_api_client.update_user(current_user) + return redirect(url_for('.user_profile')) return render_template( 'views/user-profile/authenticate.html', @@ -94,32 +95,6 @@ def user_profile_email_authenticate(): ) -@main.route("/user-profile/email/confirm", methods=['GET', 'POST']) -@login_required -def user_profile_email_confirm(): - - # Validate verify code for form - def _check_code(cde): - return user_api_client.check_verify_code(current_user.id, cde, 'email') - form = ConfirmEmailForm(_check_code) - - if NEW_EMAIL_PASSWORD_CONFIRMED not in session: - return redirect('main.user_profile_email_authenticate') - - if form.validate_on_submit(): - current_user.email_address = session[NEW_EMAIL] - del session[NEW_EMAIL] - del session[NEW_EMAIL_PASSWORD_CONFIRMED] - user_api_client.update_user(current_user) - return redirect(url_for('.user_profile')) - - return render_template( - 'views/user-profile/confirm.html', - form_field=form.email_code, - thing='email address' - ) - - @main.route("/user-profile/mobile-number", methods=['GET', 'POST']) @login_required def user_profile_mobile_number(): diff --git a/tests/app/main/views/test_user_profile.py b/tests/app/main/views/test_user_profile.py index 3905fe511..d077b124d 100644 --- a/tests/app/main/views/test_user_profile.py +++ b/tests/app/main/views/test_user_profile.py @@ -98,13 +98,13 @@ def test_should_show_authenticate_after_email_change(app_, assert response.status_code == 200 -def test_should_redirect_after_email_change_confirm(app_, - api_user_active, - mock_login, - mock_get_user, - mock_verify_password, - mock_send_verify_code, - mock_is_email_unique): +def test_should_redirect_to_profile_after_email_change_confirm(app_, + api_user_active, + mock_login, + mock_get_user, + mock_verify_password, + mock_send_verify_code, + mock_is_email_unique): with app_.test_request_context(): with app_.test_client() as client: client.login(api_user_active) @@ -115,43 +115,6 @@ def test_should_redirect_after_email_change_confirm(app_, url_for('main.user_profile_email_authenticate'), data=data) - assert response.status_code == 302 - assert response.location == url_for( - 'main.user_profile_email_confirm', _external=True) - - -def test_should_show_confirm_after_email_change(app_, - api_user_active, - mock_login, - mock_get_user): - with app_.test_request_context(): - with app_.test_client() as client: - client.login(api_user_active) - with client.session_transaction() as session: - session['new-email-password-confirmed'] = True - response = client.get(url_for('main.user_profile_email_confirm')) - - assert 'Change your email address' in response.get_data(as_text=True) - assert 'Confirm' in response.get_data(as_text=True) - assert response.status_code == 200 - - -def test_should_redirect_after_email_change_confirm(app_, - api_user_active, - mock_login, - mock_get_user, - mock_check_verify_code): - with app_.test_request_context(): - with app_.test_client() as client: - client.login(api_user_active) - with client.session_transaction() as session: - session['new-email-password-confirmed'] = True - session['new-email'] = 'new_notify@notify.gov.uk' - data = {'email_code': '12345'} - response = client.post( - url_for('main.user_profile_email_confirm'), - data=data) - assert response.status_code == 302 assert response.location == url_for( 'main.user_profile', _external=True)