mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-25 08:43:55 -04:00
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:
@@ -63,7 +63,7 @@ def get_pdf_for_templated_letter(self, notification_id):
|
|||||||
letter_filename = get_letter_pdf_filename(
|
letter_filename = get_letter_pdf_filename(
|
||||||
reference=notification.reference,
|
reference=notification.reference,
|
||||||
crown=notification.service.crown,
|
crown=notification.service.crown,
|
||||||
sending_date=notification.created_at,
|
created_at=notification.created_at,
|
||||||
ignore_folder=notification.key_type == KEY_TYPE_TEST,
|
ignore_folder=notification.key_type == KEY_TYPE_TEST,
|
||||||
postage=notification.postage
|
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(
|
letter_file_name = get_letter_pdf_filename(
|
||||||
reference=letter.reference,
|
reference=letter.reference,
|
||||||
crown=letter.service.crown,
|
crown=letter.service.crown,
|
||||||
sending_date=letter.created_at,
|
created_at=letter.created_at,
|
||||||
postage=letter.postage
|
postage=letter.postage
|
||||||
)
|
)
|
||||||
letter_head = s3.head_s3_object(current_app.config['LETTERS_PDF_BUCKET_NAME'], letter_file_name)
|
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(
|
upload_file_name = get_letter_pdf_filename(
|
||||||
reference=notification.reference,
|
reference=notification.reference,
|
||||||
crown=notification.service.crown,
|
crown=notification.service.crown,
|
||||||
sending_date=notification.created_at,
|
created_at=notification.created_at,
|
||||||
ignore_folder=True,
|
ignore_folder=True,
|
||||||
postage=notification.postage
|
postage=notification.postage
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ def _delete_letters_from_s3(
|
|||||||
if letter.sent_at:
|
if letter.sent_at:
|
||||||
prefix = get_letter_pdf_filename(reference=letter.reference,
|
prefix = get_letter_pdf_filename(reference=letter.reference,
|
||||||
crown=letter.service.crown,
|
crown=letter.service.crown,
|
||||||
sending_date=letter.created_at,
|
created_at=letter.created_at,
|
||||||
ignore_folder=letter.key_type == KEY_TYPE_TEST,
|
ignore_folder=letter.key_type == KEY_TYPE_TEST,
|
||||||
postage=letter.postage)
|
postage=letter.postage)
|
||||||
s3_objects = get_s3_bucket_objects(bucket_name=bucket_name, subfolder=prefix)
|
s3_objects = get_s3_bucket_objects(bucket_name=bucket_name, subfolder=prefix)
|
||||||
|
|||||||
@@ -34,15 +34,15 @@ def get_folder_name(created_at):
|
|||||||
return '{}/'.format(print_datetime.date())
|
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(
|
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,
|
reference=reference,
|
||||||
duplex="D",
|
duplex="D",
|
||||||
letter_class=RESOLVE_POSTAGE_FOR_FILE_NAME[postage],
|
letter_class=RESOLVE_POSTAGE_FOR_FILE_NAME[postage],
|
||||||
colour="C",
|
colour="C",
|
||||||
crown="C" if crown else "N",
|
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()
|
).upper()
|
||||||
return upload_file_name
|
return upload_file_name
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ def upload_letter_pdf(notification, pdf_data, precompiled=False):
|
|||||||
upload_file_name = get_letter_pdf_filename(
|
upload_file_name = get_letter_pdf_filename(
|
||||||
reference=notification.reference,
|
reference=notification.reference,
|
||||||
crown=notification.service.crown,
|
crown=notification.service.crown,
|
||||||
sending_date=notification.created_at,
|
created_at=notification.created_at,
|
||||||
ignore_folder=precompiled or notification.key_type == KEY_TYPE_TEST,
|
ignore_folder=precompiled or notification.key_type == KEY_TYPE_TEST,
|
||||||
postage=notification.postage
|
postage=notification.postage
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ def send_pdf_letter_notification(service_id, post_data):
|
|||||||
upload_filename = get_letter_pdf_filename(
|
upload_filename = get_letter_pdf_filename(
|
||||||
reference=notification.reference,
|
reference=notification.reference,
|
||||||
crown=notification.service.crown,
|
crown=notification.service.crown,
|
||||||
sending_date=notification.created_at,
|
created_at=notification.created_at,
|
||||||
ignore_folder=False,
|
ignore_folder=False,
|
||||||
postage=notification.postage
|
postage=notification.postage
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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(
|
mock_get_letter_pdf_filename.assert_called_once_with(
|
||||||
reference=sample_letter_notification.reference,
|
reference=sample_letter_notification.reference,
|
||||||
crown=True,
|
crown=True,
|
||||||
sending_date=sample_letter_notification.created_at,
|
created_at=sample_letter_notification.created_at,
|
||||||
ignore_folder=False,
|
ignore_folder=False,
|
||||||
postage='second'
|
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):
|
with pytest.raises(expected_exception=NoResultFound):
|
||||||
get_pdf_for_templated_letter(fake_uuid)
|
get_pdf_for_templated_letter(fake_uuid)
|
||||||
|
|
||||||
|
|||||||
@@ -140,8 +140,8 @@ def test_get_bucket_name_and_prefix_for_notification_invalid_notification():
|
|||||||
])
|
])
|
||||||
def test_get_letter_pdf_filename_returns_correct_filename(
|
def test_get_letter_pdf_filename_returns_correct_filename(
|
||||||
notify_api, mocker, crown_flag, expected_crown_text):
|
notify_api, mocker, crown_flag, expected_crown_text):
|
||||||
sending_date = datetime(2017, 12, 4, 17, 29)
|
created_at = datetime(2017, 12, 4, 17, 29)
|
||||||
filename = get_letter_pdf_filename(reference='foo', crown=crown_flag, sending_date=sending_date)
|
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)
|
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(
|
def test_get_letter_pdf_filename_returns_correct_postage_for_filename(
|
||||||
notify_api, postage, expected_postage):
|
notify_api, postage, expected_postage):
|
||||||
sending_date = datetime(2017, 12, 4, 17, 29)
|
created_at = datetime(2017, 12, 4, 17, 29)
|
||||||
filename = get_letter_pdf_filename(reference='foo', crown=True, sending_date=sending_date, postage=postage)
|
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)
|
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(
|
def test_get_letter_pdf_filename_returns_correct_filename_for_test_letters(
|
||||||
notify_api, mocker):
|
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',
|
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'
|
assert filename == 'NOTIFY.FOO.D.2.C.C.20171204172900.PDF'
|
||||||
|
|
||||||
|
|
||||||
def test_get_letter_pdf_filename_returns_tomorrows_filename(notify_api, mocker):
|
def test_get_letter_pdf_filename_returns_tomorrows_filename(notify_api, mocker):
|
||||||
sending_date = datetime(2017, 12, 4, 17, 31)
|
created_at = datetime(2017, 12, 4, 17, 31)
|
||||||
filename = get_letter_pdf_filename(reference='foo', crown=True, sending_date=sending_date)
|
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'
|
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(
|
filename = get_letter_pdf_filename(
|
||||||
reference=sample_letter_notification.reference,
|
reference=sample_letter_notification.reference,
|
||||||
crown=sample_letter_notification.service.crown,
|
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
|
ignore_folder=is_precompiled_letter
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -243,7 +243,7 @@ def test_upload_letter_pdf_uses_postage_from_notification(
|
|||||||
filename = get_letter_pdf_filename(
|
filename = get_letter_pdf_filename(
|
||||||
reference=letter_notification.reference,
|
reference=letter_notification.reference,
|
||||||
crown=letter_notification.service.crown,
|
crown=letter_notification.service.crown,
|
||||||
sending_date=letter_notification.created_at,
|
created_at=letter_notification.created_at,
|
||||||
ignore_folder=False,
|
ignore_folder=False,
|
||||||
postage=letter_notification.postage
|
postage=letter_notification.postage
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user