mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 17:38:50 -04:00
Stop calling mock_get_notications as if it's a function
By creating a new function in conftest.py, `create_notifications`, which can be used instead.
This commit is contained in:
@@ -14,7 +14,7 @@ from tests.conftest import (
|
||||
create_active_caseworking_user,
|
||||
create_active_user_view_permissions,
|
||||
create_active_user_with_permissions,
|
||||
mock_get_notifications,
|
||||
create_notifications,
|
||||
normalize_spaces,
|
||||
)
|
||||
|
||||
@@ -265,19 +265,15 @@ def test_download_not_available_to_users_without_dashboard(
|
||||
|
||||
def test_letters_with_status_virus_scan_failed_shows_a_failure_description(
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
client_request,
|
||||
service_one,
|
||||
mock_get_service_statistics,
|
||||
mock_get_service_data_retention,
|
||||
mock_get_api_keys,
|
||||
):
|
||||
mock_get_notifications(
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
is_precompiled_letter=True,
|
||||
noti_status='virus-scan-failed'
|
||||
)
|
||||
notifications = create_notifications(template_type='letter', status='virus-scan-failed', is_precompiled_letter=True)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_notifications',
|
||||
service_id=service_one['id'],
|
||||
@@ -294,7 +290,6 @@ def test_letters_with_status_virus_scan_failed_shows_a_failure_description(
|
||||
])
|
||||
def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states(
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
client_request,
|
||||
service_one,
|
||||
mock_get_service_statistics,
|
||||
@@ -302,12 +297,9 @@ def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states(
|
||||
mock_get_no_api_keys,
|
||||
letter_status,
|
||||
):
|
||||
mock_get_notifications(
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
is_precompiled_letter=True,
|
||||
noti_status=letter_status
|
||||
)
|
||||
notifications = create_notifications(template_type='letter', status=letter_status)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_notifications',
|
||||
service_id=service_one['id'],
|
||||
@@ -571,16 +563,14 @@ def test_html_contains_notification_id(
|
||||
|
||||
def test_html_contains_links_for_failed_notifications(
|
||||
client_request,
|
||||
active_user_with_permissions,
|
||||
mock_get_service_statistics,
|
||||
mock_get_service_data_retention,
|
||||
mock_get_no_api_keys,
|
||||
mocker,
|
||||
):
|
||||
mock_get_notifications(mocker,
|
||||
active_user_with_permissions,
|
||||
diff_template_type="sms",
|
||||
noti_status='technical-failure')
|
||||
notifications = create_notifications(status='technical-failure')
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
response = client_request.get(
|
||||
'main.view_notifications',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
@@ -596,18 +586,18 @@ def test_html_contains_links_for_failed_notifications(
|
||||
def test_redacts_templates_that_should_be_redacted(
|
||||
client_request,
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
mock_get_service_statistics,
|
||||
mock_get_service_data_retention,
|
||||
mock_get_no_api_keys,
|
||||
):
|
||||
mock_get_notifications(
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
template_content="hello ((name))",
|
||||
notifications = create_notifications(
|
||||
status='technical-failure',
|
||||
content='hello ((name))',
|
||||
personalisation={'name': 'Jo'},
|
||||
redact_personalisation=True,
|
||||
)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_notifications',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
@@ -680,7 +670,6 @@ def test_big_numbers_and_search_dont_show_for_letters(
|
||||
def test_sending_status_hint_displays_correctly_on_notifications_page(
|
||||
client_request,
|
||||
service_one,
|
||||
active_user_with_permissions,
|
||||
mock_get_service_statistics,
|
||||
mock_get_service_data_retention,
|
||||
mock_get_no_api_keys,
|
||||
@@ -690,7 +679,8 @@ def test_sending_status_hint_displays_correctly_on_notifications_page(
|
||||
single_line,
|
||||
mocker
|
||||
):
|
||||
mock_get_notifications(mocker, True, diff_template_type=message_type, noti_status=status)
|
||||
notifications = create_notifications(template_type=message_type, status=status)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_notifications',
|
||||
@@ -709,17 +699,19 @@ def test_sending_status_hint_displays_correctly_on_notifications_page(
|
||||
def test_should_expected_hint_for_letters(
|
||||
client_request,
|
||||
service_one,
|
||||
active_user_with_permissions,
|
||||
mock_get_service_statistics,
|
||||
mock_get_service_data_retention,
|
||||
mock_get_no_api_keys,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
is_precompiled_letter,
|
||||
expected_hint
|
||||
):
|
||||
mock_get_notifications(
|
||||
mocker, active_user_with_permissions, is_precompiled_letter=is_precompiled_letter)
|
||||
notifications = create_notifications(
|
||||
template_type='letter',
|
||||
subject=expected_hint,
|
||||
is_precompiled_letter=is_precompiled_letter,
|
||||
)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_notifications',
|
||||
|
||||
@@ -8,7 +8,7 @@ from flask import url_for
|
||||
from tests import sample_uuid, validate_route_permission
|
||||
from tests.conftest import (
|
||||
SERVICE_ONE_ID,
|
||||
mock_get_notifications,
|
||||
create_notifications,
|
||||
normalize_spaces,
|
||||
)
|
||||
|
||||
@@ -73,13 +73,13 @@ def test_should_show_api_page_with_no_notifications(
|
||||
])
|
||||
def test_letter_notifications_should_have_link_to_view_letter(
|
||||
client_request,
|
||||
api_user_active,
|
||||
mock_has_permissions,
|
||||
mocker,
|
||||
template_type,
|
||||
link_text,
|
||||
):
|
||||
mock_get_notifications(mocker, api_user_active, diff_template_type=template_type)
|
||||
notifications = create_notifications(template_type=template_type)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
page = client_request.get(
|
||||
'main.api_integration',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
@@ -93,13 +93,13 @@ def test_letter_notifications_should_have_link_to_view_letter(
|
||||
])
|
||||
def test_should_not_have_link_to_view_letter_for_precompiled_letters_in_virus_states(
|
||||
client_request,
|
||||
api_user_active,
|
||||
fake_uuid,
|
||||
mock_has_permissions,
|
||||
mocker,
|
||||
status
|
||||
):
|
||||
mock_get_notifications(mocker, api_user_active, noti_status=status)
|
||||
notifications = create_notifications(status=status)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.api_integration',
|
||||
@@ -115,14 +115,14 @@ def test_should_not_have_link_to_view_letter_for_precompiled_letters_in_virus_st
|
||||
])
|
||||
def test_letter_notifications_should_show_client_reference(
|
||||
client_request,
|
||||
api_user_active,
|
||||
fake_uuid,
|
||||
mock_has_permissions,
|
||||
mocker,
|
||||
client_reference,
|
||||
shows_ref
|
||||
):
|
||||
mock_get_notifications(mocker, api_user_active, client_reference=client_reference)
|
||||
notifications = create_notifications(client_reference=client_reference)
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.api_integration',
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.main.views.conversation import get_user_number
|
||||
from tests.conftest import (
|
||||
SERVICE_ONE_ID,
|
||||
_template,
|
||||
mock_get_notifications,
|
||||
create_notifications,
|
||||
normalize_spaces,
|
||||
)
|
||||
|
||||
@@ -76,7 +76,6 @@ def test_get_user_phone_number_raises_if_both_api_requests_fail(mocker):
|
||||
def test_view_conversation(
|
||||
client_request,
|
||||
mocker,
|
||||
api_user_active,
|
||||
mock_get_inbound_sms_by_id_with_no_messages,
|
||||
mock_get_notification,
|
||||
fake_uuid,
|
||||
@@ -84,14 +83,12 @@ def test_view_conversation(
|
||||
expected_outbound_content,
|
||||
mock_get_inbound_sms
|
||||
):
|
||||
|
||||
mock = mock_get_notifications(
|
||||
mocker,
|
||||
api_user_active,
|
||||
template_content='Hello ((name))',
|
||||
notifications = create_notifications(
|
||||
content='Hello ((name))',
|
||||
personalisation={'name': 'Jo'},
|
||||
redact_personalisation=outbound_redacted,
|
||||
)
|
||||
mock = mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.conversation',
|
||||
|
||||
@@ -11,7 +11,7 @@ from tests.conftest import (
|
||||
SERVICE_ONE_ID,
|
||||
create_active_caseworking_user,
|
||||
create_active_user_with_permissions,
|
||||
mock_get_notifications,
|
||||
create_notifications,
|
||||
mock_get_service_letter_template,
|
||||
normalize_spaces,
|
||||
)
|
||||
@@ -360,11 +360,13 @@ def test_should_show_letter_job(
|
||||
mock_get_job,
|
||||
mock_get_service_data_retention,
|
||||
fake_uuid,
|
||||
active_user_with_permissions,
|
||||
mocker,
|
||||
):
|
||||
|
||||
get_notifications = mock_get_notifications(mocker, active_user_with_permissions, diff_template_type='letter')
|
||||
notifications = create_notifications(template_type='letter', subject='template subject')
|
||||
get_notifications = mocker.patch(
|
||||
'app.notification_api_client.get_notifications_for_service',
|
||||
return_value=notifications,
|
||||
)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_job',
|
||||
@@ -742,15 +744,10 @@ def test_should_show_letter_job_with_first_class_if_notifications_are_first_clas
|
||||
mock_get_job,
|
||||
mock_get_service_data_retention,
|
||||
fake_uuid,
|
||||
active_user_with_permissions,
|
||||
mocker,
|
||||
):
|
||||
mock_get_notifications(
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
diff_template_type='letter',
|
||||
postage='first'
|
||||
)
|
||||
notifications = create_notifications(template_type='letter', postage='first')
|
||||
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||
|
||||
page = client_request.get(
|
||||
'main.view_job',
|
||||
|
||||
@@ -3930,3 +3930,39 @@ def create_notification(
|
||||
if key_type:
|
||||
noti['key_type'] = key_type
|
||||
return noti
|
||||
|
||||
|
||||
def create_notifications(
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_type='sms',
|
||||
rows=5,
|
||||
status=None,
|
||||
subject='subject',
|
||||
content='content',
|
||||
client_reference=None,
|
||||
personalisation=None,
|
||||
redact_personalisation=False,
|
||||
is_precompiled_letter=False,
|
||||
postage=None,
|
||||
):
|
||||
template = template_json(
|
||||
service_id,
|
||||
id_=str(generate_uuid()),
|
||||
type_=template_type,
|
||||
subject=subject,
|
||||
content=content,
|
||||
redact_personalisation=redact_personalisation,
|
||||
is_precompiled_letter=is_precompiled_letter
|
||||
)
|
||||
|
||||
return notification_json(
|
||||
service_id,
|
||||
template=template,
|
||||
rows=rows,
|
||||
personalisation=personalisation,
|
||||
template_type=template_type,
|
||||
client_reference=client_reference,
|
||||
status=status,
|
||||
created_by_name='Firstname Lastname',
|
||||
postage=postage
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user