From 78b6f06519e90c3c6b5330ec78747dfb421f43f2 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Fri, 7 Jul 2023 13:47:50 -0500 Subject: [PATCH] fix: repair generate_draft_aliases --- .../commands/generate_draft_aliases.py | 12 +++-- ietf/doc/tests.py | 46 ++++++++++++------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/ietf/doc/management/commands/generate_draft_aliases.py b/ietf/doc/management/commands/generate_draft_aliases.py index 88f4aa98c..9d62cf527 100755 --- a/ietf/doc/management/commands/generate_draft_aliases.py +++ b/ietf/doc/management/commands/generate_draft_aliases.py @@ -24,6 +24,7 @@ from ietf.doc.models import Document from ietf.group.utils import get_group_role_emails, get_group_ad_emails from ietf.utils.aliases import dump_sublist from utils.mail import parseaddr +from ietf.utils import log DEFAULT_YEARS = 2 @@ -120,16 +121,19 @@ class Command(BaseCommand): vfile.write("%s anything\n" % settings.DRAFT_VIRTUAL_DOMAIN) # Internet-Drafts with active status or expired within DEFAULT_YEARS - drafts = Document.objects.filter(name__startswith='draft-') + drafts = Document.objects.filter(type_id="draft") active_drafts = drafts.filter(states__slug='active') inactive_recent_drafts = drafts.exclude(states__slug='active').filter(expires__gte=show_since) interesting_drafts = active_drafts | inactive_recent_drafts alias_domains = ['ietf.org', ] for draft in interesting_drafts.distinct().iterator(): - # Omit RFCs, unless they were published in the last DEFAULT_YEARS - if draft.docalias.filter(name__startswith='rfc'): - if draft.latest_event(type='published_rfc').time < show_since: + # Omit drafts that became RFCs, unless they were published in the last DEFAULT_YEARS + if draft.get_state_slug()=="rfc": + rfc_alias = next(iter(draft.related_that_doc("became_rfc")), None) + log.assertion("rfc_alias is not None") + rfc = rfc_alias.document + if rfc.latest_event(type='published_rfc').time < show_since: continue alias = draft.name diff --git a/ietf/doc/tests.py b/ietf/doc/tests.py index fa9213da0..3db154ec4 100644 --- a/ietf/doc/tests.py +++ b/ietf/doc/tests.py @@ -2079,10 +2079,14 @@ class GenerateDraftAliasesTests(TestCase): mars.role_set.create(name_id='chair', person=marschairman, email=marschairman.email()) doc1 = IndividualDraftFactory(authors=[author1], shepherd=shepherd.email(), ad=ad) doc2 = WgDraftFactory(name='draft-ietf-mars-test', group__acronym='mars', authors=[author2], ad=ad) - doc3 = WgRfcFactory.create(name='draft-ietf-mars-finished', group__acronym='mars', authors=[author3], ad=ad, std_level_id='ps', states=[('draft','rfc'),('draft-iesg','pub')], time=a_month_ago) - DocEventFactory.create(doc=doc3, type='published_rfc', time=a_month_ago) - doc4 = WgRfcFactory.create(authors=[author4,author5], ad=ad, std_level_id='ps', states=[('draft','rfc'),('draft-iesg','pub')], time=datetime.datetime(2010,10,10, tzinfo=ZoneInfo(settings.TIME_ZONE))) - DocEventFactory.create(doc=doc4, type='published_rfc', time=datetime.datetime(2010, 10, 10, tzinfo=RPC_TZINFO)) + doc3 = WgDraftFactory.create(name='draft-ietf-mars-finished', group__acronym='mars', authors=[author3], ad=ad, std_level_id='ps', states=[('draft','rfc'),('draft-iesg','pub')], time=a_month_ago) + rfc3 = WgRfcFactory() + DocEventFactory.create(doc=rfc3, type='published_rfc', time=a_month_ago) + doc3.relateddocument_set.create(relationship_id="became_rfc", target=rfc3.docalias.first()) + doc4 = WgDraftFactory.create(authors=[author4,author5], ad=ad, std_level_id='ps', states=[('draft','rfc'),('draft-iesg','pub')], time=datetime.datetime(2010,10,10, tzinfo=ZoneInfo(settings.TIME_ZONE))) + rfc4 = WgRfcFactory() + DocEventFactory.create(doc=rfc4, type='published_rfc', time=datetime.datetime(2010, 10, 10, tzinfo=RPC_TZINFO)) + doc4.relateddocument_set.create(relationship_id="became_rfc", target=rfc4.docalias.first()) doc5 = IndividualDraftFactory(authors=[author6]) args = [ ] @@ -2093,7 +2097,7 @@ class GenerateDraftAliasesTests(TestCase): with open(settings.DRAFT_ALIASES_PATH) as afile: acontent = afile.read() - self.assertTrue(all([x in acontent for x in [ + for x in [ 'xfilter-' + doc1.name, 'xfilter-' + doc1.name + '.ad', 'xfilter-' + doc1.name + '.authors', @@ -2111,19 +2115,22 @@ class GenerateDraftAliasesTests(TestCase): 'xfilter-' + doc5.name, 'xfilter-' + doc5.name + '.authors', 'xfilter-' + doc5.name + '.all', - ]])) - self.assertFalse(all([x in acontent for x in [ + ]: + self.assertIn(x, acontent) + + for x in [ 'xfilter-' + doc1.name + '.chairs', 'xfilter-' + doc2.name + '.shepherd', 'xfilter-' + doc3.name + '.shepherd', 'xfilter-' + doc4.name, 'xfilter-' + doc5.name + '.shepherd', 'xfilter-' + doc5.name + '.ad', - ]])) + ]: + self.assertNotIn(x, acontent) with open(settings.DRAFT_VIRTUAL_PATH) as vfile: vcontent = vfile.read() - self.assertTrue(all([x in vcontent for x in [ + for x in [ ad.email_address(), shepherd.email_address(), marschairman.email_address(), @@ -2131,12 +2138,16 @@ class GenerateDraftAliasesTests(TestCase): author2.email_address(), author3.email_address(), author6.email_address(), - ]])) - self.assertFalse(all([x in vcontent for x in [ + ]: + self.assertIn(x, vcontent) + + for x in [ author4.email_address(), author5.email_address(), - ]])) - self.assertTrue(all([x in vcontent for x in [ + ]: + self.assertNotIn(x, vcontent) + + for x in [ 'xfilter-' + doc1.name, 'xfilter-' + doc1.name + '.ad', 'xfilter-' + doc1.name + '.authors', @@ -2154,15 +2165,18 @@ class GenerateDraftAliasesTests(TestCase): 'xfilter-' + doc5.name, 'xfilter-' + doc5.name + '.authors', 'xfilter-' + doc5.name + '.all', - ]])) - self.assertFalse(all([x in vcontent for x in [ + ]: + self.assertIn(x, vcontent) + + for x in [ 'xfilter-' + doc1.name + '.chairs', 'xfilter-' + doc2.name + '.shepherd', 'xfilter-' + doc3.name + '.shepherd', 'xfilter-' + doc4.name, 'xfilter-' + doc5.name + '.shepherd', 'xfilter-' + doc5.name + '.ad', - ]])) + ]: + self.assertNotIn(x, vcontent) class EmailAliasesTests(TestCase):