mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-17 04:59:37 -04:00
Stop using logged_in_client fixture
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 `logged_in_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 using `logged_in_client` to:
use `client_request` instead.
This commit is contained in:
@@ -31,26 +31,26 @@ def test_load_service_before_request_handles_404(client_request, mocker):
|
||||
'/user-profile/email/confirm/MALFORMED_TOKEN',
|
||||
'/verify-email/MALFORMED_TOKEN'
|
||||
])
|
||||
def test_malformed_token_returns_page_not_found(logged_in_client, url):
|
||||
response = logged_in_client.get(url)
|
||||
def test_malformed_token_returns_page_not_found(client_request, url):
|
||||
page = client_request.get_url(url, _expected_status=404)
|
||||
|
||||
assert response.status_code == 404
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.string.strip() == 'Page not found'
|
||||
flash_banner = page.find('div', class_='banner-dangerous').string.strip()
|
||||
assert flash_banner == "There’s something wrong with the link you’ve used."
|
||||
assert page.title.string.strip() == 'Page not found – GOV.UK Notify'
|
||||
|
||||
|
||||
def test_csrf_returns_400(logged_in_client, mocker):
|
||||
def test_csrf_returns_400(client_request, mocker):
|
||||
# we turn off CSRF handling for tests, so fake a CSRF response here.
|
||||
csrf_err = CSRFError('400 Bad Request: The CSRF tokens do not match.')
|
||||
mocker.patch('app.main.views.index.render_template', side_effect=csrf_err)
|
||||
|
||||
response = logged_in_client.get('/cookies')
|
||||
page = client_request.get_url(
|
||||
'/cookies',
|
||||
_expected_status=400,
|
||||
_test_page_title=False,
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.string.strip() == 'Sorry, there’s a problem with GOV.UK Notify'
|
||||
assert page.title.string.strip() == 'Sorry, there’s a problem with the service – GOV.UK Notify'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user