Benji York has proposed merging lp:~benji/launchpad/bug-894177-2 into 
lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #894177 in Launchpad itself: "run_jobs.py pofile_stats oopses: permission 
denied for relation productseries"
  https://bugs.launchpad.net/launchpad/+bug/894177

For more details, see:
https://code.launchpad.net/~benji/launchpad/bug-894177-2/+merge/84676

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

-- 
https://code.launchpad.net/~benji/launchpad/bug-894177-2/+merge/84676
Your team Launchpad code reviewers is requested to review the proposed merge of 
lp:~benji/launchpad/bug-894177-2 into lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg	2011-12-06 11:00:07 +0000
+++ database/schema/security.cfg	2011-12-06 21:22:27 +0000
@@ -446,6 +446,8 @@
 public.job                              = SELECT, UPDATE, DELETE
 public.pofilestatsjob                   = SELECT, UPDATE, DELETE
 public.potmsgset                        = SELECT
+public.product                          = SELECT
+public.productseries                    = SELECT
 public.distroseries                     = SELECT
 public.distribution                     = SELECT
 public.sourcepackagename                = SELECT

=== modified file 'lib/lp/translations/tests/test_pofilestatsjob.py'
--- lib/lp/translations/tests/test_pofilestatsjob.py	2011-11-10 15:02:49 +0000
+++ lib/lp/translations/tests/test_pofilestatsjob.py	2011-12-06 21:22:27 +0000
@@ -6,10 +6,12 @@
 __metaclass__ = type
 
 
+from canonical.config import config
 from canonical.launchpad.webapp.testing import verifyObject
 from canonical.testing.layers import (
     LaunchpadZopelessLayer,
     )
+from lp.app.enums import ServiceUsage
 from lp.services.job.interfaces.job import (
     IJobSource,
     IRunnableJob,
@@ -45,6 +47,26 @@
         job = pofilestatsjob.schedule(pofile.id)
         # Just scheduling the job doesn't update the statistics.
         self.assertEqual(pofile.potemplate.messageCount(), 0)
+        LaunchpadZopelessLayer.switchDbUser(config.pofile_stats.dbuser)
+        job.run()
+        # Now that the job ran, the statistics have been updated.
+        self.assertEqual(pofile.potemplate.messageCount(), 1)
+
+    def test_with_product(self):
+        product = self.factory.makeProduct(
+            translations_usage=ServiceUsage.LAUNCHPAD)
+        productseries = self.factory.makeProductSeries(product=product)
+        potemplate = self.factory.makePOTemplate(productseries=productseries)
+        pofile = self.factory.makePOFile('en', potemplate)
+        # Create a message so we have something to have statistics about.
+        singular = self.factory.getUniqueString()
+        self.factory.makePOTMsgSet(pofile.potemplate, singular)
+        # The statistics are still at 0, even though there is a message.
+        self.assertEqual(potemplate.messageCount(), 0)
+        job = pofilestatsjob.schedule(pofile.id)
+        # Just scheduling the job doesn't update the statistics.
+        self.assertEqual(pofile.potemplate.messageCount(), 0)
+        LaunchpadZopelessLayer.switchDbUser(config.pofile_stats.dbuser)
         job.run()
         # Now that the job ran, the statistics have been updated.
         self.assertEqual(pofile.potemplate.messageCount(), 1)

_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to