rename letter get_folder_name args

`_now`? why would we ever use a different _now? instead say created_at,
because that's what it'll always be set to, even if we're replaying old
letters. We always set the folder name to when the letter was
created_at, or we might not know where to look to find it.

`dont_use_sending_date` doesn't really tell us what might happen if we
don't use it - the answer is we return an empty string. we ignore the
folder entirely. so lets call it that.

Also, remove use of freeze_gun in the tests, to prove that we don't use
the current time in any calculations. Also add an assert to a mock in
the get_pdf_for_templated_letter test, because we were mocking but not
asserting before, so the tests didn't fail when the function signature
changed.
This commit is contained in:
Leo Hemsted
2020-09-21 13:46:31 +01:00
parent 120b760cae
commit bb33927b3d
6 changed files with 33 additions and 23 deletions

View File

@@ -27,20 +27,20 @@ LETTERS_PDF_FILE_LOCATION_STRUCTURE = \
PRECOMPILED_BUCKET_PREFIX = '{folder}NOTIFY.{reference}'
def get_folder_name(_now, *, dont_use_sending_date=False):
if dont_use_sending_date:
def get_folder_name(created_at, *, ignore_folder=False):
if ignore_folder:
folder_name = ''
else:
print_datetime = convert_utc_to_bst(_now)
print_datetime = convert_utc_to_bst(created_at)
if print_datetime.time() > LETTER_PROCESSING_DEADLINE:
print_datetime += timedelta(days=1)
folder_name = '{}/'.format(print_datetime.date())
return folder_name
def get_letter_pdf_filename(reference, crown, sending_date, dont_use_sending_date=False, postage=SECOND_CLASS):
def get_letter_pdf_filename(reference, crown, sending_date, ignore_folder=False, postage=SECOND_CLASS):
upload_file_name = LETTERS_PDF_FILE_LOCATION_STRUCTURE.format(
folder=get_folder_name(sending_date, dont_use_sending_date=dont_use_sending_date),
folder=get_folder_name(sending_date, ignore_folder=ignore_folder),
reference=reference,
duplex="D",
letter_class=RESOLVE_POSTAGE_FOR_FILE_NAME[postage],
@@ -59,7 +59,7 @@ def get_bucket_name_and_prefix_for_notification(notification):
bucket_name = current_app.config['TEST_LETTERS_BUCKET_NAME']
else:
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
folder = get_folder_name(notification.created_at, dont_use_sending_date=False)
folder = get_folder_name(notification.created_at, ignore_folder=False)
upload_file_name = PRECOMPILED_BUCKET_PREFIX.format(
folder=folder,
@@ -83,7 +83,7 @@ def upload_letter_pdf(notification, pdf_data, precompiled=False):
reference=notification.reference,
crown=notification.service.crown,
sending_date=notification.created_at,
dont_use_sending_date=precompiled or notification.key_type == KEY_TYPE_TEST,
ignore_folder=precompiled or notification.key_type == KEY_TYPE_TEST,
postage=notification.postage
)
@@ -151,7 +151,7 @@ def move_uploaded_pdf_to_letters_bucket(source_filename, upload_filename):
def move_sanitised_letter_to_test_or_live_pdf_bucket(filename, is_test_letter, created_at, new_filename):
target_bucket_config = 'TEST_LETTERS_BUCKET_NAME' if is_test_letter else 'LETTERS_PDF_BUCKET_NAME'
target_bucket_name = current_app.config[target_bucket_config]
target_filename = get_folder_name(created_at, dont_use_sending_date=is_test_letter) + new_filename
target_filename = get_folder_name(created_at, ignore_folder=is_test_letter) + new_filename
_move_s3_object(
source_bucket=current_app.config['LETTER_SANITISE_BUCKET_NAME'],