mirror of
https://github.com/GSA/notifications-api.git
synced 2026-06-03 21:08:26 -04:00
Change get_bucket_name_and_prefix_for_notification to use created_at
The `get_bucket_name_and_prefix_for_notification` function was looking at the `sent_at` or `updated_at` at time of a notification to see which bucket it was in. Precompiled letters sent through the admin app don't have either of these times - they only have a `created_at` time, so this lets the function check `created_at` time too.
This commit is contained in:
@@ -63,8 +63,10 @@ def get_bucket_name_and_prefix_for_notification(notification):
|
||||
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
||||
if notification.sent_at:
|
||||
folder = "{}/".format(notification.sent_at.date())
|
||||
else:
|
||||
elif notification.updated_at:
|
||||
folder = get_folder_name(notification.updated_at, False)
|
||||
else:
|
||||
folder = get_folder_name(notification.created_at, False)
|
||||
|
||||
upload_file_name = PRECOMPILED_BUCKET_PREFIX.format(
|
||||
folder=folder,
|
||||
|
||||
@@ -68,6 +68,20 @@ def test_get_bucket_name_and_prefix_for_notification_get_from_sent_at_date(sampl
|
||||
).upper()
|
||||
|
||||
|
||||
def test_get_bucket_name_and_prefix_for_notification_from_created_at_date(sample_notification):
|
||||
sample_notification.created_at = datetime(2019, 8, 1, 12, 00)
|
||||
sample_notification.updated_at = datetime(2019, 8, 2, 12, 00)
|
||||
sample_notification.sent_at = datetime(2019, 8, 3, 12, 00)
|
||||
|
||||
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-03',
|
||||
reference=sample_notification.reference
|
||||
).upper()
|
||||
|
||||
|
||||
@freeze_time(FROZEN_DATE_TIME)
|
||||
def test_get_bucket_name_and_prefix_for_notification_precompiled_letter_using_test_key(
|
||||
sample_precompiled_letter_notification_using_test_key
|
||||
|
||||
Reference in New Issue
Block a user