Merge lp:~stevenk/launchpad/queue-no-changes into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 13455
Proposed branch: lp:~stevenk/launchpad/queue-no-changes
Merge into: lp:launchpad
Diff against target: 72 lines (+24/-1)
4 files modified
lib/lp/soyuz/adapters/notification.py (+2/-0)
lib/lp/soyuz/adapters/tests/test_notification.py (+9/-0)
lib/lp/soyuz/model/queue.py (+6/-1)
lib/lp/soyuz/tests/test_packageupload.py (+7/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/queue-no-changes
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+67913@code.launchpad.net

Commit message

[r=julian-edwards][bug=810355] Support rejecting PackageUploads that have no changes file associated with them.

Description of the change

Support rejecting PackageUploads that have no changes file associated with them.

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Thanks for making this fix Steve. Just a couple of small suggestions:

8 + if not changesfile_object:

This violates our coding style, using "is not None" if you mean that.

22 + if self.changesfile:

Same thing here.

Also you need an extra unit test for the notify() change.

review: Needs Fixing
Revision history for this message
Robert Collins (lifeless) wrote :

On Thu, Jul 14, 2011 at 9:58 PM, Julian Edwards
<email address hidden> wrote:
> Review: Needs Fixing
> Thanks for making this fix Steve.  Just a couple of small suggestions:
>
> 8       + if not changesfile_object:
>
> This violates our coding style, using "is not None" if you mean that.

Not anymore. We fixed that in Texas.
"Truth conditionals
Remember that False, None, [], and 0 are not the same although they
all evaluate to False in a boolean context. If this matters in your
code, be sure to check explicitly for either of them.

Also, checking the length may be an expensive operation. Casting to
bool may avoid this if the object specializes by implementing
nonzero."

> 22      + if self.changesfile:
>
> Same thing here.

-Rob

Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Thursday 14 July 2011 11:16:30 you wrote:
> > 8 + if not changesfile_object:
> >
> > This violates our coding style, using "is not None" if you mean that.
>
> Not anymore. We fixed that in Texas.
> "Truth conditionals
> Remember that False, None, [], and 0 are not the same although they
> all evaluate to False in a boolean context. If this matters in your
> code, be sure to check explicitly for either of them.

Why was this not advertised more widely?

Revision history for this message
Julian Edwards (julian-edwards) wrote :

Make the test check for no email getting sent, and then it's r=me. Checking debug output is a little unhealthy :)

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/adapters/notification.py'
2--- lib/lp/soyuz/adapters/notification.py 2011-06-14 20:45:03 +0000
3+++ lib/lp/soyuz/adapters/notification.py 2011-07-18 02:47:35 +0000
4@@ -160,6 +160,8 @@
5 if spr is None and not bprs and not customfiles:
6 # We do not have enough context to do a normal notification, so
7 # reject what we do have.
8+ if changesfile_object is None:
9+ return
10 reject_changes_file(
11 blamer, changesfile_object.name, changes, archive, distroseries,
12 summary_text, logger=logger)
13
14=== modified file 'lib/lp/soyuz/adapters/tests/test_notification.py'
15--- lib/lp/soyuz/adapters/tests/test_notification.py 2011-06-14 20:45:03 +0000
16+++ lib/lp/soyuz/adapters/tests/test_notification.py 2011-07-18 02:47:35 +0000
17@@ -155,6 +155,15 @@
18 self.assertIn(
19 'No recipients have a preferred email.', logger.getLogBuffer())
20
21+ def test_reject_with_no_changes(self):
22+ # If we don't have any files and no changes content, nothing happens.
23+ archive = self.factory.makeArchive()
24+ distroseries = self.factory.makeDistroSeries()
25+ pocket = self.factory.getAnyPocket()
26+ notify(None, None, (), (), archive, distroseries, pocket)
27+ notifications = pop_notifications()
28+ self.assertEqual(0, len(notifications))
29+
30 def _run_recipients_test(self, changes, blamer, maintainer, changer):
31 distribution = self.factory.makeDistribution()
32 archive = self.factory.makeArchive(
33
34=== modified file 'lib/lp/soyuz/model/queue.py'
35--- lib/lp/soyuz/model/queue.py 2011-07-07 10:31:38 +0000
36+++ lib/lp/soyuz/model/queue.py 2011-07-18 02:47:35 +0000
37@@ -562,7 +562,10 @@
38 # don't think we need them for sync rejections.
39 return
40
41- changes_file_object = StringIO.StringIO(self.changesfile.read())
42+ if self.changesfile is None:
43+ changes_file_object = None
44+ else:
45+ changes_file_object = StringIO.StringIO(self.changesfile.read())
46 # We allow unsigned uploads since they come from the librarian,
47 # which are now stored unsigned.
48 self.notify(
49@@ -824,6 +827,8 @@
50 def _getChangesDict(self, changes_file_object=None):
51 """Return a dictionary with changes file tags in it."""
52 if changes_file_object is None:
53+ if self.changesfile is None:
54+ return {}, ''
55 changes_file_object = self.changesfile
56 changes_content = changes_file_object.read()
57
58
59=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
60--- lib/lp/soyuz/tests/test_packageupload.py 2011-07-11 08:31:46 +0000
61+++ lib/lp/soyuz/tests/test_packageupload.py 2011-07-18 02:47:35 +0000
62@@ -838,3 +838,10 @@
63 self.assertEqual(
64 list(reversed(ordered_uploads)),
65 list(getUtility(IPackageUploadSet).getAll(series)))
66+
67+ def test_rejectFromQueue_no_changes_file(self):
68+ # If the PackageUpload has no changesfile, we can still reject it.
69+ pu = self.factory.makePackageUpload()
70+ pu.changesfile = None
71+ pu.rejectFromQueue()
72+ self.assertEqual(PackageUploadStatus.REJECTED, pu.status)