mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Merge pull request #1303 from alphagov/ken-purge-noti-to-email_reply_to
Purge notifications to email reply to rows older than 7 days
This commit is contained in:
@@ -8,19 +8,21 @@ from sqlalchemy.exc import SQLAlchemyError, IntegrityError
|
||||
|
||||
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_service_id
|
||||
from app.models import (
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
Job,
|
||||
Notification,
|
||||
NotificationEmailReplyTo,
|
||||
NotificationHistory,
|
||||
NotificationStatistics,
|
||||
ScheduledNotification,
|
||||
ServiceEmailReplyTo,
|
||||
EMAIL_TYPE,
|
||||
NOTIFICATION_STATUS_TYPES,
|
||||
NOTIFICATION_STATUS_TYPES_FAILED,
|
||||
NOTIFICATION_SENT,
|
||||
NOTIFICATION_DELIVERED,
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
KEY_TYPE_TEST,
|
||||
KEY_TYPE_TEST
|
||||
)
|
||||
|
||||
from app.dao.notifications_dao import (
|
||||
@@ -28,9 +30,9 @@ from app.dao.notifications_dao import (
|
||||
dao_create_notification_email_reply_to_mapping,
|
||||
dao_created_scheduled_notification,
|
||||
dao_delete_notifications_and_history_by_id,
|
||||
dao_get_notifications_by_to_field,
|
||||
dao_get_last_template_usage,
|
||||
dao_get_notification_email_reply_for_notification,
|
||||
dao_get_notifications_by_to_field,
|
||||
dao_get_notification_statistics_for_service_and_day,
|
||||
dao_get_potential_notification_statistics_for_day,
|
||||
dao_get_scheduled_notifications,
|
||||
@@ -1005,6 +1007,41 @@ def test_should_delete_notifications_by_type_after_seven_days(
|
||||
assert notification.created_at.date() >= date(2016, 1, 3)
|
||||
|
||||
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_should_delete_notification_to_email_reply_to_after_seven_days(
|
||||
notify_db, notify_db_session, sample_service,
|
||||
):
|
||||
assert len(Notification.query.all()) == 0
|
||||
|
||||
reply_to = create_reply_to_email(sample_service, 'test@example.com')
|
||||
|
||||
email_template = sample_email_template(notify_db, notify_db_session, service=sample_service)
|
||||
|
||||
# create one notification a day between 1st and 10th from 11:00 to 19:00 of each type
|
||||
for i in range(1, 11):
|
||||
past_date = '2016-01-{0:02d} {0:02d}:00:00.000000'.format(i)
|
||||
with freeze_time(past_date):
|
||||
notification = create_notification(email_template)
|
||||
dao_create_notification_email_reply_to_mapping(notification.id, reply_to.id)
|
||||
|
||||
all_notifications = Notification.query.all()
|
||||
assert len(all_notifications) == 10
|
||||
|
||||
all_notification_email_reply_to = NotificationEmailReplyTo.query.all()
|
||||
assert len(all_notification_email_reply_to) == 10
|
||||
|
||||
# Records before 3rd should be deleted
|
||||
delete_notifications_created_more_than_a_week_ago_by_type(EMAIL_TYPE)
|
||||
remaining_email_notifications = Notification.query.filter_by(notification_type=EMAIL_TYPE).all()
|
||||
remaining_notification_to_email_reply_to = NotificationEmailReplyTo.query.filter_by().all()
|
||||
|
||||
assert len(remaining_email_notifications) == 8
|
||||
assert len(remaining_notification_to_email_reply_to) == 8
|
||||
|
||||
for notification in remaining_email_notifications:
|
||||
assert notification.created_at.date() >= date(2016, 1, 3)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('notification_type', ['sms', 'email', 'letter'])
|
||||
@freeze_time("2016-01-10 12:00:00.000000")
|
||||
def test_should_not_delete_notification_history(notify_db, notify_db_session, sample_service, notification_type):
|
||||
@@ -1992,7 +2029,7 @@ def test_dao_create_multiple_notification_email_reply_to_mapping(sample_service,
|
||||
assert email_reply_to[0].service_email_reply_to_id == reply_to_address.id
|
||||
|
||||
|
||||
def test_dao_get_notification_ememail_reply_toail_reply_for_notification(sample_service, sample_notification):
|
||||
def test_dao_get_notification_email_reply_for_notification(sample_service, sample_notification):
|
||||
reply_to_address = create_reply_to_email(sample_service, "test@test.com")
|
||||
dao_create_notification_email_reply_to_mapping(sample_notification.id, reply_to_address.id)
|
||||
assert dao_get_notification_email_reply_for_notification(sample_notification.id) == "test@test.com"
|
||||
|
||||
Reference in New Issue
Block a user