Merge lp:~cjwatson/launchpad/snap-webhooks-permissions into lp:launchpad

Proposed by Colin Watson on 2016-03-02
Status: Merged
Merged at revision: 17936
Proposed branch: lp:~cjwatson/launchpad/snap-webhooks-permissions
Merge into: lp:launchpad
Diff against target: 172 lines (+38/-7)
5 files modified
database/schema/security.cfg (+1/-0)
lib/lp/code/model/tests/test_branchmergeproposal.py (+12/-5)
lib/lp/code/model/tests/test_gitjob.py (+11/-0)
lib/lp/codehosting/scanner/tests/test_bzrsync.py (+6/-1)
lib/lp/snappy/tests/test_snapbuild.py (+8/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-webhooks-permissions
Reviewer Review Type Date Requested Status
William Grant code 2016-03-02 Approve on 2016-03-02
Review via email: mp+287851@code.launchpad.net

Commit Message

Fix permissions to allow dispatching of snap webhooks.

Description of the Change

Fix permissions to allow dispatching of snap webhooks. All webhook-capable models now have tests to ensure that webhook job repr() works.

To post a comment you must log in.
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 'database/schema/security.cfg'
2--- database/schema/security.cfg 2016-01-19 17:41:11 +0000
3+++ database/schema/security.cfg 2016-03-02 21:26:51 +0000
4@@ -2503,6 +2503,7 @@
5 public.job = SELECT, UPDATE
6 public.person = SELECT
7 public.product = SELECT
8+public.snap = SELECT
9 public.sourcepackagename = SELECT
10 public.webhook = SELECT
11 public.webhookjob = SELECT, UPDATE
12
13=== modified file 'lib/lp/code/model/tests/test_branchmergeproposal.py'
14--- lib/lp/code/model/tests/test_branchmergeproposal.py 2015-10-15 16:01:50 +0000
15+++ lib/lp/code/model/tests/test_branchmergeproposal.py 2016-03-02 21:26:51 +0000
16@@ -1,4 +1,4 @@
17-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
18+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
19 # GNU Affero General Public License version 3 (see the file LICENSE).
20
21 """Tests for BranchMergeProposals."""
22@@ -73,6 +73,7 @@
23 from lp.registry.enums import TeamMembershipPolicy
24 from lp.registry.interfaces.person import IPersonSet
25 from lp.registry.interfaces.product import IProductSet
26+from lp.services.config import config
27 from lp.services.database.constants import UTC_NOW
28 from lp.services.features.testing import FeatureFixture
29 from lp.services.webapp import canonical_url
30@@ -87,6 +88,7 @@
31 WebServiceTestCase,
32 ws_object,
33 )
34+from lp.testing.dbuser import dbuser
35 from lp.testing.factory import LaunchpadObjectFactory
36 from lp.testing.layers import (
37 DatabaseFunctionalLayer,
38@@ -969,11 +971,16 @@
39 }
40 return {k: Equals(v) for k, v in payload.items()}
41
42- def assertCorrectDelivery(self, expected_payload, delivery):
43+ def assertCorrectDelivery(self, expected_payload, hook, delivery):
44 self.assertThat(
45 delivery, MatchesStructure(
46 event_type=Equals("merge-proposal:0.1"),
47 payload=MatchesDict(expected_payload)))
48+ with dbuser(config.IWebhookDeliveryJobSource.dbuser):
49+ self.assertEqual(
50+ "<WebhookDeliveryJob for webhook %d on %r>" % (
51+ hook.id, hook.target),
52+ repr(delivery))
53
54 def test_create_triggers_webhooks(self):
55 # When a merge proposal is created, any relevant webhooks are
56@@ -993,7 +1000,7 @@
57 "action": Equals("created"),
58 "new": MatchesDict(self.getExpectedPayload(proposal)),
59 }
60- self.assertCorrectDelivery(expected_payload, delivery)
61+ self.assertCorrectDelivery(expected_payload, hook, delivery)
62
63 def test_modify_triggers_webhooks(self):
64 # When an existing merge proposal is modified, any relevant webhooks
65@@ -1019,7 +1026,7 @@
66 expected_payload["new"] = MatchesDict(
67 self.getExpectedPayload(proposal))
68 delivery = hook.deliveries.one()
69- self.assertCorrectDelivery(expected_payload, delivery)
70+ self.assertCorrectDelivery(expected_payload, hook, delivery)
71
72 def test_delete_triggers_webhooks(self):
73 # When an existing merge proposal is deleted, any relevant webhooks
74@@ -1040,7 +1047,7 @@
75 }
76 proposal.deleteProposal()
77 delivery = hook.deliveries.one()
78- self.assertCorrectDelivery(expected_payload, delivery)
79+ self.assertCorrectDelivery(expected_payload, hook, delivery)
80
81
82 class TestMergeProposalWebhooksBzr(
83
84=== modified file 'lib/lp/code/model/tests/test_gitjob.py'
85--- lib/lp/code/model/tests/test_gitjob.py 2016-02-05 16:51:12 +0000
86+++ lib/lp/code/model/tests/test_gitjob.py 2016-03-02 21:26:51 +0000
87@@ -39,6 +39,7 @@
88 GitRefScanJob,
89 ReclaimGitRepositorySpaceJob,
90 )
91+from lp.services.config import config
92 from lp.services.database.constants import UTC_NOW
93 from lp.services.features.testing import FeatureFixture
94 from lp.services.job.runner import JobRunner
95@@ -217,6 +218,11 @@
96 'old': None,
97 'new': {'commit_sha1': sha1('refs/tags/2.0')}},
98 })})))
99+ with dbuser(config.IWebhookDeliveryJobSource.dbuser):
100+ self.assertEqual(
101+ "<WebhookDeliveryJob for webhook %d on %r>" % (
102+ hook.id, hook.target),
103+ repr(delivery))
104
105 def test_merge_detection_triggers_webhooks(self):
106 self.useFixture(FeatureFixture(
107@@ -258,6 +264,11 @@
108 {'queue_status': Equals('Work in progress')}),
109 'new': ContainsDict({'queue_status': Equals('Merged')}),
110 })))
111+ with dbuser(config.IWebhookDeliveryJobSource.dbuser):
112+ self.assertEqual(
113+ "<WebhookDeliveryJob for webhook %d on %r>" % (
114+ hook.id, hook.target),
115+ repr(delivery))
116
117 def test_composeWebhookPayload(self):
118 repository = self.factory.makeGitRepository()
119
120=== modified file 'lib/lp/codehosting/scanner/tests/test_bzrsync.py'
121--- lib/lp/codehosting/scanner/tests/test_bzrsync.py 2015-10-01 14:45:57 +0000
122+++ lib/lp/codehosting/scanner/tests/test_bzrsync.py 2016-03-02 21:26:51 +0000
123@@ -1,6 +1,6 @@
124 #!/usr/bin/python
125 #
126-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
127+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
128 # GNU Affero General Public License version 3 (see the file LICENSE).
129
130 import datetime
131@@ -774,6 +774,11 @@
132 "old": Equals({"revision_id": old_revid}),
133 "new": Equals({"revision_id": new_revid}),
134 })))
135+ with dbuser(config.IWebhookDeliveryJobSource.dbuser):
136+ self.assertEqual(
137+ "<WebhookDeliveryJob for webhook %d on %r>" % (
138+ hook.id, hook.target),
139+ repr(delivery))
140
141
142 class TestRevisionProperty(BzrSyncTestCase):
143
144=== modified file 'lib/lp/snappy/tests/test_snapbuild.py'
145--- lib/lp/snappy/tests/test_snapbuild.py 2016-02-19 14:18:22 +0000
146+++ lib/lp/snappy/tests/test_snapbuild.py 2016-03-02 21:26:51 +0000
147@@ -52,6 +52,7 @@
148 person_logged_in,
149 TestCaseWithFactory,
150 )
151+from lp.testing.dbuser import dbuser
152 from lp.testing.layers import (
153 LaunchpadFunctionalLayer,
154 LaunchpadZopelessLayer,
155@@ -238,10 +239,16 @@
156 canonical_url(self.build.snap, force_local_path=True)),
157 "status": Equals("Successfully built"),
158 }
159+ delivery = hook.deliveries.one()
160 self.assertThat(
161- hook.deliveries.one(), MatchesStructure(
162+ delivery, MatchesStructure(
163 event_type=Equals("snap:build:0.1"),
164 payload=MatchesDict(expected_payload)))
165+ with dbuser(config.IWebhookDeliveryJobSource.dbuser):
166+ self.assertEqual(
167+ "<WebhookDeliveryJob for webhook %d on %r>" % (
168+ hook.id, hook.target),
169+ repr(delivery))
170
171 def test_notify_fullybuilt(self):
172 # notify does not send mail when a SnapBuild completes normally.