mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 23:41:17 -05:00
Call the create letters pdf task in api calls for services with letters as pdf
This commit is contained in:
@@ -14,6 +14,7 @@ from app.models import (
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_SENDING
|
||||
)
|
||||
from app.celery.letters_pdf_tasks import create_letters_pdf
|
||||
from app.celery.tasks import update_letter_notifications_to_sent_to_dvla
|
||||
from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
@@ -187,6 +188,12 @@ def process_letter_notification(*, letter_data, api_key, template):
|
||||
queue=QueueNames.RESEARCH_MODE
|
||||
)
|
||||
|
||||
if api_key.service.has_permission('letters_as_pdf'):
|
||||
create_letters_pdf.apply_async(
|
||||
[str(notification.id)],
|
||||
queue=QueueNames.CREATE_LETTERS_PDF
|
||||
)
|
||||
|
||||
return notification
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ from flask import json
|
||||
from flask import url_for
|
||||
import pytest
|
||||
|
||||
from app.config import QueueNames
|
||||
from app.dao import service_permissions_dao
|
||||
from app.models import EMAIL_TYPE
|
||||
from app.models import Job
|
||||
from app.models import KEY_TYPE_NORMAL
|
||||
@@ -80,6 +82,29 @@ def test_post_letter_notification_returns_201(client, sample_letter_template, mo
|
||||
assert not notification.reply_to_text
|
||||
|
||||
|
||||
def test_post_letter_notification_for_letters_as_pdf_calls_celery_task(client, sample_letter_template, mocker):
|
||||
service_permissions_dao.dao_add_service_permission(sample_letter_template.service.id, 'letters_as_pdf')
|
||||
|
||||
data = {
|
||||
'template_id': str(sample_letter_template.id),
|
||||
'personalisation': {
|
||||
'address_line_1': 'Her Royal Highness Queen Elizabeth II',
|
||||
'address_line_2': 'Buckingham Palace',
|
||||
'address_line_3': 'London',
|
||||
'postcode': 'SW1 1AA',
|
||||
'name': 'Lizzie'
|
||||
},
|
||||
'reference': 'foo'
|
||||
}
|
||||
fake_task = mocker.patch('app.celery.tasks.letters_pdf_tasks.create_letters_pdf.apply_async')
|
||||
|
||||
letter_request(client, data, service_id=sample_letter_template.service_id)
|
||||
|
||||
notification = Notification.query.one()
|
||||
|
||||
fake_task.assert_called_once_with([str(notification.id)], queue=QueueNames.CREATE_LETTERS_PDF)
|
||||
|
||||
|
||||
def test_post_letter_notification_returns_400_and_missing_template(
|
||||
client,
|
||||
sample_service_full_permissions
|
||||
|
||||
Reference in New Issue
Block a user