← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/webhook-logging into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/webhook-logging into lp:launchpad.

Commit message:
Give webhook jobs a more informative __repr__.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/webhook-logging/+merge/277280

Give webhook jobs a more informative __repr__.  "Running <lp.services.webhooks.model.WebhookDeliveryJob object at <0xblah>" is not as helpful for debugging as it could be.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/webhook-logging into lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg	2015-10-28 17:32:49 +0000
+++ database/schema/security.cfg	2015-11-11 18:20:52 +0000
@@ -2492,6 +2492,12 @@
 [webhookrunner]
 type=user
 groups=script
+public.branch                           = SELECT
+public.distribution                     = SELECT
+public.gitrepository                    = SELECT
 public.job                              = SELECT, UPDATE
+public.person                           = SELECT
+public.product                          = SELECT
+public.sourcepackagename                = SELECT
 public.webhook                          = SELECT
 public.webhookjob                       = SELECT, UPDATE

=== modified file 'lib/lp/services/webhooks/model.py'
--- lib/lp/services/webhooks/model.py	2015-10-14 16:03:01 +0000
+++ lib/lp/services/webhooks/model.py	2015-11-11 18:20:52 +0000
@@ -341,6 +341,13 @@
     def __init__(self, webhook_job):
         self.context = webhook_job
 
+    def __repr__(self):
+        return "<%(job_class)s for webhook %(webhook_id)d on %(target)r>" % {
+            "job_class": self.__class__.__name__,
+            "webhook_id": self.context.webhook_id,
+            "target": self.context.webhook.target,
+            }
+
     @classmethod
     def iterReady(cls):
         """See `IJobSource`."""

=== modified file 'lib/lp/services/webhooks/tests/test_job.py'
--- lib/lp/services/webhooks/tests/test_job.py	2015-09-01 05:55:01 +0000
+++ lib/lp/services/webhooks/tests/test_job.py	2015-11-11 18:20:52 +0000
@@ -313,6 +313,27 @@
             MatchesStructure.byEquality(
                 webhook=hook, event_type='test', payload={'foo': 'bar'}))
 
+    def test_gitrepository__repr__(self):
+        # `WebhookDeliveryJob` objects for Git repositories have an
+        # informative __repr__.
+        repository = self.factory.makeGitRepository()
+        hook = self.factory.makeWebhook(target=repository)
+        job = WebhookDeliveryJob.create(hook, 'test', payload={'foo': 'bar'})
+        self.assertEqual(
+            "<WebhookDeliveryJob for webhook %d on %r>" % (
+                hook.id, repository),
+            repr(job))
+
+    def test_branch__repr__(self):
+        # `WebhookDeliveryJob` objects for Bazaar branches have an
+        # informative __repr__.
+        branch = self.factory.makeAnyBranch()
+        hook = self.factory.makeWebhook(target=branch)
+        job = WebhookDeliveryJob.create(hook, 'test', payload={'foo': 'bar'})
+        self.assertEqual(
+            "<WebhookDeliveryJob for webhook %d on %r>" % (hook.id, branch),
+            repr(job))
+
     def test_short_lease_and_timeout(self):
         # Webhook jobs have a request timeout of 30 seconds, a celery
         # timeout of 45 seconds, and a lease of 60 seconds, to give


Follow ups