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
This commit is contained in:
Henrik Levkowetz 2015-12-04 23:10:01 +00:00
parent 9b274111eb
commit d3c5609cde
2 changed files with 39 additions and 2 deletions

View file

@ -6,7 +6,10 @@ from django.core.urlresolvers import reverse as urlreverse
from django.db.models import Q
from django.test import Client
import debug # pyflakes:ignore
from ietf.group.models import Role, Group
from ietf.group.utils import get_group_role_emails, get_child_group_role_emails, get_group_ad_emails
from ietf.utils.test_data import make_test_data
from ietf.utils.test_utils import login_testing_unauthorized, TestCase, unicontent
@ -57,7 +60,7 @@ class StreamTests(TestCase):
@skipIf(skip_dot_to_pdf, skip_message)
class GroupTests(TestCase):
class GroupDocDependencyGraphTests(TestCase):
def test_group_document_dependency_dotfile(self):
make_test_data()
@ -85,3 +88,34 @@ class GroupTests(TestCase):
self.assertGreater(len(r.content), 0, "Pdf dependency graph for group "
"%s has no content"%group.acronym)
class GroupRoleEmailTests(TestCase):
def test_group_role_emails(self):
make_test_data()
wgs = Group.objects.filter(type='wg')
for wg in wgs:
chair_emails = get_group_role_emails(wg, ['chair'])
secr_emails = get_group_role_emails(wg, ['secr'])
self.assertIn("chairman", list(chair_emails)[0])
self.assertIn("secretary", list(secr_emails)[0])
both_emails = get_group_role_emails(wg, ['chair', 'secr'])
self.assertEqual(secr_emails | chair_emails, both_emails)
def test_child_group_role_emails(self):
make_test_data()
areas = Group.objects.filter(type='area')
for area in areas:
emails = get_child_group_role_emails(area, ['chair', 'secr'])
self.assertGreater(len(emails), 0)
for item in emails:
self.assertIn('@', item)
def test_group_ad_emails(self):
make_test_data()
wgs = Group.objects.filter(type='wg')
for wg in wgs:
emails = get_group_ad_emails(wg)
self.assertGreater(len(emails), 0)
for item in emails:
self.assertIn('@', item)

View file

@ -176,11 +176,14 @@ def make_test_data():
# group personnel
create_person(mars_wg, "chair", name="WG Cháir Man", username="marschairman")
create_person(mars_wg, "delegate", name="WG Dèlegate", username="marsdelegate")
create_person(mars_wg, "secr", name="Miss Secretary", username="marssecretary")
mars_wg.role_set.get_or_create(name_id='ad',person=ad,email=ad.role_email('ad'))
mars_wg.save()
create_person(ames_wg, "chair", name="WG Cháir Man", username="ameschairman")
create_person(ames_wg, "chair", name="Ames Chair Man", username="ameschairman")
create_person(ames_wg, "delegate", name="WG Dèlegate", username="amesdelegate")
create_person(ames_wg, "secr", name="Mr Secretary", username="amessecretary")
ames_wg.role_set.get_or_create(name_id='ad',person=ad,email=ad.role_email('ad'))
ames_wg.save()