From 219023f4c666a032850e8146edeaccb87284ae64 Mon Sep 17 00:00:00 2001 From: David McDonald Date: Tue, 15 Dec 2020 09:48:08 +0000 Subject: [PATCH] Fix test that was passing unintentionally This test was added in https://github.com/alphagov/notifications-api/commit/ebb43082d51b9f27b17190abb0537a710a544408 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 --- .../test_notification_dao_delete_notifications.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/app/dao/notification_dao/test_notification_dao_delete_notifications.py b/tests/app/dao/notification_dao/test_notification_dao_delete_notifications.py index 091826430..8d4a2fb71 100644 --- a/tests/app/dao/notification_dao/test_notification_dao_delete_notifications.py +++ b/tests/app/dao/notification_dao/test_notification_dao_delete_notifications.py @@ -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()