mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 20:58:25 -04:00
Replace uses of client.get and client.post
We have a `client_request` fixture which does a bunch of useful stuff
like:
- checking the status code of the response
- returning a `BeautifulSoup` object
Lots of our tests still use an older fixture called `client`. This is
not as good because it:
- returns a raw `Response` object
- doesn’t do the additional checks
- means our tests contain a lot of repetetive boilerplate like `page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')`
This commit converts all the tests which had a `client.get(…)` or
`client.post(…)` statement to use their equivalents on `client_request`
instead.
Subsequent commits will remove uses of `client` in other tests, but
doing it this way means the work can be broken up into more manageable
chunks.
This commit is contained in:
@@ -7,11 +7,10 @@ from tests import user_json
|
||||
from tests.conftest import SERVICE_ONE_ID
|
||||
|
||||
|
||||
def test_should_render_forgot_password(client):
|
||||
response = client.get(url_for('.forgot_password'))
|
||||
assert response.status_code == 200
|
||||
assert 'We’ll send you an email to create a new password.' \
|
||||
in response.get_data(as_text=True)
|
||||
def test_should_render_forgot_password(client_request):
|
||||
client_request.logout()
|
||||
page = client_request.get('.forgot_password')
|
||||
assert 'We’ll send you an email to create a new password.' in page.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address', [
|
||||
@@ -19,52 +18,55 @@ def test_should_render_forgot_password(client):
|
||||
'someuser@notgovernment.com'
|
||||
])
|
||||
def test_should_redirect_to_password_reset_sent_for_valid_email(
|
||||
client,
|
||||
client_request,
|
||||
fake_uuid,
|
||||
email_address,
|
||||
mocker,
|
||||
):
|
||||
client_request.logout()
|
||||
sample_user = user_json(email_address=email_address)
|
||||
mocker.patch('app.user_api_client.send_reset_password_url', return_value=None)
|
||||
response = client.post(
|
||||
url_for('.forgot_password'),
|
||||
data={'email_address': sample_user['email_address']})
|
||||
assert response.status_code == 200
|
||||
assert 'Click the link in the email to reset your password.' \
|
||||
in response.get_data(as_text=True)
|
||||
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
|
||||
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(
|
||||
client,
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mocker,
|
||||
):
|
||||
client_request.logout()
|
||||
sample_user = user_json(email_address='test@user.gov.uk')
|
||||
mocker.patch('app.user_api_client.send_reset_password_url', return_value=None)
|
||||
response = client.post(
|
||||
client_request.post_url(
|
||||
url_for('.forgot_password') + f"?next=/services/{SERVICE_ONE_ID}/templates",
|
||||
data={'email_address': sample_user['email_address']})
|
||||
assert response.status_code == 200
|
||||
_data={'email_address': sample_user['email_address']},
|
||||
_expected_status=200,
|
||||
)
|
||||
app.user_api_client.send_reset_password_url.assert_called_once_with(
|
||||
sample_user['email_address'], next_string=f'/services/{SERVICE_ONE_ID}/templates'
|
||||
)
|
||||
|
||||
|
||||
def test_should_redirect_to_password_reset_sent_for_missing_email(
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
mocker,
|
||||
):
|
||||
|
||||
client_request.logout()
|
||||
mocker.patch('app.user_api_client.send_reset_password_url', side_effect=HTTPError(Response(status=404),
|
||||
'Not found'))
|
||||
response = client.post(
|
||||
url_for('.forgot_password'),
|
||||
data={'email_address': api_user_active['email_address']})
|
||||
assert response.status_code == 200
|
||||
assert 'Click the link in the email to reset your password.' \
|
||||
in response.get_data(as_text=True)
|
||||
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
|
||||
app.user_api_client.send_reset_password_url.assert_called_once_with(
|
||||
api_user_active['email_address'], next_string=None
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user