Fix 500 error if revisiting registration page

If you go back to this part of the registration flow then you get a 500
error, because we’re relying on something in the session. We clear the
registration info from the session after you’ve registered successfully.

Also there were no tests for the happy path of this page either
¯\_(ツ)_/¯
This commit is contained in:
Chris Hill-Scott
2017-04-27 11:55:50 +01:00
parent 3e72e0d722
commit 1a05e33fa4
2 changed files with 18 additions and 4 deletions

View File

@@ -89,4 +89,6 @@ def _do_registration(form, service=None, send_sms=True, send_email=True):
@main.route('/registration-continue')
def registration_continue():
if not session.get('user_details'):
return redirect(url_for('.show_all_services_or_dashboard'))
return render_template('views/registration-continue.html')

View File

@@ -1,4 +1,6 @@
from datetime import datetime
from bs4 import BeautifulSoup
from unittest.mock import ANY
from flask import (
url_for,
@@ -43,11 +45,12 @@ def test_register_creates_new_user_and_redirects_to_continue_page(
'password': 'validPassword!'
}
response = client.post(url_for('main.register'), data=user_data)
assert response.status_code == 302
assert response.location == url_for('main.registration_continue', _external=True)
response = client.post(url_for('main.register'), data=user_data, follow_redirects=True)
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.select('main p')[0].text == 'An email has been sent to notfound@example.gov.uk.'
from unittest.mock import ANY
mock_send_verify_email.assert_called_with(ANY, user_data['email_address'])
mock_register_user.assert_called_with(user_data['name'],
user_data['email_address'],
@@ -55,6 +58,15 @@ def test_register_creates_new_user_and_redirects_to_continue_page(
user_data['password'])
def test_register_continue_handles_missing_session_sensibly(
client,
):
# session is not set
response = client.get(url_for('main.registration_continue'))
assert response.status_code == 302
assert response.location == url_for('main.show_all_services_or_dashboard', _external=True)
def test_process_register_returns_200_when_mobile_number_is_invalid(
client,
mock_send_verify_code,