Reduce the errors related to user fixtures

We were using user fixtures in a lot of parameterized tests, but this is
no longer allowed in Pytest 5. To avoid having to split up the parametrized
tests (which would make the test files a lot longer and slightly more
difficult to read) this commit creates functions which return various types
of user json so that we can use these as the test parameters instead.
This commit is contained in:
Katie Smith
2019-12-19 16:59:07 +00:00
parent b62018a8e4
commit e4134072d9
17 changed files with 412 additions and 231 deletions

View File

@@ -9,6 +9,7 @@ from notifications_python_client.errors import HTTPError
from app.main.views.templates import get_human_readable_delta
from tests import (
sample_uuid,
single_notification_json,
template_json,
validate_route_permission,
@@ -25,9 +26,8 @@ from tests.conftest import (
SERVICE_TWO_ID,
TEMPLATE_ONE_ID,
ElementNotFound,
active_caseworking_user,
active_user_view_permissions,
fake_uuid,
create_active_caseworking_user,
create_active_user_view_permissions,
mock_get_service_email_template,
mock_get_service_letter_template,
mock_get_service_template,
@@ -90,7 +90,7 @@ def test_should_show_add_template_form_if_service_has_folder_permission(
'user, expected_page_title, extra_args, expected_nav_links, expected_templates',
[
(
active_user_view_permissions,
create_active_user_view_permissions(),
'Templates',
{},
['Email', 'Text message', 'Letter'],
@@ -104,28 +104,28 @@ def test_should_show_add_template_form_if_service_has_folder_permission(
]
),
(
active_user_view_permissions,
create_active_user_view_permissions(),
'Templates',
{'template_type': 'sms'},
['All', 'Email', 'Letter'],
['sms_template_one', 'sms_template_two'],
),
(
active_user_view_permissions,
create_active_user_view_permissions(),
'Templates',
{'template_type': 'email'},
['All', 'Text message', 'Letter'],
['email_template_one', 'email_template_two'],
),
(
active_user_view_permissions,
create_active_user_view_permissions(),
'Templates',
{'template_type': 'letter'},
['All', 'Email', 'Text message'],
['letter_template_one', 'letter_template_two'],
),
(
active_caseworking_user,
create_active_caseworking_user(),
'Templates',
{},
['Email', 'Text message', 'Letter'],
@@ -139,7 +139,7 @@ def test_should_show_add_template_form_if_service_has_folder_permission(
],
),
(
active_caseworking_user,
create_active_caseworking_user(),
'Templates',
{'template_type': 'email'},
['All', 'Text message', 'Letter'],
@@ -157,12 +157,11 @@ def test_should_show_page_for_choosing_a_template(
expected_templates,
service_one,
mocker,
fake_uuid,
user,
expected_page_title,
):
service_one['permissions'].append('letter')
client_request.login(user(fake_uuid))
client_request.login(user)
page = client_request.get(
'main.choose_template',
@@ -358,9 +357,10 @@ def test_caseworker_redirected_to_one_off(
mock_get_service_template,
mocker,
fake_uuid,
active_caseworking_user,
):
mocker.patch('app.user_api_client.get_user', return_value=active_caseworking_user(fake_uuid))
mocker.patch('app.user_api_client.get_user', return_value=active_caseworking_user)
client_request.get(
'main.view_template',
@@ -717,10 +717,10 @@ def test_should_show_sms_template_with_downgraded_unicode_characters(
@pytest.mark.parametrize('mock_contact_block, expected_partial_url', (
(no_letter_contact_blocks, partial(
url_for, 'main.service_add_letter_contact', from_template=fake_uuid(),
url_for, 'main.service_add_letter_contact', from_template=sample_uuid(),
)),
(single_letter_contact_block, partial(
url_for, 'main.set_template_sender', template_id=fake_uuid(),
url_for, 'main.set_template_sender', template_id=sample_uuid(),
)),
))
def test_should_let_letter_contact_block_be_changed_for_the_template(