Merge lp:~benji/launchpad/bug-903532 into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: no longer in the source branch.
Merged at revision: 14639
Proposed branch: lp:~benji/launchpad/bug-903532
Merge into: lp:launchpad
Diff against target: 161 lines (+117/-1)
3 files modified
database/schema/security.cfg (+1/-0)
lib/lp/translations/model/pofilestatsjob.py (+18/-0)
lib/lp/translations/tests/test_pofilestatsjob.py (+98/-1)
To merge this branch: bzr merge lp:~benji/launchpad/bug-903532
Reviewer Review Type Date Requested Status
Benji York (community) Approve
Review via email: mp+86820@code.launchpad.net

Commit message

[r=benji] make POFile statistics update jobs also update the stats for related POFiles

Description of the change

Bug 903532 is about a task that was thought to have been done, but half
still needed to be done. This branch does the other half.

The root issue is that when updating the statistics for a POFile, any
POFiles that share translations with the original POFile need to be
updated as well.

The new code (in pofilestatsjob.py) simply loops over all the POFiles
that share translations with the POFile associated with the job and, if
the languages match, updates their statistics as well.

The tests can be run with this command:

    bin/test -c -m lp.translations.tests.test_pofilestatsjob

QA:

1) Note the statistics for the translations listed in bug 904012 (a
   related bug)
2) Make a suggestion for one of those translations
3) Get webops to run cronscripts/run_jobs.py pofile_stats
4) Check to see if both the statistics for the translation you changed
   were updated as well as the statistics for the shared translation

Lint: the "make lint" report is clean.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This MP is for a bug-fix version of the branch that failed QA. The fix
wasn't involved (see discussion on [1]_ for full details) so I'm just
self-reviewing the changes.

.. [1] https://code.launchpad.net/~benji/launchpad/bug-903532/+merge/86426

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2012-01-03 01:40:09 +0000
3+++ database/schema/security.cfg 2012-01-04 16:22:26 +0000
4@@ -441,6 +441,7 @@
5 [pofilestats]
6 groups=script
7 public.language = SELECT
8+public.packaging = SELECT
9 public.pofile = SELECT, UPDATE
10 public.potemplate = SELECT, UPDATE
11 public.job = SELECT, UPDATE, DELETE
12
13=== modified file 'lib/lp/translations/model/pofilestatsjob.py'
14--- lib/lp/translations/model/pofilestatsjob.py 2012-01-01 02:58:52 +0000
15+++ lib/lp/translations/model/pofilestatsjob.py 2012-01-04 16:22:26 +0000
16@@ -34,6 +34,7 @@
17 MAIN_STORE,
18 )
19 from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource
20+from lp.translations.interfaces.potemplate import IPOTemplateSet
21 from lp.translations.model.pofile import POFile
22
23
24@@ -74,6 +75,23 @@
25 logger.info('Updating statistics for %s' % self.pofile.title)
26 self.pofile.updateStatistics()
27
28+ # Next we have to find any POFiles that share translations with the
29+ # above POFile so we can update their statistics too. To do that we
30+ # first have to find the set of shared templates.
31+ subset = getUtility(IPOTemplateSet).getSharingSubset(
32+ product=self.pofile.potemplate.product,
33+ distribution=self.pofile.potemplate.distribution,
34+ sourcepackagename=self.pofile.potemplate.sourcepackagename)
35+ shared_templates = subset.getSharingPOTemplates(
36+ self.pofile.potemplate.name)
37+ # Now we have to find any POFiles that translate the shared templates
38+ # into the same language as the POFile this job is about.
39+ for template in shared_templates:
40+ pofile = template.getPOFileByLang(self.pofile.language.code)
41+ if pofile is None:
42+ continue
43+ pofile.updateStatistics()
44+
45 @staticmethod
46 def iterReady():
47 """See `IJobSource`."""
48
49=== modified file 'lib/lp/translations/tests/test_pofilestatsjob.py'
50--- lib/lp/translations/tests/test_pofilestatsjob.py 2012-01-01 02:58:52 +0000
51+++ lib/lp/translations/tests/test_pofilestatsjob.py 2012-01-04 16:22:26 +0000
52@@ -51,7 +51,7 @@
53 # Now that the job ran, the statistics have been updated.
54 self.assertEqual(pofile.potemplate.messageCount(), 1)
55
56- def test_with_product(self):
57+ def test_run_with_product(self):
58 product = self.factory.makeProduct(
59 translations_usage=ServiceUsage.LAUNCHPAD)
60 productseries = self.factory.makeProductSeries(product=product)
61@@ -93,3 +93,100 @@
62 # is added.
63 pofilestatsjob.schedule(pofile.id)
64 self.assertIs(len(list(POFileStatsJob.iterReady())), 2)
65+
66+ def assertJobUpdatesStats(self, pofile1, pofile2):
67+ # Create a single POTMsgSet and add it to only one of the POTemplates.
68+ self.factory.makeSuggestion(pofile1)
69+ self.factory.makeSuggestion(pofile2)
70+ # The statistics start at 0.
71+ self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0))
72+ self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0))
73+ job = pofilestatsjob.schedule(pofile1.id)
74+ # Just scheduling the job doesn't update the statistics.
75+ self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0))
76+ self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0))
77+ with dbuser(config.pofile_stats.dbuser):
78+ job.run()
79+ # Now that the job ran, the statistics for the POFile have been
80+ # updated.
81+ self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 1))
82+ # The statistics for the other POFile is also updated as a result of
83+ # running the job for the other POFile because they share
84+ # translations.
85+ self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 1))
86+
87+ def test_run_with_project_shared_template(self):
88+ # Create a product with two series and sharing POTemplates
89+ # in different series ('devel' and 'stable').
90+ product = self.factory.makeProduct(
91+ translations_usage=ServiceUsage.LAUNCHPAD)
92+ devel = self.factory.makeProductSeries(
93+ name='devel', product=product)
94+ stable = self.factory.makeProductSeries(
95+ name='stable', product=product)
96+
97+ # POTemplate is a 'sharing' one if it has the same name ('messages').
98+ template1 = self.factory.makePOTemplate(devel, name='messages')
99+ template2 = self.factory.makePOTemplate(stable, name='messages')
100+
101+ self.factory.makeLanguage('en-tt')
102+ pofile1 = self.factory.makePOFile('en-tt', template1)
103+ pofile2 = self.factory.makePOFile('en-tt', template2)
104+
105+ self.assertJobUpdatesStats(pofile1, pofile2)
106+
107+ def test_run_with_product_and_distro_translation_sharing(self):
108+ language = self.factory.makeLanguage('en-tt')
109+ distroseries = self.factory.makeUbuntuDistroSeries()
110+ distroseries.distribution.translation_focus = distroseries
111+ sourcepackagename = self.factory.makeSourcePackageName()
112+ sourcepackage = self.factory.makeSourcePackage(
113+ distroseries=distroseries,
114+ sourcepackagename=sourcepackagename)
115+ productseries = self.factory.makeProductSeries()
116+ sourcepackage.setPackaging(
117+ productseries, self.factory.makePerson())
118+
119+ # Create template ready for sharing on the Ubuntu side.
120+ template1 = self.factory.makePOTemplate(
121+ distroseries=distroseries,
122+ sourcepackagename=sourcepackagename,
123+ name='messages')
124+ pofile1 = self.factory.makePOFile(
125+ language=language, potemplate=template1)
126+
127+ # Create template ready for sharing on the upstream side.
128+ template2 = self.factory.makePOTemplate(
129+ productseries=productseries, name='messages')
130+ pofile2 = template2.getPOFileByLang(language.code)
131+
132+ self.assertJobUpdatesStats(pofile1, pofile2)
133+
134+ def test_run_with_distro_translation_sharing(self):
135+ language = self.factory.makeLanguage('en-tt')
136+ distroseries1 = self.factory.makeUbuntuDistroSeries()
137+ distroseries1.distribution.translation_focus = distroseries1
138+ sourcepackagename = self.factory.makeSourcePackageName()
139+ self.factory.makeSourcePackage(
140+ distroseries=distroseries1,
141+ sourcepackagename=sourcepackagename)
142+ distroseries2 = self.factory.makeUbuntuDistroSeries()
143+ distroseries2.distribution.translation_focus = distroseries2
144+ self.factory.makeSourcePackage(
145+ distroseries=distroseries2,
146+ sourcepackagename=sourcepackagename)
147+
148+ template1 = self.factory.makePOTemplate(
149+ distroseries=distroseries1,
150+ sourcepackagename=sourcepackagename,
151+ name='messages')
152+ pofile1 = self.factory.makePOFile(
153+ language=language, potemplate=template1)
154+
155+ template2 = self.factory.makePOTemplate(
156+ distroseries=distroseries2,
157+ sourcepackagename=sourcepackagename,
158+ name='messages')
159+ pofile2 = template2.getPOFileByLang(language.code)
160+
161+ self.assertJobUpdatesStats(pofile1, pofile2)