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

77 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
2016-01-04 14:00:39 +00:00
import app
2025-06-10 11:40:14 -07:00
from notifications_python_client.errors import HTTPError
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.gsa.gov", "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)
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"]},
2022-01-04 15:40:42 +00:00
_expected_status=200,
)
assert "Click the link in the email to reset your password." in page.text
app.user_api_client.send_reset_password_url.assert_called_once_with(
sample_user["email_address"], next_string=None
)
2020-10-05 15:51:44 +01:00
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()
sample_user = user_json(email_address="test@user.gsa.gov")
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(
url_for(".forgot_password") + f"?next=/services/{SERVICE_ONE_ID}/templates",
_data={"email_address": sample_user["email_address"]},
2022-01-04 15:40:42 +00:00
_expected_status=200,
)
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=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()
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"]},
2022-01-04 15:40:42 +00:00
_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
2020-10-05 15:51:44 +01:00
)