Merge lp:~stevenk/launchpad/drop-enhanced_choice_popup into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 15802
Proposed branch: lp:~stevenk/launchpad/drop-enhanced_choice_popup
Merge into: lp:launchpad
Diff against target: 266 lines (+65/-100)
5 files modified
lib/lp/app/browser/lazrjs.py (+1/-3)
lib/lp/app/doc/lazr-js-widgets.txt (+0/-59)
lib/lp/app/widgets/tests/test_itemswidgets.py (+64/-24)
lib/lp/bugs/browser/tests/test_bugtarget_filebug.py (+0/-7)
lib/lp/services/features/flags.py (+0/-7)
To merge this branch: bzr merge lp:~stevenk/launchpad/drop-enhanced_choice_popup
Reviewer Review Type Date Requested Status
Ian Booth (community) Approve
Review via email: mp+119461@code.launchpad.net

Commit message

Destroy the disclosure.enhanced_choice_popup.enabled feature flag, it's been turned on by default for a while.

Description of the change

The feature flag disclosure.enhanced_choice_popup.enabled has been turned on by default for a while. Destroy it, and while I'm at it, rip out the doctest for EnumChoiceWidget and move it to the unit test.

To post a comment you must log in.
Revision history for this message
Ian Booth (wallyworld) wrote :

Looks good to go. I'd rename the test case now that new tests are added or even keep the existing test case and add the new tests to a new one in the same module.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/browser/lazrjs.py'
2--- lib/lp/app/browser/lazrjs.py 2012-08-10 04:48:36 +0000
3+++ lib/lp/app/browser/lazrjs.py 2012-08-14 03:55:23 +0000
4@@ -580,9 +580,7 @@
5 if description_fn is None:
6 description_fn = lambda item: getattr(item, 'description', '')
7 description = ''
8- feature_flag = getFeatureFlag(
9- 'disclosure.enhanced_choice_popup.enabled')
10- if include_description and feature_flag:
11+ if include_description:
12 description = description_fn(item)
13 new_item = {
14 'name': name,
15
16=== modified file 'lib/lp/app/doc/lazr-js-widgets.txt'
17--- lib/lp/app/doc/lazr-js-widgets.txt 2012-08-10 04:48:36 +0000
18+++ lib/lp/app/doc/lazr-js-widgets.txt 2012-08-14 03:55:23 +0000
19@@ -356,65 +356,6 @@
20 TextLineEditorWidget above.
21
22
23-EnumChoiceWidget
24-----------------
25-
26-This widget is primarily there allow setting of enum fields easily
27-using the popup chooser.
28-
29- >>> from lp.app.browser.lazrjs import EnumChoiceWidget
30-
31-As with the other widgets, this one requires a context object and a Choice
32-type field. The rendering of the widget hooks up to the lazr ChoiceSource
33-with the standard patch plugin.
34-
35-One of the different things about this widget is the styles that are added.
36-Many enums have specific colour styles. Generally these are the names of
37-the enum values (the upper-case bit) with a defined prefix. This prefix
38-is passed in to the constructor of the widget.
39-
40-A list of items is generated from the vocabulary.
41-
42-If the user does not have edit rights, the widget just renders the text based
43-on the current value of the field on the object:
44-
45- >>> login(ANONYMOUS)
46- >>> from lp.code.interfaces.branch import IBranch
47- >>> branch = factory.makeAnyBranch()
48- >>> widget = EnumChoiceWidget(
49- ... branch, IBranch['lifecycle_status'],
50- ... header='Change status to', css_class_prefix='branchstatus')
51- >>> print widget()
52- <span id="edit-lifecycle_status">
53- <span class="value branchstatusDEVELOPMENT">Development</span>
54- </span>
55-
56-If the user has edit rights, an edit icon is rendered and some javascript is
57-rendered to hook up the widget.
58-
59- >>> ignored = login_person(branch.owner)
60- >>> print widget()
61- <span id="edit-lifecycle_status">
62- <span class="value branchstatusDEVELOPMENT">Development</span>
63- <span>
64- <a class="editicon sprite edit action-icon"
65- href="http://.../+edit"
66- title="">Edit</a>
67- </span>
68- </span>
69- <script>
70- LPJS.use('lp.app.choice', function(Y) {
71- ...
72- </script>
73-
74-
75-Changing the edit link
76-**********************
77-
78-The edit link can be changed in exactly the same way as for the
79-TextLineEditorWidget above.
80-
81-
82 InlineMultiCheckboxWidget
83 -------------------
84
85
86=== modified file 'lib/lp/app/widgets/tests/test_itemswidgets.py'
87--- lib/lp/app/widgets/tests/test_itemswidgets.py 2012-07-26 07:54:40 +0000
88+++ lib/lp/app/widgets/tests/test_itemswidgets.py 2012-08-14 03:55:23 +0000
89@@ -3,9 +3,7 @@
90
91 __metaclass__ = type
92
93-
94 import doctest
95-from unittest import TestCase
96
97 from lazr.enum import (
98 EnumeratedType,
99@@ -22,17 +20,24 @@
100 SimpleVocabulary,
101 )
102
103-from lp.app.browser.lazrjs import vocabulary_to_choice_edit_items
104+from lp.app.browser.lazrjs import (
105+ EnumChoiceWidget,
106+ vocabulary_to_choice_edit_items,
107+ )
108 from lp.app.widgets.itemswidgets import (
109 LabeledMultiCheckBoxWidget,
110 LaunchpadRadioWidget,
111 LaunchpadRadioWidgetWithDescription,
112 PlainMultiCheckBoxWidget,
113 )
114-from lp.services.features.testing import FeatureFixture
115+from lp.code.interfaces.branch import IBranch
116 from lp.services.webapp.menu import structured
117 from lp.services.webapp.servers import LaunchpadTestRequest
118-from lp.testing import TestCaseWithFactory
119+from lp.testing import (
120+ ANONYMOUS,
121+ person_logged_in,
122+ TestCaseWithFactory,
123+ )
124 from lp.testing.layers import DatabaseFunctionalLayer
125
126
127@@ -222,13 +227,8 @@
128 self.assertEqual(expected, hint_html)
129
130
131-class TestVocabularyToChoiceEditItems(TestCase):
132- """Tests for vocabulary_to_choice_edit_items.
133-
134- This function is tested implicitly in lazr-js-widgets.txt.
135- Here we are adding some explicit tests for the behaviour enabled by
136- feature flag disclosure.enhanced_choice_popup.enabled.
137- """
138+class TestEnumChoiceWidget(TestCaseWithFactory):
139+ """Tests for EnumChoiceWidget and vocabulary_to_choice_edit_items."""
140
141 layer = DatabaseFunctionalLayer
142
143@@ -267,21 +267,17 @@
144 self.assertEqual(expected, items)
145
146 def test_vocabulary_to_choice_edit_items_no_description(self):
147- # Even if feature flag is on, there are no descriptions unless wanted.
148- feature_flag = {'disclosure.enhanced_choice_popup.enabled': 'on'}
149- with FeatureFixture(feature_flag):
150- overrides = {'description': ''}
151- items = vocabulary_to_choice_edit_items(self.ChoiceEnum)
152+ # There are no descriptions unless wanted.
153+ overrides = {'description': ''}
154+ items = vocabulary_to_choice_edit_items(self.ChoiceEnum)
155 expected = [self._makeItemDict(e.value, overrides)
156 for e in self.ChoiceEnum]
157 self.assertEqual(expected, items)
158
159 def test_vocabulary_to_choice_edit_items_with_description(self):
160- # The items list is as expected with the feature flag.
161- feature_flag = {'disclosure.enhanced_choice_popup.enabled': 'on'}
162- with FeatureFixture(feature_flag):
163- items = vocabulary_to_choice_edit_items(
164- self.ChoiceEnum, include_description=True)
165+ # The items list is as expected.
166+ items = vocabulary_to_choice_edit_items(
167+ self.ChoiceEnum, include_description=True)
168 expected = [self._makeItemDict(e.value) for e in self.ChoiceEnum]
169 self.assertEqual(expected, items)
170
171@@ -290,6 +286,50 @@
172 items = vocabulary_to_choice_edit_items(
173 self.ChoiceEnum, include_description=True,
174 excluded_items=[self.ChoiceEnum.ITEM_B])
175- overrides = {'description': ''}
176- expected = [self._makeItemDict(self.ChoiceEnum.ITEM_A, overrides)]
177+ expected = [self._makeItemDict(self.ChoiceEnum.ITEM_A)]
178 self.assertEqual(expected, items)
179+
180+ def test_widget_with_anonymous_user(self):
181+ # When the user is anonymous, the widget outputs static text.
182+ branch = self.factory.makeAnyBranch()
183+ widget = EnumChoiceWidget(
184+ branch, IBranch['lifecycle_status'],
185+ header='Change status to', css_class_prefix='branchstatus')
186+ with person_logged_in(ANONYMOUS):
187+ markup = widget()
188+ expected = """
189+ <span id="edit-lifecycle_status">
190+ <span class="value branchstatusDEVELOPMENT">Development</span>
191+ </span>
192+ """
193+ expected_matcher = DocTestMatches(
194+ expected, (doctest.NORMALIZE_WHITESPACE |
195+ doctest.REPORT_NDIFF | doctest.ELLIPSIS))
196+ self.assertThat(markup, expected_matcher)
197+
198+ def test_widget_with_user(self):
199+ # When the user has edit permission, the widget allows changes via JS.
200+ branch = self.factory.makeAnyBranch()
201+ widget = EnumChoiceWidget(
202+ branch, IBranch['lifecycle_status'],
203+ header='Change status to', css_class_prefix='branchstatus')
204+ with person_logged_in(branch.owner):
205+ markup = widget()
206+ expected = """
207+ <span id="edit-lifecycle_status">
208+ <span class="value branchstatusDEVELOPMENT">Development</span>
209+ <span>
210+ <a class="editicon sprite edit action-icon"
211+ href="http://.../+edit"
212+ title="">Edit</a>
213+ </span>
214+ </span>
215+ <script>
216+ LPJS.use('lp.app.choice', function(Y) {
217+ ...
218+ </script>
219+ """
220+ expected_matcher = DocTestMatches(
221+ expected, (doctest.NORMALIZE_WHITESPACE |
222+ doctest.REPORT_NDIFF | doctest.ELLIPSIS))
223+ self.assertThat(markup, expected_matcher)
224
225=== modified file 'lib/lp/bugs/browser/tests/test_bugtarget_filebug.py'
226--- lib/lp/bugs/browser/tests/test_bugtarget_filebug.py 2012-08-03 00:30:51 +0000
227+++ lib/lp/bugs/browser/tests/test_bugtarget_filebug.py 2012-08-14 03:55:23 +0000
228@@ -29,7 +29,6 @@
229 PRIVATE_INFORMATION_TYPES,
230 )
231 from lp.registry.interfaces.projectgroup import IProjectGroup
232-from lp.services.features.testing import FeatureFixture
233 from lp.services.webapp.servers import LaunchpadTestRequest
234 from lp.testing import (
235 login,
236@@ -551,12 +550,6 @@
237
238 layer = DatabaseFunctionalLayer
239
240- def setUp(self):
241- super(TestFileBugRequestCache, self).setUp()
242- self.useFixture(FeatureFixture({
243- 'disclosure.enhanced_choice_popup.enabled': 'true'
244- }))
245-
246 def _assert_cache_values(self, view, duplicate_search, private_bugs=False):
247 cache = IJSONRequestCache(view.request).objects
248 self.assertEqual(
249
250=== modified file 'lib/lp/services/features/flags.py'
251--- lib/lp/services/features/flags.py 2012-08-10 06:38:56 +0000
252+++ lib/lp/services/features/flags.py 2012-08-14 03:55:23 +0000
253@@ -233,13 +233,6 @@
254 '',
255 '',
256 ''),
257- ('disclosure.enhanced_choice_popup.enabled',
258- 'boolean',
259- ('If true, will include any available descriptive text with each choice '
260- 'item in the selection popup.'),
261- '',
262- '',
263- ''),
264 ('disclosure.enhanced_sharing.enabled',
265 'boolean',
266 ('If true, will allow the use of the new sharing view and apis used '