[damned-lies] Fixed #156 - Fixed updating stats for PoFile objects



commit 89953f4a8d4236e3cd856c63e64fd1f842394fd1
Author: Claude Paroz <claude 2xlibre net>
Date:   Wed Sep 18 21:30:49 2019 +0200

    Fixed #156 - Fixed updating stats for PoFile objects

 stats/models.py      |  4 ++--
 stats/tests/tests.py | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 0497efc2..e24126d5 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -1217,7 +1217,7 @@ class PoFile(models.Model):
 
     @property
     def full_path(self):
-        return os.path.join(self.prefix, self.path)
+        return os.path.join(self.prefix, self.path.lstrip('/'))
 
     def filename(self):
         return os.path.basename(self.path)
@@ -1275,7 +1275,7 @@ class PoFile(models.Model):
             return int(100*self.untranslated_words/pot_size)
 
     def update_stats(self):
-        stats = utils.po_file_stats(Path(self.path))
+        stats = utils.po_file_stats(Path(self.full_path))
         self.translated   = stats['translated']
         self.fuzzy        = stats['fuzzy']
         self.untranslated = stats['untranslated']
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index c0fd51dc..f95e83fc 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -17,7 +17,7 @@ from django.test.utils import override_settings
 
 from common.utils import run_shell_command
 from stats.models import (
-    GLIB_PRESET, Module, Domain, Branch, Release, CategoryName, Statistics,
+    GLIB_PRESET, Module, Domain, Branch, Release, CategoryName, PoFile, Statistics,
     FakeLangStatistics, Information, UnableToCommit
 )
 from stats import utils
@@ -662,6 +662,18 @@ class StatisticsTests(TestCase):
         total_for_lang = rel.total_for_lang(Language.objects.get(locale='bem'))
         self.assertLess(total_for_lang['ui']['untranslated'], 183)
 
+    @test_scratchdir
+    def test_update_po_file(self):
+        stats = Statistics.objects.get(
+            branch__module__name='zenity', branch__name='gnome-3-8',
+            domain__name='po', language__locale='it'
+        )
+        stats.full_po = PoFile.objects.create(path='git/gnome-hello/po/it.po')
+        stats.save()
+        stats.full_po.update_stats()
+        self.assertEqual(stats.full_po.translated, 20)
+        self.assertEqual(stats.full_po.untranslated, 2)
+
     def test_stats_links(self):
         pot_stats = Statistics.objects.get(
             branch__module__name='zenity', branch__name='gnome-3-8',


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