From 95d48d40a93039f2f82fd0a9ae85fd58cbcb0b49 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Wed, 26 Feb 2020 16:04:15 +0000 Subject: [PATCH] Update error message, now includes the url where the service can add contact details. --- app/notifications/validators.py | 6 ++++-- app/v2/notifications/post_notifications.py | 5 ++++- tests/app/notifications/test_validators.py | 13 ++++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/notifications/validators.py b/app/notifications/validators.py index 532d6e857..39e4b5386 100644 --- a/app/notifications/validators.py +++ b/app/notifications/validators.py @@ -89,10 +89,12 @@ def check_service_has_permission(notify_type, permissions): )) -def check_if_service_can_send_files_by_email(service_contact_link): +def check_if_service_can_send_files_by_email(service_contact_link, service_id): if not service_contact_link: + raise BadRequestError( - message="Send files by email has not been set up. Go to your Settings page to manage Send files by email." + message=f"Send files by email has not been set up - add contact details for your service at " + f"{current_app.config['ADMIN_BASE_URL']}/services/{service_id}/service-settings/send-files-by-email" ) diff --git a/app/v2/notifications/post_notifications.py b/app/v2/notifications/post_notifications.py index cc60b9579..04aae8776 100644 --- a/app/v2/notifications/post_notifications.py +++ b/app/v2/notifications/post_notifications.py @@ -235,7 +235,10 @@ def process_document_uploads(personalisation_data, service, simulated=False): personalisation_data = personalisation_data.copy() - check_if_service_can_send_files_by_email(authenticated_service.contact_link) + check_if_service_can_send_files_by_email( + service_contact_link=authenticated_service.contact_link, + service_id=authenticated_service.id + ) for key in file_keys: if simulated: diff --git a/tests/app/notifications/test_validators.py b/tests/app/notifications/test_validators.py index 70f4f3b01..f4ee4c6ee 100644 --- a/tests/app/notifications/test_validators.py +++ b/tests/app/notifications/test_validators.py @@ -533,13 +533,20 @@ def test_check_reply_to_letter_type(sample_service): def test_check_if_service_can_send_files_by_email_raises_if_no_contact_link_set(sample_service): with pytest.raises(BadRequestError) as e: - check_if_service_can_send_files_by_email(sample_service.contact_link) + check_if_service_can_send_files_by_email( + service_contact_link=sample_service.contact_link, + service_id=sample_service.id + ) - message = "Send files by email has not been set up. Go to your Settings page to manage Send files by email." + message = f"Send files by email has not been set up - add contact details for your service at " \ + f"http://localhost:6012/services/{sample_service.id}/service-settings/send-files-by-email" assert e.value.status_code == 400 assert e.value.message == message def test_check_if_service_can_send_files_by_email_passes_if_contact_link_set(sample_service): sample_service.contact_link = 'contact.me@gov.uk' - check_if_service_can_send_files_by_email(sample_service.contact_link) + check_if_service_can_send_files_by_email( + service_contact_link=sample_service.contact_link, + service_id=sample_service.id + )