mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Merge pull request #3405 from alphagov/downgrade-delete-letter-log-180692253
Downgrade log for letter deletion exceptions
This commit is contained in:
@@ -428,9 +428,12 @@ def _delete_letters_from_s3(
|
||||
try:
|
||||
letter_pdf = find_letter_pdf_in_s3(letter)
|
||||
letter_pdf.delete()
|
||||
except (ClientError, LetterPDFNotFound):
|
||||
except ClientError:
|
||||
current_app.logger.exception(
|
||||
"Could not delete S3 object for letter: {}".format(letter.id))
|
||||
"Error deleting S3 object for letter: {}".format(letter.id))
|
||||
except LetterPDFNotFound:
|
||||
current_app.logger.warning(
|
||||
"No S3 object to delete for letter: {}".format(letter.id))
|
||||
|
||||
|
||||
@autocommit
|
||||
|
||||
@@ -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
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user