Skip to content

Commit d3c5609

Browse files
committed
Added some tests for the group role email utility functions used by the alias generation scripts. Tempted to start using factory boy, but will wait till Robert's work in the nomcom branch comes in.
- Legacy-Id: 10544
1 parent 9b27411 commit d3c5609

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

ietf/group/tests.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
from django.db.models import Q
77
from django.test import Client
88

9+
import debug # pyflakes:ignore
10+
911
from ietf.group.models import Role, Group
12+
from ietf.group.utils import get_group_role_emails, get_child_group_role_emails, get_group_ad_emails
1013
from ietf.utils.test_data import make_test_data
1114
from ietf.utils.test_utils import login_testing_unauthorized, TestCase, unicontent
1215

@@ -57,7 +60,7 @@ def test_stream_edit(self):
5760

5861

5962
@skipIf(skip_dot_to_pdf, skip_message)
60-
class GroupTests(TestCase):
63+
class GroupDocDependencyGraphTests(TestCase):
6164

6265
def test_group_document_dependency_dotfile(self):
6366
make_test_data()
@@ -85,3 +88,34 @@ def test_group_document_dependency_pdffile(self):
8588
self.assertGreater(len(r.content), 0, "Pdf dependency graph for group "
8689
"%s has no content"%group.acronym)
8790

91+
92+
class GroupRoleEmailTests(TestCase):
93+
94+
def test_group_role_emails(self):
95+
make_test_data()
96+
wgs = Group.objects.filter(type='wg')
97+
for wg in wgs:
98+
chair_emails = get_group_role_emails(wg, ['chair'])
99+
secr_emails = get_group_role_emails(wg, ['secr'])
100+
self.assertIn("chairman", list(chair_emails)[0])
101+
self.assertIn("secretary", list(secr_emails)[0])
102+
both_emails = get_group_role_emails(wg, ['chair', 'secr'])
103+
self.assertEqual(secr_emails | chair_emails, both_emails)
104+
105+
def test_child_group_role_emails(self):
106+
make_test_data()
107+
areas = Group.objects.filter(type='area')
108+
for area in areas:
109+
emails = get_child_group_role_emails(area, ['chair', 'secr'])
110+
self.assertGreater(len(emails), 0)
111+
for item in emails:
112+
self.assertIn('@', item)
113+
114+
def test_group_ad_emails(self):
115+
make_test_data()
116+
wgs = Group.objects.filter(type='wg')
117+
for wg in wgs:
118+
emails = get_group_ad_emails(wg)
119+
self.assertGreater(len(emails), 0)
120+
for item in emails:
121+
self.assertIn('@', item)

ietf/utils/test_data.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,14 @@ def make_test_data():
176176
# group personnel
177177
create_person(mars_wg, "chair", name="WG Cháir Man", username="marschairman")
178178
create_person(mars_wg, "delegate", name="WG Dèlegate", username="marsdelegate")
179+
create_person(mars_wg, "secr", name="Miss Secretary", username="marssecretary")
180+
179181
mars_wg.role_set.get_or_create(name_id='ad',person=ad,email=ad.role_email('ad'))
180182
mars_wg.save()
181183

182-
create_person(ames_wg, "chair", name="WG Cháir Man", username="ameschairman")
184+
create_person(ames_wg, "chair", name="Ames Chair Man", username="ameschairman")
183185
create_person(ames_wg, "delegate", name="WG Dèlegate", username="amesdelegate")
186+
create_person(ames_wg, "secr", name="Mr Secretary", username="amessecretary")
184187
ames_wg.role_set.get_or_create(name_id='ad',person=ad,email=ad.role_email('ad'))
185188
ames_wg.save()
186189

0 commit comments

Comments
 (0)