Files
notifications-admin/tests/app/main/views/test_forgot_password.py
T

73 lines
2.5 KiB
Python
Raw Normal View History

import pytest
2018-02-20 11:22:17 +00:00
from flask import Response, url_for
from notifications_python_client.errors import HTTPError
2016-01-04 14:00:39 +00:00
import app
from tests import user_json
2020-10-12 12:01:39 +01:00
from tests.conftest import SERVICE_ONE_ID
2016-01-04 14:00:39 +00:00
2022-01-04 15:40:42 +00:00
def test_should_render_forgot_password(client_request):
client_request.logout()
page = client_request.get('.forgot_password')
assert 'Well send you an email to create a new password.' in page.text
2016-01-04 14:00:39 +00:00
@pytest.mark.parametrize('email_address', [
'test@user.gov.uk',
'someuser@notgovernment.com'
])
2016-03-07 18:18:52 +00:00
def test_should_redirect_to_password_reset_sent_for_valid_email(
2022-01-04 15:40:42 +00:00
client_request,
2017-02-03 10:42:01 +00:00
fake_uuid,
email_address,
mocker,
):
2022-01-04 15:40:42 +00:00
client_request.logout()
sample_user = user_json(email_address=email_address)
2017-02-03 12:07:21 +00:00
mocker.patch('app.user_api_client.send_reset_password_url', return_value=None)
2022-01-04 15:40:42 +00:00
page = client_request.post(
'.forgot_password',
_data={'email_address': sample_user['email_address']},
_expected_status=200,
)
assert 'Click the link in the email to reset your password.' in page.text
2020-10-05 15:51:44 +01:00
app.user_api_client.send_reset_password_url.assert_called_once_with(sample_user['email_address'], next_string=None)
def test_forgot_password_sends_next_link_with_reset_password_email_request(
2022-01-04 15:40:42 +00:00
client_request,
2020-10-05 15:51:44 +01:00
fake_uuid,
mocker,
):
2022-01-04 15:40:42 +00:00
client_request.logout()
2020-10-05 15:51:44 +01:00
sample_user = user_json(email_address='test@user.gov.uk')
mocker.patch('app.user_api_client.send_reset_password_url', return_value=None)
2022-01-04 15:40:42 +00:00
client_request.post_url(
2020-10-12 12:01:39 +01:00
url_for('.forgot_password') + f"?next=/services/{SERVICE_ONE_ID}/templates",
2022-01-04 15:40:42 +00:00
_data={'email_address': sample_user['email_address']},
_expected_status=200,
)
2020-10-05 15:51:44 +01:00
app.user_api_client.send_reset_password_url.assert_called_once_with(
2020-10-12 12:01:39 +01:00
sample_user['email_address'], next_string=f'/services/{SERVICE_ONE_ID}/templates'
2020-10-05 15:51:44 +01:00
)
def test_should_redirect_to_password_reset_sent_for_missing_email(
2022-01-04 15:40:42 +00:00
client_request,
2017-02-03 10:42:01 +00:00
api_user_active,
mocker,
):
2022-01-04 15:40:42 +00:00
client_request.logout()
2017-02-03 12:07:21 +00:00
mocker.patch('app.user_api_client.send_reset_password_url', side_effect=HTTPError(Response(status=404),
'Not found'))
2022-01-04 15:40:42 +00:00
page = client_request.post(
'.forgot_password',
_data={'email_address': api_user_active['email_address']},
_expected_status=200,
)
assert 'Click the link in the email to reset your password.' in page.text
2020-10-05 15:51:44 +01:00
app.user_api_client.send_reset_password_url.assert_called_once_with(
api_user_active['email_address'], next_string=None
)