2016-03-16 14:19:41 +00:00
|
|
|
|
from flask import url_for, Response
|
|
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2016-01-04 14:00:39 +00:00
|
|
|
|
|
2016-03-09 09:29:35 +00:00
|
|
|
|
import app
|
|
|
|
|
|
|
2016-01-04 14:00:39 +00:00
|
|
|
|
|
2016-01-27 12:22:32 +00:00
|
|
|
|
def test_should_render_forgot_password(app_):
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
response = app_.test_client().get(url_for('.forgot_password'))
|
2016-01-11 15:17:00 +00:00
|
|
|
|
assert response.status_code == 200
|
2016-05-10 11:36:49 +01:00
|
|
|
|
assert 'We’ll send you an email to create a new password.' \
|
2016-01-11 15:17:00 +00:00
|
|
|
|
in response.get_data(as_text=True)
|
2016-01-04 14:00:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-03-07 18:18:52 +00:00
|
|
|
|
def test_should_redirect_to_password_reset_sent_for_valid_email(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
2016-03-09 09:29:35 +00:00
|
|
|
|
mocker):
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
2016-03-09 09:29:35 +00:00
|
|
|
|
mocker.patch('app.user_api_client.send_reset_password_url', return_value=None)
|
2016-01-15 15:15:35 +00:00
|
|
|
|
response = app_.test_client().post(
|
|
|
|
|
|
url_for('.forgot_password'),
|
2016-01-27 12:22:32 +00:00
|
|
|
|
data={'email_address': api_user_active.email_address})
|
2016-01-11 15:17:00 +00:00
|
|
|
|
assert response.status_code == 200
|
2016-09-06 17:11:44 +01:00
|
|
|
|
assert 'Click the link in the email to reset your password.' \
|
2016-05-10 11:36:49 +01:00
|
|
|
|
in response.get_data(as_text=True)
|
2016-03-09 09:29:35 +00:00
|
|
|
|
app.user_api_client.send_reset_password_url.assert_called_once_with(api_user_active.email_address)
|
2016-03-16 14:19:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_redirect_to_password_reset_sent_for_missing_email(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mocker):
|
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
|
|
|
|
|
|
mocker.patch('app.user_api_client.send_reset_password_url', side_effect=HTTPError(Response(status=404),
|
|
|
|
|
|
'Not found'))
|
|
|
|
|
|
response = app_.test_client().post(
|
|
|
|
|
|
url_for('.forgot_password'),
|
|
|
|
|
|
data={'email_address': api_user_active.email_address})
|
|
|
|
|
|
assert response.status_code == 200
|
2016-09-06 17:11:44 +01:00
|
|
|
|
assert 'Click the link in the email to reset your password.' \
|
2016-05-10 11:36:49 +01:00
|
|
|
|
in response.get_data(as_text=True)
|
2016-03-16 14:19:41 +00:00
|
|
|
|
app.user_api_client.send_reset_password_url.assert_called_once_with(api_user_active.email_address)
|