Merge lp:~laney/launchpad/add-sponsor-field-to-spph into lp:launchpad

Proposed by Iain Lane on 2012-01-09
Status: Merged
Approved by: j.c.sackett on 2012-01-19
Approved revision: no longer in the source branch.
Merged at revision: 14708
Proposed branch: lp:~laney/launchpad/add-sponsor-field-to-spph
Merge into: lp:launchpad
Prerequisite: lp:~laney/launchpad/spph-sponsor
Diff against target: 322 lines (+82/-49)
5 files modified
lib/lp/soyuz/interfaces/publishing.py (+12/-1)
lib/lp/soyuz/model/publishing.py (+10/-5)
lib/lp/soyuz/scripts/packagecopier.py (+9/-4)
lib/lp/soyuz/scripts/tests/test_copypackage.py (+50/-39)
lib/lp/soyuz/stories/webservice/xx-source-package-publishing.txt (+1/-0)
To merge this branch: bzr merge lp:~laney/launchpad/add-sponsor-field-to-spph
Reviewer Review Type Date Requested Status
j.c.sackett (community) 2012-01-19 Approve on 2012-01-19
Richard Harding (community) code* 2012-01-09 Approve on 2012-01-19
Review via email: mp+87930@code.launchpad.net

Commit Message

[r=jcsackett,rharding][bug=912247] If copyPackage is sponsored, sases sponsor in SPPH.

Description of the Change

If copyPackage is sponsored, save sponsor in SPPH.

== Test ==

bin/test -cvv -t test_copypackage -t publishing.txt -t archive.txt -t builds.txt

Total: 112 tests, 0 failures, 0 errors in 4 minutes 59.660 seconds.

== Demo and QA ==

Find a package which is newer in Debian than Ubuntu and copy it into Ubuntu using copyPackage and setting the sponsored field to some user. Ensure that the sponsor field of the resulting SPPH is set to your user.

== lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/soyuz/interfaces/publishing.py
  lib/lp/soyuz/model/publishing.py
  lib/lp/soyuz/scripts/packagecopier.py
  lib/lp/soyuz/scripts/tests/test_copypackage.py

./lib/lp/soyuz/scripts/tests/test_copypackage.py
    1456: Line exceeds 78 characters.
    1456: E501 line too long (82 characters)
make: *** [lint] Error 2

Preexisting and AFAICS not fixable as it is matching a string from an email.

To post a comment you must log in.
Steve Kowalik (stevenk) wrote :

This can not land until the DB patch in lp:~laney/launchpad/spph-sponsor hits production.

Richard Harding (rharding) wrote :

Can the test for test_sponsored_copy_sponsor_field just be an additional assert in the test_sponsored_copy_notification test case? Just rename that to test_sponsored_copy perhaps? It seems a lot of duplicate boilerplate.

Other than that, approving.

review: Approve (code*)
j.c.sackett (jcsackett) wrote :
Download full text (5.8 KiB)

This looks okay, but I really would like the duplicated boilerplate in the
tests handled.

One approach I would prefer to just mashing the tests together is in the diff
below.

> === modified file 'lib/lp/soyuz/scripts/tests/test_copypackage.py'
> --- lib/lp/soyuz/scripts/tests/test_copypackage.py 2011-12-30 06:14:56 +0000
> +++ lib/lp/soyuz/scripts/tests/test_copypackage.py 2012-01-09 14:10:32 +0000
> @@ -1,4 +1,4 @@
> -# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
> +# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
> # GNU Affero General Public License version 3 (see the file LICENSE).
>
> __metaclass__ = type
> @@ -1526,6 +1526,30 @@
> 'Sponsored <email address hidden>', announcement['From'])
> self.assertEqual(sponsored_person, copied_source.creator)
>
> + def test_sponsored_copy_sponsor_field(self):
> + # If it's a sponsored copy then the SPPH's sponsored field is set to
> + # the user who sponsored the copy.
> + archive = self.test_publisher.ubuntutest.main_archive
> + source = self.test_publisher.getPubSource(
> + archive=archive, version='1.0-2', architecturehintlist='any')
> + changelog = self.factory.makeChangelog(spn="foo", versions=["1.0-2"])
> + source.sourcepackagerelease.changelog = changelog
> + # Copying to a primary archive reads the changes to close bugs.
> + transaction.commit()
> + nobby = self.createNobby(('i386', 'hppa'))
> + getUtility(ISourcePackageFormatSelectionSet).add(
> + nobby, SourcePackageFormat.FORMAT_1_0)
> + nobby.changeslist = '<email address hidden>'
> + sponsored_person = self.factory.makePerson(
> + displayname="Sponsored", <email address hidden>")
> + [copied_source] = do_copy(
> + [source], archive, nobby, source.pocket, False,
> + person=source.sourcepackagerelease.creator,
> + check_permissions=False, send_email=True,
> + sponsored=sponsored_person)
> + self.assertEqual(source.sourcepackagerelease.creator,
> + copied_source.sponsor)
> +
> def test_copy_notification_contains_aggregate_change_log(self):
> # When copying a package that generates a notification,
> # the changelog should contain all of the changelog_entry texts for
> @@ -1663,6 +1687,26 @@
> target_archive.owner,
> copied_source.creator)
>
> + def test_unsponsored_copy_does_not_set_sponsor(self):
> + # If the copy is not sponsored, SPPH.sponsor is none
> + archive = self.test_publisher.ubuntutest.main_archive
> + source = self.test_publisher.getPubSource(
> + archive=archive, version='1.0-2', architecturehintlist='any')
> + source.sourcepackagerelease.changelog_entry = '* Foo!'
> + nobby = self.createNobby(('i386', 'hppa'))
> + getUtility(ISourcePackageFormatSelectionSet).add(
> + nobby, SourcePackageFormat.FORMAT_1_0)
> + target_archive = self.factory.makeArchive(
> + distribution=self.test_publisher.ubun...

Read more...

review: Needs Fixing
j.c.sackett (jcsackett) wrote :

I note that this now removes several `changelog_entry = '* Foo!' lines, but it's been verified the tests all still pass.

This looks ok to land.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
2--- lib/lp/soyuz/interfaces/publishing.py 2011-12-24 16:54:44 +0000
3+++ lib/lp/soyuz/interfaces/publishing.py 2012-01-20 13:35:27 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 # pylint: disable-msg=E0211,E0213
10@@ -495,6 +495,15 @@
11 required=False, readonly=True
12 ))
13
14+ sponsor = exported(
15+ Reference(
16+ IPerson,
17+ title=_('Publication sponsor'),
18+ description=_('The IPerson who sponsored the creation of'
19+ 'this publication.'),
20+ required=False, readonly=True
21+ ))
22+
23 # Really IBinaryPackagePublishingHistory, see below.
24 @operation_returns_collection_of(Interface)
25 @export_read_operation()
26@@ -1009,6 +1018,8 @@
27 should be created for the new source publication.
28 :param creator: An optional `IPerson`. If this is None, the
29 sourcepackagerelease's creator will be used.
30+ :param sponsor: An optional `IPerson` indicating the sponsor of this
31+ publication.
32
33 datecreated will be UTC_NOW.
34 status will be PackagePublishingStatus.PENDING
35
36=== modified file 'lib/lp/soyuz/model/publishing.py'
37--- lib/lp/soyuz/model/publishing.py 2011-12-30 06:14:56 +0000
38+++ lib/lp/soyuz/model/publishing.py 2012-01-20 13:35:27 +0000
39@@ -1,4 +1,4 @@
40-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
41+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
42 # GNU Affero General Public License version 3 (see the file LICENSE).
43
44 # pylint: disable-msg=E0611,W0212
45@@ -456,6 +456,9 @@
46 creator = ForeignKey(
47 dbName='creator', foreignKey='Person',
48 storm_validator=validate_public_person, notNull=False, default=None)
49+ sponsor = ForeignKey(
50+ dbName='sponsor', foreignKey='Person',
51+ storm_validator=validate_public_person, notNull=False, default=None)
52
53 @property
54 def package_creator(self):
55@@ -816,7 +819,7 @@
56 archive=current.archive)
57
58 def copyTo(self, distroseries, pocket, archive, override=None,
59- create_dsd_job=True, creator=None):
60+ create_dsd_job=True, creator=None, sponsor=None):
61 """See `ISourcePackagePublishingHistory`."""
62 component = self.component
63 section = self.section
64@@ -834,7 +837,8 @@
65 pocket,
66 ancestor=self,
67 create_dsd_job=create_dsd_job,
68- creator=creator)
69+ creator=creator,
70+ sponsor=sponsor)
71
72 def getStatusSummaryForBuilds(self):
73 """See `ISourcePackagePublishingHistory`."""
74@@ -1511,7 +1515,7 @@
75 def newSourcePublication(self, archive, sourcepackagerelease,
76 distroseries, component, section, pocket,
77 ancestor=None, create_dsd_job=True,
78- creator=None):
79+ creator=None, sponsor=None):
80 """See `IPublishingSet`."""
81 # Avoid circular import.
82 from lp.registry.model.distributionsourcepackage import (
83@@ -1528,7 +1532,8 @@
84 status=PackagePublishingStatus.PENDING,
85 datecreated=UTC_NOW,
86 ancestor=ancestor,
87- creator=creator)
88+ creator=creator,
89+ sponsor=sponsor)
90 DistributionSourcePackage.ensure(pub)
91
92 if create_dsd_job:
93
94=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
95--- lib/lp/soyuz/scripts/packagecopier.py 2012-01-06 11:08:30 +0000
96+++ lib/lp/soyuz/scripts/packagecopier.py 2012-01-20 13:35:27 +0000
97@@ -1,4 +1,4 @@
98-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
99+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
100 # GNU Affero General Public License version 3 (see the file LICENSE).
101
102 """PackageCopier utilities."""
103@@ -652,13 +652,16 @@
104 if sponsored is not None:
105 announce_from_person = sponsored
106 creator = sponsored
107+ sponsor = person
108 else:
109 creator = person
110+ sponsor = None
111 sub_copies = _do_direct_copy(
112 source, archive, destination_series, pocket,
113 include_binaries, override, close_bugs=close_bugs,
114 create_dsd_job=create_dsd_job,
115- close_bugs_since_version=old_version, creator=creator)
116+ close_bugs_since_version=old_version, creator=creator,
117+ sponsor=sponsor)
118 if send_email:
119 notify(
120 person, source.sourcepackagerelease, [], [], archive,
121@@ -674,7 +677,8 @@
122
123 def _do_direct_copy(source, archive, series, pocket, include_binaries,
124 override=None, close_bugs=True, create_dsd_job=True,
125- close_bugs_since_version=None, creator=None):
126+ close_bugs_since_version=None, creator=None,
127+ sponsor=None):
128 """Copy publishing records to another location.
129
130 Copy each item of the given list of `SourcePackagePublishingHistory`
131@@ -701,6 +705,7 @@
132 then this parameter says which changelog entries to parse looking
133 for bugs to close. See `close_bugs_for_sourcepackagerelease`.
134 :param creator: the requester `IPerson`.
135+ :param sponsor: the sponsor `IPerson`, if this copy is being sponsored.
136
137 :return: a list of `ISourcePackagePublishingHistory` and
138 `BinaryPackagePublishingHistory` corresponding to the copied
139@@ -731,7 +736,7 @@
140 override = overrides[0]
141 source_copy = source.copyTo(
142 series, pocket, archive, override, create_dsd_job=create_dsd_job,
143- creator=creator)
144+ creator=creator, sponsor=sponsor)
145 if close_bugs:
146 close_bugs_for_sourcepublication(
147 source_copy, close_bugs_since_version)
148
149=== modified file 'lib/lp/soyuz/scripts/tests/test_copypackage.py'
150--- lib/lp/soyuz/scripts/tests/test_copypackage.py 2011-12-30 06:14:56 +0000
151+++ lib/lp/soyuz/scripts/tests/test_copypackage.py 2012-01-20 13:35:27 +0000
152@@ -1,4 +1,4 @@
153-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
154+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
155 # GNU Affero General Public License version 3 (see the file LICENSE).
156
157 __metaclass__ = type
158@@ -1336,11 +1336,19 @@
159 self.assertComponentSectionAndPriority(
160 ebin_hppa.component, ebin_hppa, copied_bin_hppa)
161
162+ def _setup_archive(self):
163+ archive = self.test_publisher.ubuntutest.main_archive
164+ source = self.test_publisher.getPubSource(
165+ archive=archive, version='1.0-2', architecturehintlist='any')
166+ nobby = self.createNobby(('i386', 'hppa'))
167+ getUtility(ISourcePackageFormatSelectionSet).add(
168+ nobby, SourcePackageFormat.FORMAT_1_0)
169+ return nobby, archive, source
170+
171 def test_existing_publication_overrides_pockets(self):
172 # When we copy source/binaries from one pocket to another, the
173 # overrides are unchanged from the source publication overrides.
174- nobby = self.createNobby(('i386', 'hppa'))
175- archive = self.test_publisher.ubuntutest.main_archive
176+ nobby, archive, _ = self._setup_archive()
177 source = self.test_publisher.getPubSource(
178 archive=archive, version='1.0-1', architecturehintlist='any',
179 distroseries=nobby, pocket=PackagePublishingPocket.PROPOSED)
180@@ -1422,15 +1430,10 @@
181
182 def test_copy_ppa_generates_notification(self):
183 # When a copy into a PPA is performed, a notification is sent.
184- archive = self.test_publisher.ubuntutest.main_archive
185- source = self.test_publisher.getPubSource(
186- archive=archive, version='1.0-2', architecturehintlist='any')
187+ nobby, archive, source = self._setup_archive()
188 changelog = self.factory.makeChangelog(spn="foo", versions=["1.0-2"])
189 source.sourcepackagerelease.changelog = changelog
190- transaction.commit() # Librarian.
191- nobby = self.createNobby(('i386', 'hppa'))
192- getUtility(ISourcePackageFormatSelectionSet).add(
193- nobby, SourcePackageFormat.FORMAT_1_0)
194+ transaction.commit()
195 target_archive = self.factory.makeArchive(
196 distribution=self.test_publisher.ubuntutest)
197 [copied_source] = do_copy(
198@@ -1503,16 +1506,11 @@
199 # If it's a sponsored copy then the From: address on the
200 # notification is changed to the sponsored person and the
201 # SPPH.creator is set to the same person.
202- archive = self.test_publisher.ubuntutest.main_archive
203- source = self.test_publisher.getPubSource(
204- archive=archive, version='1.0-2', architecturehintlist='any')
205+ nobby, archive, source = self._setup_archive()
206 changelog = self.factory.makeChangelog(spn="foo", versions=["1.0-2"])
207 source.sourcepackagerelease.changelog = changelog
208 # Copying to a primary archive reads the changes to close bugs.
209 transaction.commit()
210- nobby = self.createNobby(('i386', 'hppa'))
211- getUtility(ISourcePackageFormatSelectionSet).add(
212- nobby, SourcePackageFormat.FORMAT_1_0)
213 nobby.changeslist = 'nobby-changes@example.com'
214 sponsored_person = self.factory.makePerson(
215 displayname="Sponsored", email="sponsored@example.com")
216@@ -1526,6 +1524,24 @@
217 'Sponsored <sponsored@example.com>', announcement['From'])
218 self.assertEqual(sponsored_person, copied_source.creator)
219
220+ def test_sponsored_copy_sponsor_field(self):
221+ # If it's a sponsored copy then the SPPH's sponsored field is set to
222+ # the user who sponsored the copy.
223+ nobby, archive, source = self._setup_archive()
224+ changelog = self.factory.makeChangelog(spn="foo", versions=["1.0-2"])
225+ source.sourcepackagerelease.changelog = changelog
226+ # Copying to a primary archive reads the changes to close bugs.
227+ transaction.commit()
228+ sponsored_person = self.factory.makePerson(
229+ displayname="Sponsored", email="sponsored@example.com")
230+ [copied_source] = do_copy(
231+ [source], archive, nobby, source.pocket, False,
232+ person=source.sourcepackagerelease.creator,
233+ check_permissions=False, send_email=True,
234+ sponsored=sponsored_person)
235+ self.assertEqual(source.sourcepackagerelease.creator,
236+ copied_source.sponsor)
237+
238 def test_copy_notification_contains_aggregate_change_log(self):
239 # When copying a package that generates a notification,
240 # the changelog should contain all of the changelog_entry texts for
241@@ -1567,14 +1583,7 @@
242 def test_copy_generates_rejection_email(self):
243 # When a copy into a primary archive fails, we expect a rejection
244 # email if the send_email parameter is True.
245- archive = self.test_publisher.ubuntutest.main_archive
246- source = self.test_publisher.getPubSource(
247- archive=archive, version='1.0-2', architecturehintlist='any')
248- source.sourcepackagerelease.changelog_entry = '* Foo!'
249- transaction.commit() # Librarian.
250- nobby = self.createNobby(('i386', 'hppa'))
251- getUtility(ISourcePackageFormatSelectionSet).add(
252- nobby, SourcePackageFormat.FORMAT_1_0)
253+ nobby, archive, source = self._setup_archive()
254 # Ensure the same source is already in the destination so that we
255 # get a rejection.
256 self.test_publisher.getPubSource(
257@@ -1602,15 +1611,9 @@
258 self.assertIn(expected_text, notification.as_string())
259
260 def test_copy_does_not_generate_notification(self):
261- # When notify = False is passed to do_copy, no notification is
262+ # When send_email = False is passed to do_copy, no notification is
263 # generated.
264- archive = self.test_publisher.ubuntutest.main_archive
265- source = self.test_publisher.getPubSource(
266- archive=archive, version='1.0-2', architecturehintlist='any')
267- source.sourcepackagerelease.changelog_entry = '* Foo!'
268- nobby = self.createNobby(('i386', 'hppa'))
269- getUtility(ISourcePackageFormatSelectionSet).add(
270- nobby, SourcePackageFormat.FORMAT_1_0)
271+ nobby, archive, source = self._setup_archive()
272 target_archive = self.factory.makeArchive(
273 distribution=self.test_publisher.ubuntutest)
274 [copied_source] = do_copy(
275@@ -1645,13 +1648,7 @@
276 def test_copy_sets_creator(self):
277 # The creator for the copied SPPH is the person passed
278 # to do_copy.
279- archive = self.test_publisher.ubuntutest.main_archive
280- source = self.test_publisher.getPubSource(
281- archive=archive, version='1.0-2', architecturehintlist='any')
282- source.sourcepackagerelease.changelog_entry = '* Foo!'
283- nobby = self.createNobby(('i386', 'hppa'))
284- getUtility(ISourcePackageFormatSelectionSet).add(
285- nobby, SourcePackageFormat.FORMAT_1_0)
286+ nobby, archive, source = self._setup_archive()
287 target_archive = self.factory.makeArchive(
288 distribution=self.test_publisher.ubuntutest)
289 [copied_source] = do_copy(
290@@ -1663,6 +1660,20 @@
291 target_archive.owner,
292 copied_source.creator)
293
294+ def test_unsponsored_copy_does_not_set_sponsor(self):
295+ # If the copy is not sponsored, SPPH.sponsor is none
296+ nobby, archive, source = self._setup_archive()
297+ target_archive = self.factory.makeArchive(
298+ distribution=self.test_publisher.ubuntutest)
299+ [copied_source] = do_copy(
300+ [source], target_archive, nobby, source.pocket, False,
301+ person=target_archive.owner, check_permissions=False,
302+ send_email=False)
303+
304+ self.assertEqual(
305+ copied_source.sponsor,
306+ None)
307+
308
309 class TestDoDelayedCopy(TestCaseWithFactory, BaseDoCopyTests):
310
311
312=== modified file 'lib/lp/soyuz/stories/webservice/xx-source-package-publishing.txt'
313--- lib/lp/soyuz/stories/webservice/xx-source-package-publishing.txt 2011-12-24 17:49:30 +0000
314+++ lib/lp/soyuz/stories/webservice/xx-source-package-publishing.txt 2012-01-20 13:35:27 +0000
315@@ -138,6 +138,7 @@
316 self_link: u'http://.../~cprov/+archive/ppa/+sourcepub/...'
317 source_package_name: u'testwebservice'
318 source_package_version: u'666'
319+ sponsor_link: None
320 status: u'Pending'
321
322 >>> webservice.named_get(