mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 16:31:15 -05:00
Use the letter_branding logo if it exists otherwise fall back to the dvla_organisation logo.
This commit is contained in:
@@ -52,11 +52,13 @@ from app.models import (
|
|||||||
def create_letters_pdf(self, notification_id):
|
def create_letters_pdf(self, notification_id):
|
||||||
try:
|
try:
|
||||||
notification = get_notification_by_id(notification_id, _raise=True)
|
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(
|
pdf_data, billable_units = get_letters_pdf(
|
||||||
notification.template,
|
notification.template,
|
||||||
contact_block=notification.reply_to_text,
|
contact_block=notification.reply_to_text,
|
||||||
filename=notification.service.dvla_organisation.filename,
|
filename=letter_logo_file_name,
|
||||||
values=notification.personalisation
|
values=notification.personalisation
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -274,13 +274,15 @@ def preview_letter_template_by_notification_id(service_id, notification_id, file
|
|||||||
}
|
}
|
||||||
|
|
||||||
service = dao_fetch_service_by_id(service_id)
|
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 = {
|
data = {
|
||||||
'letter_contact_block': notification.reply_to_text,
|
'letter_contact_block': notification.reply_to_text,
|
||||||
'template': template_for_letter_print,
|
'template': template_for_letter_print,
|
||||||
'values': notification.personalisation,
|
'values': notification.personalisation,
|
||||||
'date': notification.created_at.isoformat(),
|
'date': notification.created_at.isoformat(),
|
||||||
'filename': service.dvla_organisation.filename,
|
'filename': letter_logo_filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
url = '{}/preview.{}{}'.format(
|
url = '{}/preview.{}{}'.format(
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ from app.models import (
|
|||||||
NOTIFICATION_VIRUS_SCAN_FAILED,
|
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
|
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')
|
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):
|
def test_collate_letter_pdfs_for_day(notify_api, mocker):
|
||||||
mock_s3 = mocker.patch('app.celery.tasks.s3.get_s3_bucket_objects')
|
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=[
|
mock_group_letters = mocker.patch('app.celery.letters_pdf_tasks.group_letters', return_value=[
|
||||||
|
|||||||
Reference in New Issue
Block a user