mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-15 15:28:02 -04:00
Merge pull request #2036 from alphagov/fix-deleted-count
Fix deleted count for logs and delete with letters that have not been sent
This commit is contained in:
@@ -334,7 +334,7 @@ def delete_notifications_created_more_than_a_week_ago_by_type(notification_type)
|
|||||||
services_with_data_retention))
|
services_with_data_retention))
|
||||||
if notification_type == LETTER_TYPE:
|
if notification_type == LETTER_TYPE:
|
||||||
_delete_letters_from_s3(query=query)
|
_delete_letters_from_s3(query=query)
|
||||||
deleted = query.delete(synchronize_session='fetch')
|
deleted += query.delete(synchronize_session='fetch')
|
||||||
return deleted
|
return deleted
|
||||||
|
|
||||||
|
|
||||||
@@ -342,6 +342,8 @@ def _delete_letters_from_s3(query):
|
|||||||
letters_to_delete_from_s3 = query.all()
|
letters_to_delete_from_s3 = query.all()
|
||||||
for letter in letters_to_delete_from_s3:
|
for letter in letters_to_delete_from_s3:
|
||||||
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
bucket_name = current_app.config['LETTERS_PDF_BUCKET_NAME']
|
||||||
|
# If the letter has not been sent there isn't a letter to delete from S3
|
||||||
|
if letter.sent_at:
|
||||||
sent_at = str(letter.sent_at.date())
|
sent_at = str(letter.sent_at.date())
|
||||||
prefix = LETTERS_PDF_FILE_LOCATION_STRUCTURE.format(
|
prefix = LETTERS_PDF_FILE_LOCATION_STRUCTURE.format(
|
||||||
folder=sent_at,
|
folder=sent_at,
|
||||||
|
|||||||
@@ -176,6 +176,16 @@ def test_delete_notifications_delete_notification_type_for_default_time_if_no_da
|
|||||||
assert len(Notification.query.filter_by(notification_type='email').all()) == 1
|
assert len(Notification.query.filter_by(notification_type='email').all()) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_delete_notifications_does_try_to_delete_from_s3_when_letter_has_not_been_sent(sample_service, mocker):
|
||||||
|
mock_get_s3 = mocker.patch("app.dao.notifications_dao.get_s3_object_by_prefix")
|
||||||
|
letter_template = create_template(service=sample_service, template_type='letter')
|
||||||
|
|
||||||
|
create_notification(template=letter_template, status='sending',
|
||||||
|
reference='LETTER_REF')
|
||||||
|
delete_notifications_created_more_than_a_week_ago_by_type('email')
|
||||||
|
mock_get_s3.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def _create_templates(sample_service):
|
def _create_templates(sample_service):
|
||||||
email_template = create_template(service=sample_service, template_type='email')
|
email_template = create_template(service=sample_service, template_type='email')
|
||||||
sms_template = create_template(service=sample_service)
|
sms_template = create_template(service=sample_service)
|
||||||
|
|||||||
Reference in New Issue
Block a user