Turn on redirects for check_and_resend_text_code

This is part of the work to make sure user is redirected
to the page they initially were meant to visit after
they sign in.
This commit is contained in:
Pea Tyczynska
2020-10-09 11:39:01 +01:00
parent d089424501
commit c3b7481e11
3 changed files with 22 additions and 7 deletions

View File

@@ -27,23 +27,32 @@ def test_should_render_email_verification_resend_show_email_address_and_resend_v
mock_send_verify_email.assert_called_with(api_user_active['id'], api_user_active['email_address'])
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
])
def test_should_render_correct_resend_template_for_active_user(
client,
api_user_active,
mock_get_user_by_email,
mock_send_verify_code,
redirect_url
):
with client.session_transaction() as session:
session['user_details'] = {
'id': api_user_active['id'],
'email': api_user_active['email_address']}
response = client.get(url_for('main.check_and_resend_text_code'))
response = client.get(url_for('main.check_and_resend_text_code', next=redirect_url))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.h1.string == 'Resend security code'
# there shouldn't be a form for updating mobile number
assert page.find('form') is None
assert page.find('a', class_="govuk-button")['href'] == url_for(
'main.check_and_resend_verification_code',
next=redirect_url
)
def test_should_render_correct_resend_template_for_pending_user(
@@ -71,6 +80,10 @@ def test_should_render_correct_resend_template_for_pending_user(
assert page.find('form').input['value'] == api_user_pending['mobile_number']
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
])
@pytest.mark.parametrize('phone_number_to_register_with', [
'+447700900460',
'+1800-555-555',
@@ -82,6 +95,7 @@ def test_should_resend_verify_code_and_update_mobile_for_pending_user(
mock_update_user_attribute,
mock_send_verify_code,
phone_number_to_register_with,
redirect_url
):
mocker.patch('app.user_api_client.get_user_by_email', return_value=api_user_pending)
@@ -89,10 +103,10 @@ def test_should_resend_verify_code_and_update_mobile_for_pending_user(
session['user_details'] = {
'id': api_user_pending['id'],
'email': api_user_pending['email_address']}
response = client.post(url_for('main.check_and_resend_text_code'),
response = client.post(url_for('main.check_and_resend_text_code', next=redirect_url),
data={'mobile_number': phone_number_to_register_with})
assert response.status_code == 302
assert response.location == url_for('main.verify', _external=True)
assert response.location == url_for('main.verify', _external=True, next=redirect_url)
mock_update_user_attribute.assert_called_once_with(
api_user_pending['id'],