launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #21421
[Merge] lp:~cjwatson/launchpad/snap-repr into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/snap-repr into lp:launchpad.
Commit message:
Add a more useful __repr__ for Snap.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/snap-repr/+merge/321195
This makes it easier to look for snap-related webhook delivery jobs in logs.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/snap-repr into lp:launchpad.
=== modified file 'lib/lp/services/webhooks/tests/test_job.py'
--- lib/lp/services/webhooks/tests/test_job.py 2016-09-14 11:13:06 +0000
+++ lib/lp/services/webhooks/tests/test_job.py 2017-03-28 16:25:10 +0000
@@ -1,4 +1,4 @@
-# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for `WebhookJob`s."""
@@ -334,6 +334,15 @@
"<WebhookDeliveryJob for webhook %d on %r>" % (hook.id, branch),
repr(job))
+ def test_snap__repr__(self):
+ # `WebhookDeliveryJob` objects for snaps have an informative __repr__.
+ snap = self.factory.makeSnap()
+ hook = self.factory.makeWebhook(target=snap)
+ job = WebhookDeliveryJob.create(hook, 'test', payload={'foo': 'bar'})
+ self.assertEqual(
+ "<WebhookDeliveryJob for webhook %d on %r>" % (hook.id, snap),
+ 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
=== modified file 'lib/lp/snappy/model/snap.py'
--- lib/lp/snappy/model/snap.py 2017-03-08 18:36:37 +0000
+++ lib/lp/snappy/model/snap.py 2017-03-28 16:25:10 +0000
@@ -233,6 +233,9 @@
self.store_secrets = store_secrets
self.store_channels = store_channels
+ def __repr__(self):
+ return "<Snap ~%s/+snap/%s>" % (self.owner.name, self.name)
+
@property
def valid_webhook_event_types(self):
return ["snap:build:0.1"]
=== modified file 'lib/lp/snappy/tests/test_snap.py'
--- lib/lp/snappy/tests/test_snap.py 2017-02-27 18:46:38 +0000
+++ lib/lp/snappy/tests/test_snap.py 2017-03-28 16:25:10 +0000
@@ -132,6 +132,12 @@
with admin_logged_in():
self.assertProvides(snap, ISnap)
+ def test___repr__(self):
+ # `Snap` objects have an informative __repr__.
+ snap = self.factory.makeSnap()
+ self.assertEqual(
+ "<Snap ~%s/+snap/%s>" % (snap.owner.name, snap.name), repr(snap))
+
def test_avoids_problematic_snapshots(self):
self.assertThat(
self.factory.makeSnap(),
Follow ups