Merge lp:~jtv/launchpad/bug-802840 into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 13372
Proposed branch: lp:~jtv/launchpad/bug-802840
Merge into: lp:launchpad
Diff against target: 103 lines (+49/-9)
4 files modified
lib/lp/soyuz/model/packagecopyjob.py (+4/-8)
lib/lp/soyuz/model/queue.py (+1/-1)
lib/lp/soyuz/tests/test_packagecopyjob.py (+34/-0)
lib/lp/soyuz/tests/test_packageupload.py (+10/-0)
To merge this branch: bzr merge lp:~jtv/launchpad/bug-802840
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+66775@code.launchpad.net

Commit message

Ignore None component/section on sync upload source override.

Description of the change

= Summary =

When setting an override on a sync-type package upload, leaving out the component causes an oops during the component permissions check.

(Background note: an override sets the upload's component and section).

== Proposed fix ==

Treat the None component setting as "no change," which is permitted.

== Pre-implementation notes ==

Discussed with Julian. Proper behaviour is to permit the change as long as the usual permission check on the existing component still passes. If it doesn't, then the entire override attempt will (and should) still fail. There is no similar check for sections; the component permission check basically verifies whether you are allowed to set overrides in the current component.

== Implementation details ==

An "or" in the "if" would have required a line break or a helper variable. I just appended None to the list of valid components.

== Tests ==

{{{
./bin/test -vvc lp.soyuz.tests.test_packagecopyjob -t Override
./bin/test -vvc lp.soyuz.tests.test_packageupload -t Override
}}}

== Demo and Q/A ==

Set an override on a sync-type package upload on the +queue page (you recognize these by the fact that the name of the upload is not a link) but set no component. This should now work.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/soyuz/model/queue.py
  lib/lp/soyuz/model/packagecopyjob.py
  lib/lp/soyuz/tests/test_packagecopyjob.py
  lib/lp/soyuz/tests/test_packageupload.py

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

From IRC:

<gmb> jtv: Lazy reviewer alert: Those tests could do with some leading comments. I know you've tried to make the test names meaningful and descriptive, but it still took me several seconds to parse them, and I'm fundamentally lazy.

Other than that, r=me.

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/soyuz/model/packagecopyjob.py'
2--- lib/lp/soyuz/model/packagecopyjob.py 2011-06-24 06:56:17 +0000
3+++ lib/lp/soyuz/model/packagecopyjob.py 2011-07-05 09:26:17 +0000
4@@ -371,16 +371,12 @@
5
6 def addSourceOverride(self, override):
7 """Add an `ISourceOverride` to the metadata."""
8- component = ""
9- section = ""
10+ metadata_changes = {}
11 if override.component is not None:
12- component = override.component.name
13+ metadata_changes['component_override'] = override.component.name
14 if override.section is not None:
15- section = override.section.name
16- metadata_dict = dict(
17- component_override=component,
18- section_override=section)
19- self.context.extendMetadata(metadata_dict)
20+ metadata_changes['section_override'] = override.section.name
21+ self.context.extendMetadata(metadata_changes)
22
23 def getSourceOverride(self):
24 """Fetch an `ISourceOverride` from the metadata."""
25
26=== modified file 'lib/lp/soyuz/model/queue.py'
27--- lib/lp/soyuz/model/queue.py 2011-06-28 13:30:55 +0000
28+++ lib/lp/soyuz/model/queue.py 2011-07-05 09:26:17 +0000
29@@ -929,7 +929,7 @@
30 # Nothing needs overriding, bail out.
31 return False
32
33- if new_component not in allowed_components:
34+ if new_component not in list(allowed_components) + [None]:
35 raise QueueInconsistentStateError(
36 "No rights to override to %s" % new_component.name)
37
38
39=== modified file 'lib/lp/soyuz/tests/test_packagecopyjob.py'
40--- lib/lp/soyuz/tests/test_packagecopyjob.py 2011-06-24 05:57:31 +0000
41+++ lib/lp/soyuz/tests/test_packagecopyjob.py 2011-07-05 09:26:17 +0000
42@@ -795,6 +795,40 @@
43 section=Equals(metadata_section))
44 self.assertThat(override, matcher)
45
46+ def test_addSourceOverride_accepts_None_component_as_no_change(self):
47+ # When given an override with None as the component,
48+ # addSourceOverride will update the section but not the
49+ # component.
50+ pcj = self.factory.makePlainPackageCopyJob()
51+ old_component = self.factory.makeComponent()
52+ old_section = self.factory.makeSection()
53+ pcj.addSourceOverride(SourceOverride(
54+ source_package_name=pcj.package_name,
55+ component=old_component, section=old_section))
56+ new_section = self.factory.makeSection()
57+ pcj.addSourceOverride(SourceOverride(
58+ source_package_name=pcj.package_name,
59+ component=None, section=new_section))
60+ self.assertEqual(old_component.name, pcj.component_name)
61+ self.assertEqual(new_section.name, pcj.section_name)
62+
63+ def test_addSourceOverride_accepts_None_section_as_no_change(self):
64+ # When given an override with None for the section,
65+ # addSourceOverride will update the component but not the
66+ # section.
67+ pcj = self.factory.makePlainPackageCopyJob()
68+ old_component = self.factory.makeComponent()
69+ old_section = self.factory.makeSection()
70+ pcj.addSourceOverride(SourceOverride(
71+ source_package_name=pcj.package_name,
72+ component=old_component, section=old_section))
73+ new_component = self.factory.makeComponent()
74+ pcj.addSourceOverride(SourceOverride(
75+ source_package_name=pcj.package_name,
76+ component=new_component, section=None))
77+ self.assertEqual(new_component.name, pcj.component_name)
78+ self.assertEqual(old_section.name, pcj.section_name)
79+
80 def test_getSourceOverride(self):
81 # Test the getSourceOverride which gets an ISourceOverride from
82 # the metadata.
83
84=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
85--- lib/lp/soyuz/tests/test_packageupload.py 2011-06-23 13:05:52 +0000
86+++ lib/lp/soyuz/tests/test_packageupload.py 2011-07-05 09:26:17 +0000
87@@ -428,6 +428,16 @@
88 pu.overrideSource,
89 disallowed_component, section, [current_component])
90
91+ def test_overrideSource_ignores_None_component_change(self):
92+ # overrideSource accepts None as a component; it will not object
93+ # based on permissions for the new component.
94+ pu, pcj = self.makeUploadWithPackageCopyJob()
95+ current_component = getUtility(IComponentSet)[pcj.component_name]
96+ new_section = self.factory.makeSection()
97+ pu.overrideSource(None, new_section, [current_component])
98+ self.assertEqual(current_component.name, pcj.component_name)
99+ self.assertEqual(new_section.name, pcj.section_name)
100+
101 def test_acceptFromQueue_with_copy_job(self):
102 # acceptFromQueue should accept the upload and resume the copy
103 # job.