mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
create pdfs for test templated letters
previously, we didn't create templated letters, and just marked them as delivered straight away. However, we may need to return PDFs for these letters, so we should create them the same as live letters. Then update the functions so that they know where to look for these letters.
This commit is contained in:
@@ -67,8 +67,9 @@ def create_letters_pdf(self, notification_id):
|
||||
|
||||
upload_letter_pdf(notification, pdf_data)
|
||||
|
||||
notification.billable_units = billable_units
|
||||
dao_update_notification(notification)
|
||||
if notification.key_type != KEY_TYPE_TEST:
|
||||
notification.billable_units = billable_units
|
||||
dao_update_notification(notification)
|
||||
|
||||
current_app.logger.info(
|
||||
'Letter notification reference {reference}: billable units set to {billable_units}'.format(
|
||||
|
||||
@@ -50,11 +50,10 @@ def get_letter_pdf_filename(reference, crown, is_scan_letter=False, postage=SECO
|
||||
|
||||
|
||||
def get_bucket_name_and_prefix_for_notification(notification):
|
||||
is_test_letter = notification.key_type == KEY_TYPE_TEST and notification.template.is_precompiled_letter
|
||||
folder = ''
|
||||
if notification.status == NOTIFICATION_VALIDATION_FAILED:
|
||||
bucket_name = current_app.config['INVALID_PDF_BUCKET_NAME']
|
||||
elif is_test_letter:
|
||||
elif notification.key_type == KEY_TYPE_TEST:
|
||||
bucket_name = current_app.config['TEST_LETTERS_BUCKET_NAME']
|
||||
else:
|
||||
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
||||
@@ -90,6 +89,8 @@ def upload_letter_pdf(notification, pdf_data, precompiled=False):
|
||||
|
||||
if precompiled:
|
||||
bucket_name = current_app.config['LETTERS_SCAN_BUCKET_NAME']
|
||||
elif notification.key_type == KEY_TYPE_TEST:
|
||||
bucket_name = current_app.config['TEST_LETTERS_BUCKET_NAME']
|
||||
else:
|
||||
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
||||
|
||||
|
||||
@@ -259,10 +259,11 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text
|
||||
template=template,
|
||||
reply_to_text=reply_to_text)
|
||||
|
||||
should_send = not (api_key.key_type == KEY_TYPE_TEST)
|
||||
test_key = api_key.key_type == KEY_TYPE_TEST
|
||||
|
||||
# if we don't want to actually send the letter, then start it off in SENDING so we don't pick it up
|
||||
status = NOTIFICATION_CREATED if should_send else NOTIFICATION_SENDING
|
||||
status = NOTIFICATION_CREATED if not test_key else NOTIFICATION_SENDING
|
||||
queue = QueueNames.CREATE_LETTERS_PDF if not test_key else QueueNames.RESEARCH_MODE
|
||||
|
||||
notification = create_letter_notification(letter_data=letter_data,
|
||||
template=template,
|
||||
@@ -270,18 +271,19 @@ def process_letter_notification(*, letter_data, api_key, template, reply_to_text
|
||||
status=status,
|
||||
reply_to_text=reply_to_text)
|
||||
|
||||
if should_send:
|
||||
create_letters_pdf.apply_async(
|
||||
[str(notification.id)],
|
||||
queue=QueueNames.CREATE_LETTERS_PDF
|
||||
)
|
||||
elif current_app.config['NOTIFY_ENVIRONMENT'] in ['preview', 'development']:
|
||||
create_fake_letter_response_file.apply_async(
|
||||
(notification.reference,),
|
||||
queue=QueueNames.RESEARCH_MODE
|
||||
)
|
||||
else:
|
||||
update_notification_status_by_reference(notification.reference, NOTIFICATION_DELIVERED)
|
||||
create_letters_pdf.apply_async(
|
||||
[str(notification.id)],
|
||||
queue=queue
|
||||
)
|
||||
|
||||
if test_key:
|
||||
if current_app.config['NOTIFY_ENVIRONMENT'] in ['preview', 'development']:
|
||||
create_fake_letter_response_file.apply_async(
|
||||
(notification.reference,),
|
||||
queue=queue
|
||||
)
|
||||
else:
|
||||
update_notification_status_by_reference(notification.reference, NOTIFICATION_DELIVERED)
|
||||
|
||||
return notification
|
||||
|
||||
|
||||
Reference in New Issue
Block a user