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:
Chris Hill-Scott
2021-12-31 12:08:14 +00:00
parent 50eae6f935
commit 0706664be4
20 changed files with 341 additions and 291 deletions

View File

@@ -2,7 +2,7 @@ from flask import url_for
def test_view_template_version(
logged_in_client,
client_request,
api_user_active,
mock_login,
mock_get_service,
@@ -20,18 +20,17 @@ def test_view_template_version(
service_id=service_id,
template_id=template_id
)
resp = logged_in_client.get(url_for(
page = client_request.get(
'.view_template_version',
service_id=service_id,
template_id=template_id,
version=version))
version=version,
)
assert resp.status_code == 200
resp_data = resp.get_data(as_text=True)
template = mock_get_template_version(service_id, template_id, version)
assert api_user_active['name'] in resp_data
assert template['data']['content'] in resp_data
assert all_versions_link in resp_data
assert api_user_active['name'] in page.text
assert template['data']['content'] in page.text
assert all_versions_link in str(page)
mock_get_template_version.assert_called_with(
service_id,
template_id,
@@ -40,7 +39,7 @@ def test_view_template_version(
def test_view_template_versions(
logged_in_client,
client_request,
api_user_active,
mock_login,
mock_get_service,
@@ -53,17 +52,15 @@ def test_view_template_versions(
):
service_id = fake_uuid
template_id = fake_uuid
resp = logged_in_client.get(url_for(
page = client_request.get(
'.view_template_versions',
service_id=service_id,
template_id=template_id
))
template_id=template_id,
)
assert resp.status_code == 200
resp_data = resp.get_data(as_text=True)
versions = mock_get_template_versions(service_id, template_id)
assert api_user_active['name'] in resp_data
assert versions['data'][0]['content'] in resp_data
assert api_user_active['name'] in page.text
assert versions['data'][0]['content'] in page.text
mock_get_template_versions.assert_called_with(
service_id,
template_id