mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Add test-letters bucket for precompiled test keys
- uses moto to mock out boto3 for testing
This commit is contained in:
@@ -5,13 +5,14 @@ from flask import current_app
|
||||
|
||||
from notifications_utils.s3 import s3upload
|
||||
|
||||
from app.models import KEY_TYPE_TEST
|
||||
from app.variables import Retention
|
||||
|
||||
|
||||
LETTERS_PDF_FILE_LOCATION_STRUCTURE = \
|
||||
'{folder}NOTIFY.{reference}.{duplex}.{letter_class}.{colour}.{crown}.{date}.pdf'
|
||||
|
||||
PRECOMPILED_BUCKET_PREFIX = '{folder}/NOTIFY.{reference}'
|
||||
PRECOMPILED_BUCKET_PREFIX = '{folder}NOTIFY.{reference}'
|
||||
|
||||
|
||||
def get_folder_name(_now, is_test_letter):
|
||||
@@ -41,9 +42,10 @@ def get_letter_pdf_filename(reference, crown, is_test_letter=False):
|
||||
return upload_file_name
|
||||
|
||||
|
||||
def get_bucket_prefix_for_notification(notification):
|
||||
def get_bucket_prefix_for_notification(notification, is_test_letter=False):
|
||||
upload_file_name = PRECOMPILED_BUCKET_PREFIX.format(
|
||||
folder=notification.created_at.date(),
|
||||
folder='' if is_test_letter else
|
||||
'{}/'.format(notification.created_at.date()),
|
||||
reference=notification.reference
|
||||
).upper()
|
||||
|
||||
@@ -75,12 +77,16 @@ def upload_letter_pdf(notification, pdf_data, is_test_letter=False):
|
||||
|
||||
|
||||
def get_letter_pdf(notification):
|
||||
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
||||
is_test_letter = notification.key_type == KEY_TYPE_TEST and notification.template.is_precompiled_letter
|
||||
if is_test_letter:
|
||||
bucket_name = current_app.config['TEST_LETTERS_BUCKET_NAME']
|
||||
else:
|
||||
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
||||
|
||||
s3 = boto3.resource('s3')
|
||||
bucket = s3.Bucket(bucket_name)
|
||||
|
||||
for item in bucket.objects.filter(Prefix=get_bucket_prefix_for_notification(notification)):
|
||||
for item in bucket.objects.filter(Prefix=get_bucket_prefix_for_notification(notification, is_test_letter)):
|
||||
obj = s3.Object(
|
||||
bucket_name=bucket_name,
|
||||
key=item.key
|
||||
|
||||
Reference in New Issue
Block a user