diff --git a/app/celery/letters_pdf_tasks.py b/app/celery/letters_pdf_tasks.py index a57be4044..6cb126740 100644 --- a/app/celery/letters_pdf_tasks.py +++ b/app/celery/letters_pdf_tasks.py @@ -52,11 +52,13 @@ from app.models import ( def create_letters_pdf(self, notification_id): try: notification = get_notification_by_id(notification_id, _raise=True) - + # We only need this while we are migrating to the new letter_branding model + letter_logo_file_name = notification.service.letter_branding.filename if notification.service.letter_branding\ + else notification.service.dvla_organisation.filename pdf_data, billable_units = get_letters_pdf( notification.template, contact_block=notification.reply_to_text, - filename=notification.service.dvla_organisation.filename, + filename=letter_logo_file_name, values=notification.personalisation ) diff --git a/app/template/rest.py b/app/template/rest.py index 79b1d7d8b..db744fdda 100644 --- a/app/template/rest.py +++ b/app/template/rest.py @@ -274,13 +274,15 @@ def preview_letter_template_by_notification_id(service_id, notification_id, file } service = dao_fetch_service_by_id(service_id) - + # We only need this while we are migrating to the new letter_branding model + letter_logo_filename = service.letter_branding.filename if service.letter_branding \ + else service.dvla_organisation.filename data = { 'letter_contact_block': notification.reply_to_text, 'template': template_for_letter_print, 'values': notification.personalisation, 'date': notification.created_at.isoformat(), - 'filename': service.dvla_organisation.filename, + 'filename': letter_logo_filename, } url = '{}/preview.{}{}'.format( diff --git a/tests/app/celery/test_letters_pdf_tasks.py b/tests/app/celery/test_letters_pdf_tasks.py index ce7c9cd79..586f48b85 100644 --- a/tests/app/celery/test_letters_pdf_tasks.py +++ b/tests/app/celery/test_letters_pdf_tasks.py @@ -39,7 +39,7 @@ from app.models import ( NOTIFICATION_VIRUS_SCAN_FAILED, ) -from tests.app.db import create_notification +from tests.app.db import create_notification, create_letter_branding from tests.conftest import set_config_values @@ -182,6 +182,42 @@ def test_create_letters_pdf_sets_technical_failure_max_retries(mocker, sample_le mock_update_noti.assert_called_once_with(sample_letter_notification.id, 'technical-failure') +# We only need this while we are migrating to the new letter_branding model +def test_create_letters_gets_the_right_logo_when_service_has_dvla_logo( + notify_api, mocker, sample_letter_notification +): + mock_get_letters_pdf = mocker.patch('app.celery.letters_pdf_tasks.get_letters_pdf', return_value=(b'\x00\x01', 1)) + mocker.patch('app.letters.utils.upload_letter_pdf') + mocker.patch('app.celery.letters_pdf_tasks.update_notification_status_by_id') + + create_letters_pdf(sample_letter_notification.id) + mock_get_letters_pdf.assert_called_once_with( + sample_letter_notification.template, + contact_block=sample_letter_notification.reply_to_text, + filename=sample_letter_notification.service.dvla_organisation.filename, + values=sample_letter_notification.personalisation + ) + + +# We only need this while we are migrating to the new letter_branding model +def test_create_letters_gets_the_right_logo_when_service_has_letter_branding_logo( + notify_api, mocker, sample_letter_notification +): + letter_branding = create_letter_branding(name='test brand', filename='test-brand', platform_default=False) + sample_letter_notification.service.letter_branding = letter_branding + mock_get_letters_pdf = mocker.patch('app.celery.letters_pdf_tasks.get_letters_pdf', return_value=(b'\x00\x01', 1)) + mocker.patch('app.letters.utils.upload_letter_pdf') + mocker.patch('app.celery.letters_pdf_tasks.update_notification_status_by_id') + + create_letters_pdf(sample_letter_notification.id) + mock_get_letters_pdf.assert_called_once_with( + sample_letter_notification.template, + contact_block=sample_letter_notification.reply_to_text, + filename=sample_letter_notification.service.letter_branding.filename, + values=sample_letter_notification.personalisation + ) + + def test_collate_letter_pdfs_for_day(notify_api, mocker): mock_s3 = mocker.patch('app.celery.tasks.s3.get_s3_bucket_objects') mock_group_letters = mocker.patch('app.celery.letters_pdf_tasks.group_letters', return_value=[