mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-15 23:38:52 -04:00
Allow extra metadata fields when uploading letter to S3
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import json
|
||||
|
||||
from boto3 import resource
|
||||
from flask import current_app
|
||||
from notifications_utils.s3 import s3upload as utils_s3upload
|
||||
@@ -7,17 +9,23 @@ def get_transient_letter_file_location(service_id, upload_id):
|
||||
return 'service-{}/{}.pdf'.format(service_id, upload_id)
|
||||
|
||||
|
||||
def upload_letter_to_s3(data, *, file_location, status, page_count, filename):
|
||||
def upload_letter_to_s3(data, *, file_location, status, page_count, filename, message=None, invalid_pages=None):
|
||||
metadata = {
|
||||
'status': status,
|
||||
'page_count': str(page_count),
|
||||
'filename': filename,
|
||||
}
|
||||
if message:
|
||||
metadata['message'] = message
|
||||
if invalid_pages:
|
||||
metadata['invalid_pages'] = json.dumps(invalid_pages)
|
||||
|
||||
utils_s3upload(
|
||||
filedata=data,
|
||||
region=current_app.config['AWS_REGION'],
|
||||
bucket_name=current_app.config['TRANSIENT_UPLOADED_LETTERS'],
|
||||
file_location=file_location,
|
||||
metadata={
|
||||
'status': status,
|
||||
'page_count': str(page_count),
|
||||
'filename': filename,
|
||||
}
|
||||
metadata=metadata,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -20,3 +20,30 @@ def test_upload_letter_to_s3(mocker):
|
||||
metadata={'status': 'valid', 'page_count': '3', 'filename': 'my_doc'},
|
||||
region=current_app.config['AWS_REGION']
|
||||
)
|
||||
|
||||
|
||||
def test_upload_letter_to_s3_with_message_and_invalid_pages(mocker):
|
||||
s3_mock = mocker.patch('app.s3_client.s3_letter_upload_client.utils_s3upload')
|
||||
|
||||
upload_letter_to_s3(
|
||||
'pdf_data',
|
||||
file_location='service_id/upload_id.pdf',
|
||||
status='invalid',
|
||||
page_count=3,
|
||||
filename='my_doc',
|
||||
message='This file failed',
|
||||
invalid_pages=[1, 2, 5])
|
||||
|
||||
s3_mock.assert_called_once_with(
|
||||
bucket_name=current_app.config['TRANSIENT_UPLOADED_LETTERS'],
|
||||
file_location='service_id/upload_id.pdf',
|
||||
filedata='pdf_data',
|
||||
metadata={
|
||||
'status': 'invalid',
|
||||
'page_count': '3',
|
||||
'filename': 'my_doc',
|
||||
'message': 'This file failed',
|
||||
'invalid_pages': '[1, 2, 5]'
|
||||
},
|
||||
region=current_app.config['AWS_REGION']
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user