mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 08:16:51 -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_caseworking_user,
|
||||||
create_active_user_view_permissions,
|
create_active_user_view_permissions,
|
||||||
create_active_user_with_permissions,
|
create_active_user_with_permissions,
|
||||||
mock_get_notifications,
|
create_notifications,
|
||||||
normalize_spaces,
|
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(
|
def test_letters_with_status_virus_scan_failed_shows_a_failure_description(
|
||||||
mocker,
|
mocker,
|
||||||
active_user_with_permissions,
|
|
||||||
client_request,
|
client_request,
|
||||||
service_one,
|
service_one,
|
||||||
mock_get_service_statistics,
|
mock_get_service_statistics,
|
||||||
mock_get_service_data_retention,
|
mock_get_service_data_retention,
|
||||||
mock_get_api_keys,
|
mock_get_api_keys,
|
||||||
):
|
):
|
||||||
mock_get_notifications(
|
notifications = create_notifications(template_type='letter', status='virus-scan-failed', is_precompiled_letter=True)
|
||||||
mocker,
|
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||||
active_user_with_permissions,
|
|
||||||
is_precompiled_letter=True,
|
|
||||||
noti_status='virus-scan-failed'
|
|
||||||
)
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
'main.view_notifications',
|
'main.view_notifications',
|
||||||
service_id=service_one['id'],
|
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(
|
def test_should_not_show_preview_link_for_precompiled_letters_in_virus_states(
|
||||||
mocker,
|
mocker,
|
||||||
active_user_with_permissions,
|
|
||||||
client_request,
|
client_request,
|
||||||
service_one,
|
service_one,
|
||||||
mock_get_service_statistics,
|
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,
|
mock_get_no_api_keys,
|
||||||
letter_status,
|
letter_status,
|
||||||
):
|
):
|
||||||
mock_get_notifications(
|
notifications = create_notifications(template_type='letter', status=letter_status)
|
||||||
mocker,
|
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||||
active_user_with_permissions,
|
|
||||||
is_precompiled_letter=True,
|
|
||||||
noti_status=letter_status
|
|
||||||
)
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
'main.view_notifications',
|
'main.view_notifications',
|
||||||
service_id=service_one['id'],
|
service_id=service_one['id'],
|
||||||
@@ -571,16 +563,14 @@ def test_html_contains_notification_id(
|
|||||||
|
|
||||||
def test_html_contains_links_for_failed_notifications(
|
def test_html_contains_links_for_failed_notifications(
|
||||||
client_request,
|
client_request,
|
||||||
active_user_with_permissions,
|
|
||||||
mock_get_service_statistics,
|
mock_get_service_statistics,
|
||||||
mock_get_service_data_retention,
|
mock_get_service_data_retention,
|
||||||
mock_get_no_api_keys,
|
mock_get_no_api_keys,
|
||||||
mocker,
|
mocker,
|
||||||
):
|
):
|
||||||
mock_get_notifications(mocker,
|
notifications = create_notifications(status='technical-failure')
|
||||||
active_user_with_permissions,
|
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||||
diff_template_type="sms",
|
|
||||||
noti_status='technical-failure')
|
|
||||||
response = client_request.get(
|
response = client_request.get(
|
||||||
'main.view_notifications',
|
'main.view_notifications',
|
||||||
service_id=SERVICE_ONE_ID,
|
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(
|
def test_redacts_templates_that_should_be_redacted(
|
||||||
client_request,
|
client_request,
|
||||||
mocker,
|
mocker,
|
||||||
active_user_with_permissions,
|
|
||||||
mock_get_service_statistics,
|
mock_get_service_statistics,
|
||||||
mock_get_service_data_retention,
|
mock_get_service_data_retention,
|
||||||
mock_get_no_api_keys,
|
mock_get_no_api_keys,
|
||||||
):
|
):
|
||||||
mock_get_notifications(
|
notifications = create_notifications(
|
||||||
mocker,
|
status='technical-failure',
|
||||||
active_user_with_permissions,
|
content='hello ((name))',
|
||||||
template_content="hello ((name))",
|
|
||||||
personalisation={'name': 'Jo'},
|
personalisation={'name': 'Jo'},
|
||||||
redact_personalisation=True,
|
redact_personalisation=True,
|
||||||
)
|
)
|
||||||
|
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||||
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
'main.view_notifications',
|
'main.view_notifications',
|
||||||
service_id=SERVICE_ONE_ID,
|
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(
|
def test_sending_status_hint_displays_correctly_on_notifications_page(
|
||||||
client_request,
|
client_request,
|
||||||
service_one,
|
service_one,
|
||||||
active_user_with_permissions,
|
|
||||||
mock_get_service_statistics,
|
mock_get_service_statistics,
|
||||||
mock_get_service_data_retention,
|
mock_get_service_data_retention,
|
||||||
mock_get_no_api_keys,
|
mock_get_no_api_keys,
|
||||||
@@ -690,7 +679,8 @@ def test_sending_status_hint_displays_correctly_on_notifications_page(
|
|||||||
single_line,
|
single_line,
|
||||||
mocker
|
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(
|
page = client_request.get(
|
||||||
'main.view_notifications',
|
'main.view_notifications',
|
||||||
@@ -709,17 +699,19 @@ def test_sending_status_hint_displays_correctly_on_notifications_page(
|
|||||||
def test_should_expected_hint_for_letters(
|
def test_should_expected_hint_for_letters(
|
||||||
client_request,
|
client_request,
|
||||||
service_one,
|
service_one,
|
||||||
active_user_with_permissions,
|
|
||||||
mock_get_service_statistics,
|
mock_get_service_statistics,
|
||||||
mock_get_service_data_retention,
|
mock_get_service_data_retention,
|
||||||
mock_get_no_api_keys,
|
mock_get_no_api_keys,
|
||||||
mocker,
|
mocker,
|
||||||
fake_uuid,
|
|
||||||
is_precompiled_letter,
|
is_precompiled_letter,
|
||||||
expected_hint
|
expected_hint
|
||||||
):
|
):
|
||||||
mock_get_notifications(
|
notifications = create_notifications(
|
||||||
mocker, active_user_with_permissions, is_precompiled_letter=is_precompiled_letter)
|
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(
|
page = client_request.get(
|
||||||
'main.view_notifications',
|
'main.view_notifications',
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from flask import url_for
|
|||||||
from tests import sample_uuid, validate_route_permission
|
from tests import sample_uuid, validate_route_permission
|
||||||
from tests.conftest import (
|
from tests.conftest import (
|
||||||
SERVICE_ONE_ID,
|
SERVICE_ONE_ID,
|
||||||
mock_get_notifications,
|
create_notifications,
|
||||||
normalize_spaces,
|
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(
|
def test_letter_notifications_should_have_link_to_view_letter(
|
||||||
client_request,
|
client_request,
|
||||||
api_user_active,
|
|
||||||
mock_has_permissions,
|
mock_has_permissions,
|
||||||
mocker,
|
mocker,
|
||||||
template_type,
|
template_type,
|
||||||
link_text,
|
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(
|
page = client_request.get(
|
||||||
'main.api_integration',
|
'main.api_integration',
|
||||||
service_id=SERVICE_ONE_ID,
|
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(
|
def test_should_not_have_link_to_view_letter_for_precompiled_letters_in_virus_states(
|
||||||
client_request,
|
client_request,
|
||||||
api_user_active,
|
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
mock_has_permissions,
|
mock_has_permissions,
|
||||||
mocker,
|
mocker,
|
||||||
status
|
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(
|
page = client_request.get(
|
||||||
'main.api_integration',
|
'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(
|
def test_letter_notifications_should_show_client_reference(
|
||||||
client_request,
|
client_request,
|
||||||
api_user_active,
|
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
mock_has_permissions,
|
mock_has_permissions,
|
||||||
mocker,
|
mocker,
|
||||||
client_reference,
|
client_reference,
|
||||||
shows_ref
|
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(
|
page = client_request.get(
|
||||||
'main.api_integration',
|
'main.api_integration',
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from app.main.views.conversation import get_user_number
|
|||||||
from tests.conftest import (
|
from tests.conftest import (
|
||||||
SERVICE_ONE_ID,
|
SERVICE_ONE_ID,
|
||||||
_template,
|
_template,
|
||||||
mock_get_notifications,
|
create_notifications,
|
||||||
normalize_spaces,
|
normalize_spaces,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -76,7 +76,6 @@ def test_get_user_phone_number_raises_if_both_api_requests_fail(mocker):
|
|||||||
def test_view_conversation(
|
def test_view_conversation(
|
||||||
client_request,
|
client_request,
|
||||||
mocker,
|
mocker,
|
||||||
api_user_active,
|
|
||||||
mock_get_inbound_sms_by_id_with_no_messages,
|
mock_get_inbound_sms_by_id_with_no_messages,
|
||||||
mock_get_notification,
|
mock_get_notification,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
@@ -84,14 +83,12 @@ def test_view_conversation(
|
|||||||
expected_outbound_content,
|
expected_outbound_content,
|
||||||
mock_get_inbound_sms
|
mock_get_inbound_sms
|
||||||
):
|
):
|
||||||
|
notifications = create_notifications(
|
||||||
mock = mock_get_notifications(
|
content='Hello ((name))',
|
||||||
mocker,
|
|
||||||
api_user_active,
|
|
||||||
template_content='Hello ((name))',
|
|
||||||
personalisation={'name': 'Jo'},
|
personalisation={'name': 'Jo'},
|
||||||
redact_personalisation=outbound_redacted,
|
redact_personalisation=outbound_redacted,
|
||||||
)
|
)
|
||||||
|
mock = mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||||
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
'main.conversation',
|
'main.conversation',
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from tests.conftest import (
|
|||||||
SERVICE_ONE_ID,
|
SERVICE_ONE_ID,
|
||||||
create_active_caseworking_user,
|
create_active_caseworking_user,
|
||||||
create_active_user_with_permissions,
|
create_active_user_with_permissions,
|
||||||
mock_get_notifications,
|
create_notifications,
|
||||||
mock_get_service_letter_template,
|
mock_get_service_letter_template,
|
||||||
normalize_spaces,
|
normalize_spaces,
|
||||||
)
|
)
|
||||||
@@ -360,11 +360,13 @@ def test_should_show_letter_job(
|
|||||||
mock_get_job,
|
mock_get_job,
|
||||||
mock_get_service_data_retention,
|
mock_get_service_data_retention,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
active_user_with_permissions,
|
|
||||||
mocker,
|
mocker,
|
||||||
):
|
):
|
||||||
|
notifications = create_notifications(template_type='letter', subject='template subject')
|
||||||
get_notifications = mock_get_notifications(mocker, active_user_with_permissions, diff_template_type='letter')
|
get_notifications = mocker.patch(
|
||||||
|
'app.notification_api_client.get_notifications_for_service',
|
||||||
|
return_value=notifications,
|
||||||
|
)
|
||||||
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
'main.view_job',
|
'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_job,
|
||||||
mock_get_service_data_retention,
|
mock_get_service_data_retention,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
active_user_with_permissions,
|
|
||||||
mocker,
|
mocker,
|
||||||
):
|
):
|
||||||
mock_get_notifications(
|
notifications = create_notifications(template_type='letter', postage='first')
|
||||||
mocker,
|
mocker.patch('app.notification_api_client.get_notifications_for_service', return_value=notifications)
|
||||||
active_user_with_permissions,
|
|
||||||
diff_template_type='letter',
|
|
||||||
postage='first'
|
|
||||||
)
|
|
||||||
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
'main.view_job',
|
'main.view_job',
|
||||||
|
|||||||
@@ -3930,3 +3930,39 @@ def create_notification(
|
|||||||
if key_type:
|
if key_type:
|
||||||
noti['key_type'] = key_type
|
noti['key_type'] = key_type
|
||||||
return noti
|
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