mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 09:28:27 -04:00
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:
@@ -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')
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user