[damned-lies] Made 'Send to repository' option available for 'committing' state



commit 50a786b616b53ce0401a7cc319ed51de19928c38
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Mar 24 20:14:09 2014 +0100

    Made 'Send to repository' option available for 'committing' state
    
    Fixes bug #726934

 vertimus/models.py      |   10 +++++++---
 vertimus/tests/tests.py |   41 +++++++++++++++++++++++++++--------------
 2 files changed, 34 insertions(+), 17 deletions(-)
---
diff --git a/vertimus/models.py b/vertimus/models.py
index 415cf1a..c0069a3 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -220,9 +220,11 @@ class StateProofread(State):
             action_names = ['TC', 'RP', 'TR']
         else:
             action_names = []
-        if (not self.branch.is_vcs_readonly() and person.is_committer(self.language.team)
-                and self.get_latest_po_file_action() is not None):
-            action_names.insert(1, 'CI')
+        if person.is_committer(self.language.team):
+            action_names.append('RC')
+            if (not self.branch.is_vcs_readonly()
+                    and self.get_latest_po_file_action() is not None):
+                action_names.insert(1, 'CI')
 
         return self._get_available_actions(person, action_names)
 
@@ -273,6 +275,8 @@ class StateCommitting(State):
         if person.is_committer(self.language.team):
             if (self.person == person):
                 action_names = ['IC', 'TR', 'UNDO']
+            if not self.branch.is_vcs_readonly() and self.get_latest_po_file_action() is not None:
+                action_names.insert(0, 'CI')
 
         return self._get_available_actions(person, action_names)
 
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index 0438ac9..e864d15 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -63,7 +63,17 @@ class VertimusTest(TeamsAndRolesTests):
 
     def tearDown(self):
         for path in self.files_to_clean:
-            os.remove(path)
+            if os.path.exists(path):
+                os.remove(path)
+
+    def upload_file(self, to_state, action_code='UP'):
+        """ Test utility to add an uploaded file to a state """
+        test_file = ContentFile('test content')
+        test_file.name = 'mytestfile.po'
+        action = Action.new_by_name(action_code, person=self.pr, comment="Done.", file=test_file)
+        action.apply_on(to_state, {'send_to_ml': action.send_mail_to_ml})
+        self.files_to_clean.append(action.file.path)
+        return action.file
 
     def test_state_none(self):
         state = StateNone(branch=self.b, domain=self.d, language=self.l)
@@ -141,7 +151,7 @@ class VertimusTest(TeamsAndRolesTests):
 
         for p in (self.pc, self.pcoo):
             action_names = [a.name for a in state.get_available_actions(p)]
-            self.assertEqual(action_names, ['TC', 'RP', 'TR', 'WC', None, 'IC', 'AA'])
+            self.assertEqual(action_names, ['TC', 'RP', 'TR', 'RC', 'WC', None, 'IC', 'AA'])
 
     def test_state_to_review(self):
         state = StateToReview(branch=self.b, domain=self.d, language=self.l, person=self.pt)
@@ -169,7 +179,12 @@ class VertimusTest(TeamsAndRolesTests):
             self.assertEqual(action_names, ['RC', 'TR', 'UNDO', 'WC', None, 'IC', 'AA'])
 
     def test_state_committing(self):
-        state = StateCommitting(branch=self.b, domain=self.d, language=self.l, person=self.pc)
+        state = StateProofreading(branch=self.b, domain=self.d, language=self.l, person=self.pr)
+        state.save()
+        self.upload_file(state, 'UP')
+        action = Action.new_by_name('RC', person=self.pc, comment="Reserve the commit")
+        action.apply_on(state, {})
+        self.assertEqual(state.name, 'Committing')
 
         for p in (self.pn, self.pt, self.pr):
             action_names = [a.name for a in state.get_available_actions(p)]
@@ -181,6 +196,11 @@ class VertimusTest(TeamsAndRolesTests):
         action_names = [a.name for a in state.get_available_actions(self.pc)]
         self.assertEqual(action_names, ['IC', 'TR', 'UNDO', 'WC'])
 
+        self.b.module.vcs_root = self.b.module.vcs_root.replace('git://', 'ssh://')
+        self.b.module.save()
+        action_names = [a.name for a in state.get_available_actions(self.pcoo)]
+        self.assertEqual(action_names, ['CI', 'WC', 'UNDO', None, 'IC', 'AA'])
+
     def test_state_committed(self):
         state = StateCommitted(branch=self.b, domain=self.d, language=self.l, person=self.pc)
 
@@ -297,10 +317,7 @@ class VertimusTest(TeamsAndRolesTests):
         action = Action.new_by_name('WC', person=self.pt, comment="Hi!")
         action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
 
-        test_file = ContentFile('test content')
-        test_file.name = 'mytestfile.po'
-        action = Action.new_by_name('UP', person=self.pr, comment="Done.", file=test_file)
-        action.apply_on(state, {})
+        self.upload_file(state, 'UP')
 
         self.assertIn(ActionCI, map(type, state.get_available_actions(self.pcoo)))
 
@@ -316,16 +333,12 @@ class VertimusTest(TeamsAndRolesTests):
         state = StateProofreading(branch=self.b, domain=self.d, language=self.l, person=self.pr)
         state.save()
 
-        # Create a new file
-        test_file = ContentFile('test content')
-        test_file.name = 'mytestfile.po'
-
-        action = Action.new_by_name('UP', person=self.pr, comment="Done.", file=test_file)
-        action.apply_on(state, {'send_to_ml': action.send_mail_to_ml})
+        # Upload a new file
+        action_file = self.upload_file(state, 'UP')
         self.assertEqual(len(mail.outbox), 1) # Mail sent to mailing list
         mail.outbox = []
 
-        file_path = os.path.join(settings.MEDIA_ROOT, action.file.name)
+        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.")


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