launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24793
[Merge] ~pappacena/launchpad:update-stats-on-translation-copy into launchpad:master
Thiago F. Pappacena has proposed merging ~pappacena/launchpad:update-stats-on-translation-copy into launchpad:master.
Commit message:
Scheduling to run statistics update on PO and POT files when we copy translations.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1877624 in Launchpad itself: "Migrated imported translations don't trigger updates of the summary page"
https://bugs.launchpad.net/launchpad/+bug/1877624
For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/383669
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:update-stats-on-translation-copy into launchpad:master.
diff --git a/lib/lp/translations/utilities/tests/test_file_importer.py b/lib/lp/translations/utilities/tests/test_file_importer.py
index 013d13f..939b742 100644
--- a/lib/lp/translations/utilities/tests/test_file_importer.py
+++ b/lib/lp/translations/utilities/tests/test_file_importer.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Translation File Importer tests."""
@@ -12,13 +12,20 @@ from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
from lp.registry.interfaces.person import IPersonSet
+from lp.services.config import config
+from lp.services.job.runner import JobRunner
from lp.services.librarianserver.testing.fake import FakeLibrarian
-from lp.testing import TestCaseWithFactory
+from lp.testing import (
+ admin_logged_in,
+ TestCaseWithFactory,
+ )
+from lp.testing.dbuser import dbuser
from lp.testing.layers import (
LaunchpadZopelessLayer,
ZopelessDatabaseLayer,
)
from lp.translations.enums import TranslationPermission
+from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource
from lp.translations.interfaces.potemplate import IPOTemplateSet
from lp.translations.interfaces.side import TranslationSide
from lp.translations.interfaces.translationfileformat import (
@@ -395,6 +402,23 @@ class FileImporterTestCase(TestCaseWithFactory):
"POFileImporter.importFile did not create an "
"ITranslationMessage object in the database.")
+ # Checks if statistics update was scheduled correctly.
+ with admin_logged_in():
+ self.assertEqual(0, po_importer.pofile.translatedCount())
+ self.assertEqual(0, po_importer.pofile.untranslatedCount())
+ self.assertEqual(0, pot_importer.potemplate.translatedCount())
+ self.assertEqual(0, pot_importer.potemplate.untranslatedCount())
+
+ jobs = getUtility(IPOFileStatsJobSource).iterReady()
+ self.assertGreaterEqual(jobs.count(), 2)
+ with dbuser(config.IPOFileStatsJobSource.dbuser):
+ JobRunner(jobs).runAll()
+
+ self.assertEqual(1, po_importer.pofile.translatedCount())
+ self.assertEqual(0, po_importer.pofile.untranslatedCount())
+ self.assertEqual(0, pot_importer.potemplate.translatedCount())
+ self.assertEqual(1, pot_importer.potemplate.untranslatedCount())
+
def test_FileImporter_importFile_conflict(self):
(pot_importer, po_importer) = (
self._createImporterForExportedEntries())
diff --git a/lib/lp/translations/utilities/translation_import.py b/lib/lp/translations/utilities/translation_import.py
index f9af932..5a3962a 100644
--- a/lib/lp/translations/utilities/translation_import.py
+++ b/lib/lp/translations/utilities/translation_import.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
@@ -570,6 +570,7 @@ class FileImporter(object):
:return: The errors encountered during the import.
"""
+ from lp.translations.model import pofilestatsjob
# Collect errors here.
self.errors = []
@@ -577,6 +578,12 @@ class FileImporter(object):
if message.msgid_singular:
self.importMessage(message)
+ # Update statistics in background.
+ if self.pofile is not None:
+ pofilestatsjob.schedule(self.pofile.id)
+ elif self.potemplate is not None:
+ pofilestatsjob.schedule(self.potemplate.id)
+
return self.errors, self.translation_file.syntax_warnings
@property