Fix test that was passing unintentionally

This test was added in
ebb43082d5

However, there are a few problems with it

1. The test name doesn't seem to match what the code is doing. It looks
   like instead that it is NOT trying to delete from s3 when the letter
   has not been sent and therefore I've updated the test name as such.

2. `delete_notifications_older_than_retention_by_type` was being called
   with `email` as it's argument which doesn't match. This is a test for
   letters. It definitely wouldn't do any looking in s3 for emails.

3. `created_at` needed bumping back into the past, past the default 7
   days retention so these letters would be considered old enough to
   delete

4. For the letter to not be sent, it needs to be in `created`, not in
   `sending` so I have updated the status. Note, there could be other
   statuses which class as 'not sent' but this is the most obvious one
   to test with
This commit is contained in:
David McDonald
2020-12-15 09:48:08 +00:00
parent 34e8da7285
commit 219023f4c6

View File

@@ -212,13 +212,17 @@ def test_delete_notifications_delete_notification_type_for_default_time_if_no_da
assert Notification.query.filter_by(notification_type='email').count() == 1
def test_delete_notifications_does_try_to_delete_from_s3_when_letter_has_not_been_sent(sample_service, mocker):
def test_delete_notifications_doesnt_try_to_delete_from_s3_when_letter_has_not_sent(sample_service, mocker):
mock_get_s3 = mocker.patch("app.dao.notifications_dao.get_s3_bucket_objects")
letter_template = create_template(service=sample_service, template_type='letter')
create_notification(template=letter_template, status='sending',
reference='LETTER_REF')
delete_notifications_older_than_retention_by_type('email', qry_limit=1)
create_notification(
template=letter_template,
status='created',
reference='LETTER_REF',
created_at=datetime.utcnow() - timedelta(days=14)
)
delete_notifications_older_than_retention_by_type('letter', qry_limit=1)
mock_get_s3.assert_not_called()