From 612f33e0143874ebed1381ecd868aba90c9cb670 Mon Sep 17 00:00:00 2001 From: Russ Housley Date: Tue, 8 Nov 2022 11:06:42 -0500 Subject: [PATCH] fix: Don't send I-D expiration warning if it will happen within 12 hours. (#4700) * fix: 4635 * fix: use timezone.now rather than datetime.datetime.now * chore: fix merge error Co-authored-by: Robert Sparks --- ietf/doc/expire.py | 7 +++++++ ietf/doc/tests_draft.py | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ietf/doc/expire.py b/ietf/doc/expire.py index 6d812adb4..9f82e699c 100644 --- a/ietf/doc/expire.py +++ b/ietf/doc/expire.py @@ -87,6 +87,13 @@ def send_expire_warning_for_draft(doc): return # don't warn about dead or inactive documents expiration = doc.expires.astimezone(DEADLINE_TZINFO).date() + now_plus_12hours = timezone.now() + datetime.timedelta(hours=12) + soon = now_plus_12hours.date() + if expiration <= soon: + # The document will expire very soon, which will send email to the + # same people, so do not send the warning at this point in time + return + (to,cc) = gather_address_lists('doc_expires_soon',doc=doc) diff --git a/ietf/doc/tests_draft.py b/ietf/doc/tests_draft.py index 518bff377..dc24cda9b 100644 --- a/ietf/doc/tests_draft.py +++ b/ietf/doc/tests_draft.py @@ -659,7 +659,7 @@ class ExpireIDsTests(DraftFileMixin, TestCase): self.assertEqual(len(list(get_soon_to_expire_drafts(14))), 0) - # hack into expirable state + # hack into expirable state to expire in 10 days draft.set_state(State.objects.get(type_id='draft-iesg',slug='idexists')) draft.expires = timezone.now() + datetime.timedelta(days=10) draft.save_with_history([DocEvent.objects.create(doc=draft, rev=draft.rev, type="changed_document", by=Person.objects.get(user__username="secretary"), desc="Test")]) @@ -675,8 +675,17 @@ class ExpireIDsTests(DraftFileMixin, TestCase): self.assertTrue('draft-ietf-mars-test@' in outbox[-1]['To']) # Gets the authors self.assertTrue('mars-chairs@ietf.org' in outbox[-1]['Cc']) self.assertTrue('aread@' in outbox[-1]['Cc']) + + # hack into expirable state to expire in 10 hours + draft.expires = timezone.now() + datetime.timedelta(hours=10) + draft.save_with_history([DocEvent.objects.create(doc=draft, rev=draft.rev, type="changed_document", by=Person.objects.get(user__username="secretary"), desc="Test")]) + + # test send warning is not sent for a document so close to expiration + mailbox_before = len(outbox) + send_expire_warning_for_draft(draft) + self.assertEqual(len(outbox), mailbox_before) - #Check that we don't sent expiration warnings for dead or replaced drafts + # Check that we don't sent expiration warnings for dead or replaced drafts old_state = draft.get_state_slug("draft-iesg") mailbox_before = len(outbox) draft.set_state(State.objects.get(type_id="draft-iesg",slug="dead"))