Files
notifications-admin/tests/app/main/views/test_template_history.py
Chris Hill-Scott 0706664be4 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.
2022-01-10 14:39:44 +00:00

68 lines
1.7 KiB
Python

from flask import url_for
def test_view_template_version(
client_request,
api_user_active,
mock_login,
mock_get_service,
mock_get_template_version,
mock_get_user,
mock_get_user_by_email,
mock_has_permissions,
fake_uuid,
):
service_id = fake_uuid
template_id = fake_uuid
version = 1
all_versions_link = url_for(
'main.view_template_versions',
service_id=service_id,
template_id=template_id
)
page = client_request.get(
'.view_template_version',
service_id=service_id,
template_id=template_id,
version=version,
)
template = mock_get_template_version(service_id, template_id, version)
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,
version
)
def test_view_template_versions(
client_request,
api_user_active,
mock_login,
mock_get_service,
mock_get_template_versions,
mock_get_service_template,
mock_get_user,
mock_get_user_by_email,
mock_has_permissions,
fake_uuid,
):
service_id = fake_uuid
template_id = fake_uuid
page = client_request.get(
'.view_template_versions',
service_id=service_id,
template_id=template_id,
)
versions = mock_get_template_versions(service_id, template_id)
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
)