Merge lp:~benji/launchpad/bug-894177-2 into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: no longer in the source branch.
Merged at revision: 14476
Proposed branch: lp:~benji/launchpad/bug-894177-2
Merge into: lp:launchpad
Diff against target: 63 lines (+26/-1)
2 files modified
database/schema/security.cfg (+2/-0)
lib/lp/translations/tests/test_pofilestatsjob.py (+24/-1)
To merge this branch: bzr merge lp:~benji/launchpad/bug-894177-2
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Brad Crittenden (community) code Approve
Martin Pool (community) Approve
Review via email: mp+84676@code.launchpad.net

Commit message

[r=bac,lifeless,mbp][bug=894177] add some needed permissions (with tests)

Description of the change

In moving translations statistics updates into a cron job I missed some permissions it would need when running against products. This branch adds those permissions and adds tests that fail without the permissions in place. The branch also makes the pre-existing tests assert proper permissions.

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

Lint: "make lint" reports none

QA:

- note the translation statistics for a project
- make a translation change to a project (like submit a message string and ask
  for review)
- verify that the statistics haven't changed
- ask a LOSA, er, webops to run cronscripts/run_jobs.py pofile_stats
- verify that they report that the job did not raise an exception
- verify that the statistics have changed

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

It looks plausible to me but you probably want another review from someone more experienced.

review: Approve
Revision history for this message
Brad Crittenden (bac) wrote :

Looks good Benji. Thanks for the clear QA steps.

review: Approve (code)
Revision history for this message
Robert Collins (lifeless) wrote :

10:49 < lifeless> benji: there is a context manager for switching db user
10:49 < lifeless> benji: it might be nicer
10:50 < benji> lifeless: ooh, indeed it would; thanks

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 2011-12-06 11:00:07 +0000
3+++ database/schema/security.cfg 2011-12-08 14:39:37 +0000
4@@ -446,6 +446,8 @@
5 public.job = SELECT, UPDATE, DELETE
6 public.pofilestatsjob = SELECT, UPDATE, DELETE
7 public.potmsgset = SELECT
8+public.product = SELECT
9+public.productseries = SELECT
10 public.distroseries = SELECT
11 public.distribution = SELECT
12 public.sourcepackagename = SELECT
13
14=== modified file 'lib/lp/translations/tests/test_pofilestatsjob.py'
15--- lib/lp/translations/tests/test_pofilestatsjob.py 2011-11-10 15:02:49 +0000
16+++ lib/lp/translations/tests/test_pofilestatsjob.py 2011-12-08 14:39:37 +0000
17@@ -6,15 +6,18 @@
18 __metaclass__ = type
19
20
21+from canonical.config import config
22 from canonical.launchpad.webapp.testing import verifyObject
23 from canonical.testing.layers import (
24 LaunchpadZopelessLayer,
25 )
26+from lp.app.enums import ServiceUsage
27 from lp.services.job.interfaces.job import (
28 IJobSource,
29 IRunnableJob,
30 )
31 from lp.testing import TestCaseWithFactory
32+from lp.testing.dbuser import dbuser
33 from lp.translations.interfaces.pofilestatsjob import IPOFileStatsJobSource
34 from lp.translations.interfaces.side import TranslationSide
35 from lp.translations.model import pofilestatsjob
36@@ -45,7 +48,27 @@
37 job = pofilestatsjob.schedule(pofile.id)
38 # Just scheduling the job doesn't update the statistics.
39 self.assertEqual(pofile.potemplate.messageCount(), 0)
40- job.run()
41+ with dbuser(config.pofile_stats.dbuser):
42+ job.run()
43+ # Now that the job ran, the statistics have been updated.
44+ self.assertEqual(pofile.potemplate.messageCount(), 1)
45+
46+ def test_with_product(self):
47+ product = self.factory.makeProduct(
48+ translations_usage=ServiceUsage.LAUNCHPAD)
49+ productseries = self.factory.makeProductSeries(product=product)
50+ potemplate = self.factory.makePOTemplate(productseries=productseries)
51+ pofile = self.factory.makePOFile('en', potemplate)
52+ # Create a message so we have something to have statistics about.
53+ singular = self.factory.getUniqueString()
54+ self.factory.makePOTMsgSet(pofile.potemplate, singular)
55+ # The statistics are still at 0, even though there is a message.
56+ self.assertEqual(potemplate.messageCount(), 0)
57+ job = pofilestatsjob.schedule(pofile.id)
58+ # Just scheduling the job doesn't update the statistics.
59+ self.assertEqual(pofile.potemplate.messageCount(), 0)
60+ with dbuser(config.pofile_stats.dbuser):
61+ job.run()
62 # Now that the job ran, the statistics have been updated.
63 self.assertEqual(pofile.potemplate.messageCount(), 1)
64