From 85fc601886b5fc255c9db801f893defee5b4ddf1 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 1 May 2020 14:26:20 +0100 Subject: [PATCH] Tell template preview to allow international letters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a service has permission to send international letters then it should tell template preview, so that template preview knows what rule to apply when it’s validating the address of the letter. Depends on: - [ ] https://github.com/alphagov/notifications-template-preview/pull/445 --- app/celery/letters_pdf_tasks.py | 4 ++++ tests/app/celery/test_letters_pdf_tasks.py | 24 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/celery/letters_pdf_tasks.py b/app/celery/letters_pdf_tasks.py index 495426cba..0d749e057 100644 --- a/app/celery/letters_pdf_tasks.py +++ b/app/celery/letters_pdf_tasks.py @@ -40,6 +40,7 @@ from app.letters.utils import ( get_file_names_from_error_bucket, ) from app.models import ( + INTERNATIONAL_LETTERS, KEY_TYPE_TEST, NOTIFICATION_CREATED, NOTIFICATION_DELIVERED, @@ -227,6 +228,9 @@ def sanitise_letter(self, filename): kwargs={ 'notification_id': str(notification.id), 'filename': filename, + 'allow_international_letters': notification.service.has_permission( + INTERNATIONAL_LETTERS + ), }, queue=QueueNames.SANITISE_LETTERS, ) diff --git a/tests/app/celery/test_letters_pdf_tasks.py b/tests/app/celery/test_letters_pdf_tasks.py index a6e43c27b..6f4e1562a 100644 --- a/tests/app/celery/test_letters_pdf_tasks.py +++ b/tests/app/celery/test_letters_pdf_tasks.py @@ -31,8 +31,10 @@ from app.celery.letters_pdf_tasks import ( from app.config import QueueNames, TaskNames from app.letters.utils import ScanErrorType from app.models import ( + INTERNATIONAL_LETTERS, KEY_TYPE_NORMAL, KEY_TYPE_TEST, + LETTER_TYPE, Notification, NOTIFICATION_CREATED, NOTIFICATION_DELIVERED, @@ -42,7 +44,7 @@ from app.models import ( NOTIFICATION_VIRUS_SCAN_FAILED, ) -from tests.app.db import create_notification, create_letter_branding +from tests.app.db import create_notification, create_letter_branding, create_service from tests.conftest import set_config_values @@ -546,16 +548,32 @@ def test_move_invalid_letter_and_update_status_logs_error_and_sets_tech_failure_ ) -def test_sanitise_letter_calls_template_preview_sanitise_task(mocker, sample_letter_notification): +@pytest.mark.parametrize('permissions, expected_international_letters_allowed', ( + ([LETTER_TYPE], False), + ([LETTER_TYPE, INTERNATIONAL_LETTERS], True), +)) +def test_sanitise_letter_calls_template_preview_sanitise_task( + mocker, + sample_letter_notification, + permissions, + expected_international_letters_allowed, +): mock_celery = mocker.patch('app.celery.letters_pdf_tasks.notify_celery.send_task') filename = 'NOTIFY.{}'.format(sample_letter_notification.reference) + sample_letter_notification.service = create_service( + service_permissions=permissions + ) sample_letter_notification.status = NOTIFICATION_PENDING_VIRUS_CHECK sanitise_letter(filename) mock_celery.assert_called_once_with( name=TaskNames.SANITISE_LETTER, - kwargs={'notification_id': str(sample_letter_notification.id), 'filename': filename}, + kwargs={ + 'notification_id': str(sample_letter_notification.id), + 'filename': filename, + 'allow_international_letters': expected_international_letters_allowed, + }, queue=QueueNames.SANITISE_LETTERS, )