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