Skip to content

Commit

Permalink
test: Test DraftAliasGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-richards committed Feb 6, 2024
1 parent cec54d5 commit 2d2353c
Showing 1 changed file with 98 additions and 1 deletion.
99 changes: 98 additions & 1 deletion ietf/doc/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
StatusChangeFactory, DocExtResourceFactory, RgDraftFactory, BcpFactory)
from ietf.doc.forms import NotifyForm
from ietf.doc.fields import SearchableDocumentsField
from ietf.doc.utils import create_ballot_if_not_open, uppercase_std_abbreviated_name
from ietf.doc.utils import create_ballot_if_not_open, uppercase_std_abbreviated_name, DraftAliasGenerator
from ietf.group.models import Group, Role
from ietf.group.factories import GroupFactory, RoleFactory
from ietf.ipr.factories import HolderIprDisclosureFactory
Expand Down Expand Up @@ -2291,6 +2291,7 @@ def testManagementCommand(self):
"xfilter-" + doc3.name + ".ad",
"xfilter-" + doc3.name + ".authors",
"xfilter-" + doc3.name + ".chairs",
"xfilter-" + doc3.name + ".all",
"xfilter-" + doc5.name,
"xfilter-" + doc5.name + ".authors",
"xfilter-" + doc5.name + ".all",
Expand All @@ -2307,6 +2308,102 @@ def testManagementCommand(self):
]:
self.assertNotIn(x, vcontent)

def test_generator_class(self):
"""The DraftAliasGenerator should generate the same lists as the old mgmt cmd"""
a_month_ago = (timezone.now() - datetime.timedelta(30)).astimezone(RPC_TZINFO)
a_month_ago = a_month_ago.replace(hour=0, minute=0, second=0, microsecond=0)
ad = RoleFactory(
name_id="ad", group__type_id="area", group__state_id="active"
).person
shepherd = PersonFactory()
author1 = PersonFactory()
author2 = PersonFactory()
author3 = PersonFactory()
author4 = PersonFactory()
author5 = PersonFactory()
author6 = PersonFactory()
mars = GroupFactory(type_id="wg", acronym="mars")
marschairman = PersonFactory(user__username="marschairman")
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 = 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)
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)
doc5 = IndividualDraftFactory(authors=[author6])

output = [(alias, alist) for alias, alist in DraftAliasGenerator()]
alias_dict = dict(output)
self.assertEqual(len(alias_dict), len(output)) # no duplicate aliases
expected_dict = {
doc1.name: [author1.email_address()],
doc1.name + ".ad": [ad.email_address()],
doc1.name + ".authors": [author1.email_address()],
doc1.name + ".shepherd": [shepherd.email_address()],
doc1.name
+ ".all": [
author1.email_address(),
ad.email_address(),
shepherd.email_address(),
],
doc2.name: [author2.email_address()],
doc2.name + ".ad": [ad.email_address()],
doc2.name + ".authors": [author2.email_address()],
doc2.name + ".chairs": [marschairman.email_address()],
doc2.name
+ ".all": [
author2.email_address(),
ad.email_address(),
marschairman.email_address(),
],
doc3.name: [author3.email_address()],
doc3.name + ".ad": [ad.email_address()],
doc3.name + ".authors": [author3.email_address()],
doc3.name + ".chairs": [marschairman.email_address()],
doc3.name
+ ".all": [
author3.email_address(),
ad.email_address(),
marschairman.email_address(),
],
doc5.name: [author6.email_address()],
doc5.name + ".authors": [author6.email_address()],
doc5.name + ".all": [author6.email_address()],
}
# Sort lists for comparison
self.assertEqual(
{k: sorted(v) for k, v in alias_dict.items()},
{k: sorted(v) for k, v in expected_dict.items()},
)


class EmailAliasesTests(TestCase):

def setUp(self):
Expand Down

0 comments on commit 2d2353c

Please sign in to comment.