Downgrade log for letter deletion exceptions

If the S3 object is missing [1], then that's what we want, so we
don't need such a severe log for it, but we still want to know as
it's not expected. This is separate to more general "ClientError"
exceptions, which could mean anything.

There weren't any tests to cover missing S3 objects, so I've added
one. I don't think we need a test for ClientErrors:

- If there was no handler, the task would fail and we'd learn about
it that way.

- The scope of the calling task is now much smaller, so it matters
less than it used to [2].

[1]: 81a79e56ce/app/letters/utils.py (L52)
[2]: f965322f25
This commit is contained in:
Ben Thorner
2021-12-20 12:05:53 +00:00
parent 81a79e56ce
commit de9ae08ecc
2 changed files with 22 additions and 2 deletions

View File

@@ -51,6 +51,23 @@ def test_move_notifications_deletes_letters_from_s3(sample_letter_template, mock
s3.get_object(Bucket=bucket_name, Key=filename)
@mock_s3
@freeze_time('2019-09-01 04:30')
def test_move_notifications_copes_if_letter_not_in_s3(sample_letter_template, mocker):
s3 = boto3.client('s3', region_name='eu-west-1')
s3.create_bucket(
Bucket=current_app.config['LETTERS_PDF_BUCKET_NAME'],
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)
eight_days_ago = datetime.utcnow() - timedelta(days=8)
create_notification(template=sample_letter_template, status='delivered', sent_at=eight_days_ago)
move_notifications_to_notification_history('letter', sample_letter_template.service_id, datetime(2020, 1, 2))
assert Notification.query.count() == 0
assert NotificationHistory.query.count() == 1
def test_move_notifications_does_nothing_if_notification_history_row_already_exists(
sample_email_template, mocker
):