mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 10:03:38 -04:00
Merge pull request #2605 from alphagov/fix-get-pdf-using-created_at-date
Fix the folder returned for a pdf letter.
This commit is contained in:
@@ -58,7 +58,10 @@ def get_bucket_name_and_prefix_for_notification(notification):
|
|||||||
bucket_name = current_app.config['TEST_LETTERS_BUCKET_NAME']
|
bucket_name = current_app.config['TEST_LETTERS_BUCKET_NAME']
|
||||||
else:
|
else:
|
||||||
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
||||||
folder = get_folder_name(notification.created_at, False)
|
if notification.sent_at:
|
||||||
|
folder = "{}/".format(notification.sent_at.date())
|
||||||
|
else:
|
||||||
|
folder = get_folder_name(notification.updated_at, False)
|
||||||
|
|
||||||
upload_file_name = PRECOMPILED_BUCKET_PREFIX.format(
|
upload_file_name = PRECOMPILED_BUCKET_PREFIX.format(
|
||||||
folder=folder,
|
folder=folder,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ def _sample_precompiled_letter_notification(sample_letter_notification):
|
|||||||
sample_letter_notification.reference = 'foo'
|
sample_letter_notification.reference = 'foo'
|
||||||
with freeze_time(FROZEN_DATE_TIME):
|
with freeze_time(FROZEN_DATE_TIME):
|
||||||
sample_letter_notification.created_at = datetime.utcnow()
|
sample_letter_notification.created_at = datetime.utcnow()
|
||||||
|
sample_letter_notification.updated_at = datetime.utcnow()
|
||||||
return sample_letter_notification
|
return sample_letter_notification
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ def _sample_precompiled_letter_notification_using_test_key(sample_precompiled_le
|
|||||||
])
|
])
|
||||||
def test_get_bucket_name_and_prefix_for_notification_valid_notification(sample_notification, created_at, folder):
|
def test_get_bucket_name_and_prefix_for_notification_valid_notification(sample_notification, created_at, folder):
|
||||||
sample_notification.created_at = created_at
|
sample_notification.created_at = created_at
|
||||||
|
sample_notification.updated_at = created_at
|
||||||
|
|
||||||
bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(sample_notification)
|
bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(sample_notification)
|
||||||
|
|
||||||
@@ -52,6 +54,19 @@ def test_get_bucket_name_and_prefix_for_notification_valid_notification(sample_n
|
|||||||
).upper()
|
).upper()
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_bucket_name_and_prefix_for_notification_get_from_sent_at_date(sample_notification):
|
||||||
|
sample_notification.created_at = datetime(2019, 8, 1, 17, 35)
|
||||||
|
sample_notification.sent_at = datetime(2019, 8, 2, 17, 45)
|
||||||
|
|
||||||
|
bucket, bucket_prefix = get_bucket_name_and_prefix_for_notification(sample_notification)
|
||||||
|
|
||||||
|
assert bucket == current_app.config['LETTERS_PDF_BUCKET_NAME']
|
||||||
|
assert bucket_prefix == '{folder}/NOTIFY.{reference}'.format(
|
||||||
|
folder='2019-08-02',
|
||||||
|
reference=sample_notification.reference
|
||||||
|
).upper()
|
||||||
|
|
||||||
|
|
||||||
@freeze_time(FROZEN_DATE_TIME)
|
@freeze_time(FROZEN_DATE_TIME)
|
||||||
def test_get_bucket_name_and_prefix_for_notification_precompiled_letter_using_test_key(
|
def test_get_bucket_name_and_prefix_for_notification_precompiled_letter_using_test_key(
|
||||||
sample_precompiled_letter_notification_using_test_key
|
sample_precompiled_letter_notification_using_test_key
|
||||||
|
|||||||
Reference in New Issue
Block a user