Commits

Apostolis Bessas committed de47ce4

Allow minimum_perc and reviewed to be combined.

Comments (0)

Files changed (2)

txclib/project.py

                     'stats': stats,
                     'local_file': local_file,
                     'force': force,
+                    'mode': mode,
                 }
                 if not self._should_update_translation(**kwargs):
                     msg = "Skipping '%s' translation (file: %s)."
                         'stats': stats,
                         'local_file': local_file,
                         'force': force,
+                        'mode': mode,
                     }
                     if not self._should_push_translation(**kwargs):
                         msg = "Skipping '%s' translation (file: %s)."
         return raw
 
 
-    def _should_update_translation(self, lang, stats, local_file, force=False):
+    def _should_update_translation(self, lang, stats, local_file, force=False,
+                                   mode=None):
         """Whether a translation should be udpated from Transifex.
 
         We use the following criteria for that:
             stats: The (global) statistics object.
             local_file: The local translation file.
             force: A boolean flag.
+            mode: The mode for the translation.
         Returns:
             True or False.
         """
         return self._should_download(lang, stats, local_file, force)
 
-    def _should_add_translation(self, lang, stats, force=False):
+    def _should_add_translation(self, lang, stats, force=False, mode=None):
         """Whether a translation should be added from Transifex.
 
         We use the following criteria for that:
             lang: The language code to check.
             stats: The (global) statistics object.
             force: A boolean flag.
+            mode: The mode for the translation.
         Returns:
             True or False.
         """
         return self._should_download(lang, stats, None, force)
 
-    def _should_download(self, lang, stats, local_file=None, force=False):
+    def _should_download(self, lang, stats, local_file=None, force=False,
+                         mode=None):
         """Return whether a translation should be downloaded.
 
         If local_file is None, skip the timestamps check (the file does
             logger.debug("No lang %s in statistics" % lang)
             return False
 
-        satisfies_min = self._satisfies_min_translated(lang_stats)
+        satisfies_min = self._satisfies_min_translated(lang_stats, mode)
         if not satisfies_min:
             return False
 
             return None
         return time.mktime(time.gmtime(os.path.getmtime(path)))
 
-    def _satisfies_min_translated(self, stats):
+    def _satisfies_min_translated(self, stats, mode=None):
         """Check whether a translation fulfills the filter used for
         minimum translated percentage.
 
         Returns:
             True or False
         """
-        cur = self._extract_completed(stats)
+        cur = self._extract_completed(stats, mode)
         option_name = 'minimum_perc'
         if self.minimum_perc is not None:
             minimum_percent = self.minimum_perc
         return True
 
     @classmethod
-    def _extract_completed(cls, stats):
+    def _extract_completed(cls, stats, mode=None):
         """Extract the information for the translated percentage from the stats.
 
         Args:
             stats: The stats object for a language as returned by Transifex.
+            mode: The mode of translations requested.
         Returns:
             The percentage of translation as integer.
         """
+        if mode == 'reviewed':
+            key = 'reviewed'
+        else:
+            key = 'completed'
         try:
-            return int(stats['completed'][:-1])
+            return int(stats[key][:-1])
         except KeyError, e:
             return 0
 
     import json
 except ImportError:
     import simplejson as json
-from mock import patch
+from mock import Mock, patch
 from txclib.project import Project
 from txclib.config import Flipdict
 
             self.assertEquals('set', calls[0][0])
             self.assertEquals('set', calls[1][0])
 
+
+class TestStats(unittest.TestCase):
+    """Test the access to the stats objects."""
+
+    def setUp(self):
+        self.stats = Mock()
+        self.stats.__getitem__ = Mock()
+        self.stats.__getitem__.return_value = '12%'
+
+    def test_field_used_per_mode(self):
+        """Test the fields used for each mode."""
+        Project._extract_completed(self.stats, 'translate')
+        self.stats.__getitem__.assert_called_with('completed')
+        Project._extract_completed(self.stats, 'reviewed')
+        self.stats.__getitem__.assert_called_with('reviewed')
+