Merge lp:~cjwatson/launchpad/archive-edit-fix-restricted-processors into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 17781
Proposed branch: lp:~cjwatson/launchpad/archive-edit-fix-restricted-processors
Merge into: lp:launchpad
Diff against target: 167 lines (+60/-38)
2 files modified
lib/lp/soyuz/browser/archive.py (+10/-5)
lib/lp/soyuz/browser/tests/test_archive.py (+50/-33)
To merge this branch: bzr merge lp:~cjwatson/launchpad/archive-edit-fix-restricted-processors
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+272999@code.launchpad.net

Commit message

Ensure that enabled and restricted processors are left untouched when submitting Archive:+edit.

Description of the change

Ensure that enabled and restricted processors are left untouched when submitting Archive:+edit. This is much the same strategy that we use for enabled and unavailable processors.

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/soyuz/browser/archive.py'
2--- lib/lp/soyuz/browser/archive.py 2015-09-23 12:15:53 +0000
3+++ lib/lp/soyuz/browser/archive.py 2015-09-30 23:39:16 +0000
4@@ -2085,12 +2085,17 @@
5 def validate(self, data):
6 if 'processors' in data:
7 available_processors = set(self.context.available_processors)
8+ widget = self.widgets['processors']
9 for processor in self.context.processors:
10- if (processor not in available_processors and
11- processor not in data['processors']):
12- # This processor is not currently available for
13- # selection, but is enabled. Leave it untouched.
14- data['processors'].append(processor)
15+ if processor not in data['processors']:
16+ if processor not in available_processors:
17+ # This processor is not currently available for
18+ # selection, but is enabled. Leave it untouched.
19+ data['processors'].append(processor)
20+ elif processor.name in widget.disabled_items:
21+ # This processor is restricted and currently
22+ # enabled. Leave it untouched.
23+ data['processors'].append(processor)
24
25
26 class ArchiveAdminView(BaseArchiveEditView, EnableProcessorsMixin):
27
28=== modified file 'lib/lp/soyuz/browser/tests/test_archive.py'
29--- lib/lp/soyuz/browser/tests/test_archive.py 2015-09-25 13:54:46 +0000
30+++ lib/lp/soyuz/browser/tests/test_archive.py 2015-09-30 23:39:16 +0000
31@@ -18,6 +18,7 @@
32 from lp.testing import (
33 admin_logged_in,
34 login_person,
35+ person_logged_in,
36 record_two_runs,
37 TestCaseWithFactory,
38 )
39@@ -44,6 +45,20 @@
40 distroseries=self.ubuntu.getSeries("breezy-autotest"),
41 architecturetag="amd64", processor=proc_amd64)
42
43+ def assertArchiveProcessors(self, archive, names):
44+ with person_logged_in(archive.owner):
45+ self.assertContentEqual(
46+ names, [processor.name for processor in archive.processors])
47+
48+ def assertProcessorControls(self, processors_control, enabled, disabled):
49+ matchers = [
50+ MatchesStructure.byEquality(optionValue=name, disabled=False)
51+ for name in enabled]
52+ matchers.extend([
53+ MatchesStructure.byEquality(optionValue=name, disabled=True)
54+ for name in disabled])
55+ self.assertThat(processors_control.controls, MatchesSetwise(*matchers))
56+
57 def test_display_processors(self):
58 ppa = self.factory.makeArchive()
59 owner = login_person(ppa.owner)
60@@ -57,20 +72,14 @@
61
62 def test_edit_processors(self):
63 ppa = self.factory.makeArchive()
64- owner = login_person(ppa.owner)
65- self.assertContentEqual(
66- ["386", "amd64", "hppa"],
67- [processor.name for processor in ppa.processors])
68+ self.assertArchiveProcessors(ppa, ["386", "amd64", "hppa"])
69 browser = self.getUserBrowser(
70- canonical_url(ppa) + "/+edit", user=owner)
71+ canonical_url(ppa) + "/+edit", user=ppa.owner)
72 processors = browser.getControl(name="field.processors")
73 self.assertContentEqual(["386", "amd64", "hppa"], processors.value)
74 processors.value = ["386", "amd64"]
75 browser.getControl("Save").click()
76- login_person(ppa.owner)
77- self.assertContentEqual(
78- ["386", "amd64"],
79- [processor.name for processor in ppa.processors])
80+ self.assertArchiveProcessors(ppa, ["386", "amd64"])
81
82 def test_edit_with_invisible_processor(self):
83 # It's possible for existing archives to have an enabled processor
84@@ -84,19 +93,14 @@
85 proc_armel = self.factory.makeProcessor(
86 name="armel", restricted=True, build_by_default=False)
87 ppa = self.factory.makeArchive()
88- with admin_logged_in():
89- ppa.setProcessors([proc_386, proc_amd64, proc_armel])
90- owner = login_person(ppa.owner)
91+ ppa.setProcessors([proc_386, proc_amd64, proc_armel])
92 browser = self.getUserBrowser(
93- canonical_url(ppa) + "/+edit", user=owner)
94+ canonical_url(ppa) + "/+edit", user=ppa.owner)
95 processors = browser.getControl(name="field.processors")
96 self.assertContentEqual(["386", "amd64"], processors.value)
97 processors.value = ["amd64"]
98 browser.getControl("Save").click()
99- login_person(ppa.owner)
100- self.assertContentEqual(
101- ["amd64", "armel"],
102- [processor.name for processor in ppa.processors])
103+ self.assertArchiveProcessors(ppa, ["amd64", "armel"])
104
105 def test_edit_processors_restricted(self):
106 # A restricted processor is shown disabled in the UI and cannot be
107@@ -108,25 +112,13 @@
108 distroseries=self.ubuntu.getSeries("breezy-autotest"),
109 architecturetag="armhf", processor=proc_armhf)
110 ppa = self.factory.makeArchive()
111- owner = login_person(ppa.owner)
112- self.assertContentEqual(
113- ["386", "amd64", "hppa"],
114- [processor.name for processor in ppa.processors])
115+ self.assertArchiveProcessors(ppa, ["386", "amd64", "hppa"])
116 browser = self.getUserBrowser(
117- canonical_url(ppa) + "/+edit", user=owner)
118+ canonical_url(ppa) + "/+edit", user=ppa.owner)
119 processors = browser.getControl(name="field.processors")
120 self.assertContentEqual(["386", "amd64", "hppa"], processors.value)
121- self.assertThat(
122- processors.controls, MatchesSetwise(
123- MatchesStructure.byEquality(
124- optionValue="386", disabled=False),
125- MatchesStructure.byEquality(
126- optionValue="amd64", disabled=False),
127- MatchesStructure.byEquality(
128- optionValue="armhf", disabled=True),
129- MatchesStructure.byEquality(
130- optionValue="hppa", disabled=False),
131- ))
132+ self.assertProcessorControls(
133+ processors, ["386", "amd64", "hppa"], ["armhf"])
134 # Even if the user works around the disabled checkbox and forcibly
135 # enables it, they can't enable the restricted processor.
136 for control in processors.controls:
137@@ -136,6 +128,31 @@
138 self.assertRaises(
139 CannotModifyArchiveProcessor, browser.getControl("Save").click)
140
141+ def test_edit_processors_restricted_already_enabled(self):
142+ # A restricted processor that is already enabled is shown disabled
143+ # in the UI. This causes form submission to omit it, but the
144+ # validation code fixes that up behind the scenes so that we don't
145+ # get CannotModifyArchiveProcessor.
146+ proc_386 = getUtility(IProcessorSet).getByName("386")
147+ proc_amd64 = getUtility(IProcessorSet).getByName("amd64")
148+ proc_armhf = self.factory.makeProcessor(
149+ name="armhf", restricted=True, build_by_default=False)
150+ self.factory.makeDistroArchSeries(
151+ distroseries=self.ubuntu.getSeries("breezy-autotest"),
152+ architecturetag="armhf", processor=proc_armhf)
153+ ppa = self.factory.makeArchive()
154+ ppa.setProcessors([proc_386, proc_amd64, proc_armhf])
155+ self.assertArchiveProcessors(ppa, ["386", "amd64", "armhf"])
156+ browser = self.getUserBrowser(
157+ canonical_url(ppa) + "/+edit", user=ppa.owner)
158+ processors = browser.getControl(name="field.processors")
159+ self.assertContentEqual(["386", "amd64"], processors.value)
160+ self.assertProcessorControls(
161+ processors, ["386", "amd64", "hppa"], ["armhf"])
162+ processors.value = ["386"]
163+ browser.getControl("Save").click()
164+ self.assertArchiveProcessors(ppa, ["386", "armhf"])
165+
166
167 class TestArchiveCopyPackagesView(TestCaseWithFactory):
168