[damned-lies] [vertimus] Fix mail not sent to mailing list when committing



commit 7763323ce66808971a41553dae61657b9ffd87c1
Author: Claude Paroz <claude 2xlibre net>
Date:   Sun May 22 21:45:42 2011 +0200

    [vertimus] Fix mail not sent to mailing list when committing

 teams/tests.py             |    2 +-
 vertimus/models.py         |    8 ++------
 vertimus/tests/__init__.py |    9 +++++++++
 3 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/teams/tests.py b/teams/tests.py
index 4a379c8..21d029d 100644
--- a/teams/tests.py
+++ b/teams/tests.py
@@ -37,7 +37,7 @@ class TeamsAndRolesTests(TestCase):
         self.pcoo.set_password('password')
         self.pcoo.save()
 
-        self.t = Team(name='fr', description='French', mailing_list='nowhere example org')
+        self.t = Team(name='fr', description='French', mailing_list='french_ml example org')
         self.t.save()
 
         self.t2 = Team(name='pt', description='Portuguese')
diff --git a/vertimus/models.py b/vertimus/models.py
index d35d179..b3a4d39 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -417,6 +417,7 @@ class Action(ActionAbstract):
             # All actions change state except Writing a comment
             self.state_db.change_state(self.target_state, self.person)
             if self.target_state == StateCommitted:
+                self.send_mail_new_state(state, (state.language.team.mailing_list,))
                 # Committed is the last state of the workflow, archive actions
                 arch_action = self.new_by_name('AA', person=self.person)
                 arch_action.apply_on(self.state_db)
@@ -627,8 +628,7 @@ class ActionCI(Action):
             # FIXME: somewhere the error should be catched and handled properly
             raise Exception(_("The commit failed. The error was: '%s'") % sys.exc_info()[1])
 
-        super(ActionCI, self).apply_on(state)
-        self.send_mail_new_state(state, (state.language.team.mailing_list,))
+        super(ActionCI, self).apply_on(state) # Mail sent in super
 
 class ActionRC(Action):
     name = 'RC'
@@ -645,10 +645,6 @@ class ActionIC(Action):
     class Meta:
         proxy = True
 
-    def apply(self, state):
-        super(ActionIC, self).apply_on(state)
-        self.send_mail_new_state(state, (state.language.team.mailing_list,))
-
 class ActionTR(Action):
     name = 'TR'
     target_state = StateToReview
diff --git a/vertimus/tests/__init__.py b/vertimus/tests/__init__.py
index f8a119b..620edb6 100644
--- a/vertimus/tests/__init__.py
+++ b/vertimus/tests/__init__.py
@@ -273,19 +273,28 @@ class VertimusTest(TeamsAndRolesTests):
 
         action = Action.new_by_name('UP', person=self.pr, comment="Done.", file=test_file)
         action.apply_on(state)
+        self.assertEquals(len(mail.outbox), 1) # Mail sent to mailing list
+        mail.outbox = []
 
         file_path = os.path.join(settings.MEDIA_ROOT, action.file.name)
         self.assertTrue(os.access(file_path, os.W_OK))
 
         action = Action.new_by_name('TC', person=self.pc, comment="To commit.")
         action.apply_on(state)
+        self.assertEquals(len(mail.outbox), 1) # Mail sent to committers
+        mail.outbox = []
 
         action = Action.new_by_name('RC', person=self.pc, comment="Reserved commit.")
         action.apply_on(state)
 
         action = Action.new_by_name('IC', person=self.pc, comment="Committed.")
         action.apply_on(state)
+        # Mail sent to mailing list
+        self.assertEquals(len(mail.outbox), 1)
+        self.assertEquals(mail.outbox[0].recipients(), [self.l.team.mailing_list])
+        self.assertTrue(u'Commité' in mail.outbox[0].body) # Team is French
 
+        self.assertTrue(isinstance(state, StateNone))
         self.assertTrue(not os.access(file_path, os.F_OK), "%s not deleted" % file_path)
 
         # Remove test file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]