Commit f4ac3060 authored by Stéphane Raimbault's avatar Stéphane Raimbault

Fix #566802 - Send an email to coordinator when 'Ready for submission'

- add new functions to handle nested roles
- use get_committers() in Vertimus
- add many tests
parent 54cc577e
......@@ -145,6 +145,34 @@ class Team(models.Model):
def get_translators_exact(self):
return self.get_members_by_role_exact('translator')
def get_members_by_roles(self, roles):
"""Requires a list of roles in argument"""
try:
members = []
for role in roles:
members += self.roles[role]
except:
members = list(Person.objects.filter(role__team__id=self.id,
role__role__in=roles))
return members
def get_committers(self):
return self.get_members_by_roles(['coordinator', 'committer'])
def get_reviewers(self):
return self.get_members_by_roles(['coordinator', 'committer', 'reviewer'])
def get_translators(self):
"""Don't use get_members_by_roles to provide an optimization"""
try:
members = []
for role in ['coordinator', 'committer', 'reviewer', 'translator']:
members += self.roles[role]
except:
# Not necessary to filter as for other roles
members = list(self.members.all())
return members
class FakeTeam(object):
"""
This is a class replacing a Team object when a language
......
......@@ -50,16 +50,55 @@ class TeamTest(TestCase):
self.pn.delete()
self.t.delete()
def test_roles(self):
def run_roles_exact_test(self, team):
pcoo = team.get_coordinator()
self.assertEqual(pcoo, self.pcoo)
members = team.get_committers_exact()
self.assert_(len(members), 1)
self.assertEqual(members[0], self.pc)
members = team.get_reviewers_exact()
self.assert_(len(members), 1)
self.assertEqual(members[0], self.pr)
members = team.get_translators_exact()
self.assert_(len(members), 1)
self.assertEqual(members[0], self.pt)
def test_roles_exact(self):
self.run_roles_exact_test(self.t)
def test_roles_exact_prefilled_coordinator(self):
self.run_roles_exact_test(Team.objects.all_with_coordinator()[0])
def test_roles_exact_prefilled_all(self):
self.run_roles_exact_test(Team.objects.all_with_roles()[0])
def run_roles_test(self, team):
"""
Tests the hierarchy of roles
"""
people = self.t.get_coordinator()
self.assertEqual(people, self.pcoo)
members = team.get_committers()
self.assertEqual(len(members), 2)
for pc in members:
self.assert_(pc in [self.pcoo, self.pc])
team = Team.objects.all_with_coordinator()[0]
pcoo = team.get_coordinator()
self.assertEqual(pcoo, self.pcoo)
members = team.get_reviewers()
self.assertEqual(len(members), 3)
for pc in members:
self.assert_(pc in [self.pcoo, self.pc, self.pr])
members = team.get_translators()
self.assertEqual(len(members), 4)
for pc in members:
self.assert_(pc in [self.pcoo, self.pc, self.pr, self.pt])
def test_roles(self):
self.run_roles_test(self.t)
def test_roles_prefilled_coordinator(self):
self.run_roles_test(Team.objects.all_with_coordinator()[0])
list_pc = team.get_committers_exact()
self.assertEqual(list_pc[0], self.pc)
def test_roles_prefilled_all(self):
self.run_roles_test(Team.objects.all_with_roles()[0])
......@@ -653,7 +653,7 @@ class ActionTC(ActionAbstract):
new_state = self._new_state()
# Send an email to all committers of the team
committers = [c.email for c in state.language.team.get_committers_exact()]
committers = [c.email for c in state.language.team.get_committers()]
self.send_mail_new_state(state, new_state, committers)
return new_state
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment