rename sending_date to created_at

we don't name letters based on the day we send them on, rather, the day
we create them on. If we process a letter for a second time for whatever
reason, even if it's a couple of days later, it'll still go in a folder
based on the created_at timestamp. There's still a slight confusion,
however - if the timestamp is after 5:30pm, the folder will be for the
day after. However, still the day after creation, so I think created_at
still makes the most sense.

Remove the term `sending_date` to try and make this relationship more
apparent.
This commit is contained in:
Leo Hemsted
2020-09-21 14:40:22 +01:00
parent 4f1e5ee5a3
commit 1e928a926a
6 changed files with 21 additions and 21 deletions

View File

@@ -63,7 +63,7 @@ def get_pdf_for_templated_letter(self, notification_id):
letter_filename = get_letter_pdf_filename(
reference=notification.reference,
crown=notification.service.crown,
sending_date=notification.created_at,
created_at=notification.created_at,
ignore_folder=notification.key_type == KEY_TYPE_TEST,
postage=notification.postage
)
@@ -182,7 +182,7 @@ def get_key_and_size_of_letters_to_be_sent_to_print(print_run_deadline, postage)
letter_file_name = get_letter_pdf_filename(
reference=letter.reference,
crown=letter.service.crown,
sending_date=letter.created_at,
created_at=letter.created_at,
postage=letter.postage
)
letter_head = s3.head_s3_object(current_app.config['LETTERS_PDF_BUCKET_NAME'], letter_file_name)
@@ -311,7 +311,7 @@ def process_sanitised_letter(self, sanitise_data):
upload_file_name = get_letter_pdf_filename(
reference=notification.reference,
crown=notification.service.crown,
sending_date=notification.created_at,
created_at=notification.created_at,
ignore_folder=True,
postage=notification.postage
)

View File

@@ -432,7 +432,7 @@ def _delete_letters_from_s3(
if letter.sent_at:
prefix = get_letter_pdf_filename(reference=letter.reference,
crown=letter.service.crown,
sending_date=letter.created_at,
created_at=letter.created_at,
ignore_folder=letter.key_type == KEY_TYPE_TEST,
postage=letter.postage)
s3_objects = get_s3_bucket_objects(bucket_name=bucket_name, subfolder=prefix)

View File

@@ -34,15 +34,15 @@ def get_folder_name(created_at):
return '{}/'.format(print_datetime.date())
def get_letter_pdf_filename(reference, crown, sending_date, ignore_folder=False, postage=SECOND_CLASS):
def get_letter_pdf_filename(reference, crown, created_at, ignore_folder=False, postage=SECOND_CLASS):
upload_file_name = LETTERS_PDF_FILE_LOCATION_STRUCTURE.format(
folder='' if ignore_folder else get_folder_name(sending_date),
folder='' if ignore_folder else get_folder_name(created_at),
reference=reference,
duplex="D",
letter_class=RESOLVE_POSTAGE_FOR_FILE_NAME[postage],
colour="C",
crown="C" if crown else "N",
date=sending_date.strftime('%Y%m%d%H%M%S')
date=created_at.strftime('%Y%m%d%H%M%S')
).upper()
return upload_file_name
@@ -78,7 +78,7 @@ def upload_letter_pdf(notification, pdf_data, precompiled=False):
upload_file_name = get_letter_pdf_filename(
reference=notification.reference,
crown=notification.service.crown,
sending_date=notification.created_at,
created_at=notification.created_at,
ignore_folder=precompiled or notification.key_type == KEY_TYPE_TEST,
postage=notification.postage
)

View File

@@ -195,7 +195,7 @@ def send_pdf_letter_notification(service_id, post_data):
upload_filename = get_letter_pdf_filename(
reference=notification.reference,
crown=notification.service.crown,
sending_date=notification.created_at,
created_at=notification.created_at,
ignore_folder=False,
postage=notification.postage
)

View File

@@ -93,13 +93,13 @@ def test_get_pdf_for_templated_letter_happy_path(mocker, sample_letter_notificat
mock_get_letter_pdf_filename.assert_called_once_with(
reference=sample_letter_notification.reference,
crown=True,
sending_date=sample_letter_notification.created_at,
created_at=sample_letter_notification.created_at,
ignore_folder=False,
postage='second'
)
def test_get_pdf_for_templated_letter_non_existent_notification(notify_api, mocker, fake_uuid):
def test_get_pdf_for_templated_letter_non_existent_notification(notify_db_session, mocker, fake_uuid):
with pytest.raises(expected_exception=NoResultFound):
get_pdf_for_templated_letter(fake_uuid)

View File

@@ -140,8 +140,8 @@ def test_get_bucket_name_and_prefix_for_notification_invalid_notification():
])
def test_get_letter_pdf_filename_returns_correct_filename(
notify_api, mocker, crown_flag, expected_crown_text):
sending_date = datetime(2017, 12, 4, 17, 29)
filename = get_letter_pdf_filename(reference='foo', crown=crown_flag, sending_date=sending_date)
created_at = datetime(2017, 12, 4, 17, 29)
filename = get_letter_pdf_filename(reference='foo', crown=crown_flag, created_at=created_at)
assert filename == '2017-12-04/NOTIFY.FOO.D.2.C.{}.20171204172900.PDF'.format(expected_crown_text)
@@ -152,24 +152,24 @@ def test_get_letter_pdf_filename_returns_correct_filename(
])
def test_get_letter_pdf_filename_returns_correct_postage_for_filename(
notify_api, postage, expected_postage):
sending_date = datetime(2017, 12, 4, 17, 29)
filename = get_letter_pdf_filename(reference='foo', crown=True, sending_date=sending_date, postage=postage)
created_at = datetime(2017, 12, 4, 17, 29)
filename = get_letter_pdf_filename(reference='foo', crown=True, created_at=created_at, postage=postage)
assert filename == '2017-12-04/NOTIFY.FOO.D.{}.C.C.20171204172900.PDF'.format(expected_postage)
def test_get_letter_pdf_filename_returns_correct_filename_for_test_letters(
notify_api, mocker):
sending_date = datetime(2017, 12, 4, 17, 29)
created_at = datetime(2017, 12, 4, 17, 29)
filename = get_letter_pdf_filename(reference='foo', crown='C',
sending_date=sending_date, ignore_folder=True)
created_at=created_at, ignore_folder=True)
assert filename == 'NOTIFY.FOO.D.2.C.C.20171204172900.PDF'
def test_get_letter_pdf_filename_returns_tomorrows_filename(notify_api, mocker):
sending_date = datetime(2017, 12, 4, 17, 31)
filename = get_letter_pdf_filename(reference='foo', crown=True, sending_date=sending_date)
created_at = datetime(2017, 12, 4, 17, 31)
filename = get_letter_pdf_filename(reference='foo', crown=True, created_at=created_at)
assert filename == '2017-12-05/NOTIFY.FOO.D.2.C.C.20171204173100.PDF'
@@ -216,7 +216,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,
created_at=sample_letter_notification.created_at,
ignore_folder=is_precompiled_letter
)
@@ -243,7 +243,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,
created_at=letter_notification.created_at,
ignore_folder=False,
postage=letter_notification.postage
)