Commit 40325c42 authored by Claude Paroz's avatar Claude Paroz

Add test for mail sent to coordinator

Thanks Grégoire Détrez for the initial patch (refs #753507).
Took advantage to modernize some code.
parent 578670d2
......@@ -23,6 +23,7 @@ from datetime import datetime, timedelta
from django.db import models
from django.core import mail
from django.utils import translation
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy, ugettext as _
from django.conf import settings
from django.contrib.sites.models import Site
......@@ -196,18 +197,16 @@ class Team(models.Model):
recipients = [pers.email for pers in self.get_coordinators() if pers.email]
if not recipients:
return
prev_lang = translation.get_language()
translation.activate(self.language_set.all()[0].locale)
message = u"%s\n--\n" % (message % messagekw,)
message += _(u"This is an automated message sent from %s.") % Site.objects.get_current()
mail.send_mail(
subject,
message,
settings.DEFAULT_FROM_EMAIL,
recipients
)
translation.activate(prev_lang)
with translation.override(self.language_set.all()[0].locale):
message = u"%s\n--\n" % (message % messagekw,)
message += _(u"This is an automated message sent from %s.") % Site.objects.get_current()
mail.send_mail(
force_text(subject),
message,
settings.DEFAULT_FROM_EMAIL,
recipients
)
class FakeTeam(object):
"""
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from datetime import datetime, timedelta
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.core import mail
from django.test import TestCase
from django.utils.translation import ugettext_lazy
from people.models import Person
from teams.models import Team, Role
from languages.models import Language
......@@ -39,11 +42,13 @@ class TeamsAndRolesTests(TestCase):
self.l = Language.objects.create(name='French', locale='fr', team=self.t)
_ = Role.objects.create(team=self.t, person=self.pt)
_ = Role.objects.create(team=self.t2, person=self.pt, role='reviewer')
_ = Role.objects.create(team=self.t, person=self.pr, role='reviewer')
_ = Role.objects.create(team=self.t, person=self.pc, role='committer')
_ = Role.objects.create(team=self.t, person=self.pcoo, role='coordinator')
Role.objects.bulk_create([
Role(team=self.t, person=self.pt),
Role(team=self.t2, person=self.pt, role='reviewer'),
Role(team=self.t, person=self.pr, role='reviewer'),
Role(team=self.t, person=self.pc, role='committer'),
Role(team=self.t, person=self.pcoo, role='coordinator'),
])
class TeamTest(TeamsAndRolesTests):
def setUp(self):
......@@ -143,7 +148,7 @@ class TeamTest(TeamsAndRolesTests):
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].recipients()[0], self.pcoo.email)
# Mail should be sent in the target team's language (i.e. French here)
self.assertTrue("rejoindre" in mail.outbox[0].body)
self.assertIn("rejoindre", mail.outbox[0].body)
def test_edit_team(self):
""" Test team edit form """
......@@ -162,6 +167,16 @@ class TeamTest(TeamsAndRolesTests):
team = Team.objects.get(name='fr')
self.assertEqual(team.webpage_url, "http://www.gnomefr.org/")
def test_send_mail_to_coordinator(self):
self.t.send_mail_to_coordinator(subject="foo", message="bar")
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, "foo")
# the message is sent in the language of the team
self.t.send_mail_to_coordinator(subject=ugettext_lazy("About Damned Lies"), message="...")
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(mail.outbox[1].subject, "À propos de Damned Lies")
class JSONTeamsTest(TeamsAndRolesTests):
def setUp(self):
super(JSONTeamsTest, self).setUp()
......
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