Refactor the code that figures out what folder and filename to use for the letter pdf files.

Now we consistently use the created_at date, so we can always get the right file location and name.

The previous updates to this code were trying to solve the problem if a pdf being created at 17:29, but not ready to upload until 17:31 after the antivirus and validation check.
But in those cases we would have trouble finding the file.
This commit is contained in:
Rebecca Law
2019-09-16 14:20:40 +01:00
committed by Leo Hemsted
parent a10aaddbcc
commit 702d8fa85f
5 changed files with 45 additions and 42 deletions

View File

@@ -55,7 +55,7 @@ def test_get_bucket_name_and_prefix_for_notification_valid_notification(sample_n
).upper()
def test_get_bucket_name_and_prefix_for_notification_get_from_sent_at_date(sample_notification):
def test_get_bucket_name_and_prefix_for_notification_is_tomorrow_after_17_30(sample_notification):
sample_notification.created_at = datetime(2019, 8, 1, 17, 35)
sample_notification.sent_at = datetime(2019, 8, 2, 17, 45)
@@ -68,7 +68,7 @@ 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):
def test_get_bucket_name_and_prefix_for_notification_is_today_before_17_30(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)
@@ -77,7 +77,7 @@ def test_get_bucket_name_and_prefix_for_notification_from_created_at_date(sample
assert bucket == current_app.config['LETTERS_PDF_BUCKET_NAME']
assert bucket_prefix == '{folder}/NOTIFY.{reference}'.format(
folder='2019-08-03',
folder='2019-08-01',
reference=sample_notification.reference
).upper()
@@ -137,10 +137,10 @@ def test_get_bucket_name_and_prefix_for_notification_invalid_notification():
(True, 'C'),
(False, 'N'),
])
@freeze_time("2017-12-04 17:29:00")
def test_get_letter_pdf_filename_returns_correct_filename(
notify_api, mocker, crown_flag, expected_crown_text):
filename = get_letter_pdf_filename(reference='foo', crown=crown_flag)
sending_date = datetime(2017, 12, 4, 17, 29)
filename = get_letter_pdf_filename(reference='foo', crown=crown_flag, sending_date=sending_date)
assert filename == '2017-12-04/NOTIFY.FOO.D.2.C.{}.20171204172900.PDF'.format(expected_crown_text)
@@ -149,25 +149,25 @@ def test_get_letter_pdf_filename_returns_correct_filename(
('second', 2),
('first', 1),
])
@freeze_time("2017-12-04 17:29:00")
def test_get_letter_pdf_filename_returns_correct_postage_for_filename(
notify_api, postage, expected_postage):
filename = get_letter_pdf_filename(reference='foo', crown=True, postage=postage)
sending_date = datetime(2017, 12, 4, 17, 29)
filename = get_letter_pdf_filename(reference='foo', crown=True, sending_date=sending_date, postage=postage)
assert filename == '2017-12-04/NOTIFY.FOO.D.{}.C.C.20171204172900.PDF'.format(expected_postage)
@freeze_time("2017-12-04 17:29:00")
def test_get_letter_pdf_filename_returns_correct_filename_for_test_letters(
notify_api, mocker):
filename = get_letter_pdf_filename(reference='foo', crown='C', is_scan_letter=True)
sending_date = datetime(2017, 12, 4, 17, 29)
filename = get_letter_pdf_filename(reference='foo', crown='C', sending_date=sending_date, is_scan_letter=True)
assert filename == 'NOTIFY.FOO.D.2.C.C.20171204172900.PDF'
@freeze_time("2017-12-04 17:31:00")
def test_get_letter_pdf_filename_returns_tomorrows_filename(notify_api, mocker):
filename = get_letter_pdf_filename(reference='foo', crown=True)
sending_date = datetime(2017, 12, 4, 17, 31)
filename = get_letter_pdf_filename(reference='foo', crown=True, sending_date=sending_date)
assert filename == '2017-12-05/NOTIFY.FOO.D.2.C.C.20171204173100.PDF'
@@ -214,6 +214,7 @@ def test_upload_letter_pdf_to_correct_bucket(
filename = get_letter_pdf_filename(
reference=sample_letter_notification.reference,
crown=sample_letter_notification.service.crown,
sending_date=sample_letter_notification.created_at,
is_scan_letter=is_precompiled_letter
)
@@ -240,6 +241,7 @@ def test_upload_letter_pdf_uses_postage_from_notification(
filename = get_letter_pdf_filename(
reference=letter_notification.reference,
crown=letter_notification.service.crown,
sending_date=letter_notification.created_at,
is_scan_letter=False,
postage=letter_notification.postage
)