Merge lp:~cjwatson/launchpad/snap-repr into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18336
Proposed branch: lp:~cjwatson/launchpad/snap-repr
Merge into: lp:launchpad
Diff against target: 56 lines (+19/-1)
3 files modified
lib/lp/services/webhooks/tests/test_job.py (+10/-1)
lib/lp/snappy/model/snap.py (+3/-0)
lib/lp/snappy/tests/test_snap.py (+6/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-repr
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+321195@code.launchpad.net

Commit message

Add a more useful __repr__ for Snap.

Description of the change

This makes it easier to look for snap-related webhook delivery jobs in logs.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/webhooks/tests/test_job.py'
2--- lib/lp/services/webhooks/tests/test_job.py 2016-09-14 11:13:06 +0000
3+++ lib/lp/services/webhooks/tests/test_job.py 2017-03-28 16:25:10 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
6+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Tests for `WebhookJob`s."""
10@@ -334,6 +334,15 @@
11 "<WebhookDeliveryJob for webhook %d on %r>" % (hook.id, branch),
12 repr(job))
13
14+ def test_snap__repr__(self):
15+ # `WebhookDeliveryJob` objects for snaps have an informative __repr__.
16+ snap = self.factory.makeSnap()
17+ hook = self.factory.makeWebhook(target=snap)
18+ job = WebhookDeliveryJob.create(hook, 'test', payload={'foo': 'bar'})
19+ self.assertEqual(
20+ "<WebhookDeliveryJob for webhook %d on %r>" % (hook.id, snap),
21+ repr(job))
22+
23 def test_short_lease_and_timeout(self):
24 # Webhook jobs have a request timeout of 30 seconds, a celery
25 # timeout of 45 seconds, and a lease of 60 seconds, to give
26
27=== modified file 'lib/lp/snappy/model/snap.py'
28--- lib/lp/snappy/model/snap.py 2017-03-08 18:36:37 +0000
29+++ lib/lp/snappy/model/snap.py 2017-03-28 16:25:10 +0000
30@@ -233,6 +233,9 @@
31 self.store_secrets = store_secrets
32 self.store_channels = store_channels
33
34+ def __repr__(self):
35+ return "<Snap ~%s/+snap/%s>" % (self.owner.name, self.name)
36+
37 @property
38 def valid_webhook_event_types(self):
39 return ["snap:build:0.1"]
40
41=== modified file 'lib/lp/snappy/tests/test_snap.py'
42--- lib/lp/snappy/tests/test_snap.py 2017-02-27 18:46:38 +0000
43+++ lib/lp/snappy/tests/test_snap.py 2017-03-28 16:25:10 +0000
44@@ -132,6 +132,12 @@
45 with admin_logged_in():
46 self.assertProvides(snap, ISnap)
47
48+ def test___repr__(self):
49+ # `Snap` objects have an informative __repr__.
50+ snap = self.factory.makeSnap()
51+ self.assertEqual(
52+ "<Snap ~%s/+snap/%s>" % (snap.owner.name, snap.name), repr(snap))
53+
54 def test_avoids_problematic_snapshots(self):
55 self.assertThat(
56 self.factory.makeSnap(),