Merge lp:~cjwatson/launchpad/bugtaskeditview-spn-dsp-vocab into lp:launchpad

Proposed by Colin Watson on 2016-07-23
Status: Merged
Merged at revision: 18166
Proposed branch: lp:~cjwatson/launchpad/bugtaskeditview-spn-dsp-vocab
Merge into: lp:launchpad
Prerequisite: lp:~cjwatson/launchpad/fix-dsp-vocab-picker
Diff against target: 173 lines (+70/-16)
3 files modified
lib/lp/bugs/browser/bugtask.py (+27/-4)
lib/lp/bugs/browser/tests/test_bugtask.py (+42/-11)
lib/lp/bugs/browser/widgets/bugtask.py (+1/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/bugtaskeditview-spn-dsp-vocab
Reviewer Review Type Date Requested Status
William Grant code 2016-07-23 Approve on 2016-07-26
Review via email: mp+300975@code.launchpad.net

Commit Message

Convert BugTaskEditView to use the DistributionSourcePackage picker if the appropriate feature flag is set.

Description of the Change

Convert BugTaskEditView to use the DistributionSourcePackage picker if the appropriate feature flag is set.

To post a comment you must log in.
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/bugs/browser/bugtask.py'
2--- lib/lp/bugs/browser/bugtask.py 2016-01-26 15:47:37 +0000
3+++ lib/lp/bugs/browser/bugtask.py 2016-07-23 10:37:37 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """IBugTask-related browser views."""
10@@ -1073,11 +1073,30 @@
11 return self.context.userHasBugSupervisorPrivileges(self.user)
12
13
14+class IBugTaskEditForm(IBugTask):
15+
16+ sourcepackagename = copy_field(
17+ IBugTask['sourcepackagename'],
18+ vocabularyName='DistributionSourcePackage')
19+
20+
21 class BugTaskEditView(LaunchpadEditFormView, BugTaskBugWatchMixin,
22 BugTaskPrivilegeMixin):
23 """The view class used for the task +editstatus page."""
24
25- schema = IBugTask
26+ @property
27+ def schema(self):
28+ """See `LaunchpadFormView`."""
29+ if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
30+ return IBugTaskEditForm
31+ else:
32+ return IBugTask
33+
34+ @property
35+ def adapters(self):
36+ """See `LaunchpadFormView`."""
37+ return {IBugTaskEditForm: self.context}
38+
39 milestone_source = None
40 user_is_subscribed = None
41 edit_form = ViewPageTemplateFile('../templates/bugtask-edit-form.pt')
42@@ -1324,8 +1343,12 @@
43 def validate(self, data):
44 if self.show_sourcepackagename_widget and 'sourcepackagename' in data:
45 data['target'] = self.context.distroseries
46- spn = data.get('sourcepackagename')
47- if spn:
48+ spn_or_dsp = data.get('sourcepackagename')
49+ if spn_or_dsp:
50+ if IDistributionSourcePackage.providedBy(spn_or_dsp):
51+ spn = spn_or_dsp.sourcepackagename
52+ else:
53+ spn = spn_or_dsp
54 data['target'] = data['target'].getSourcePackage(spn)
55 del data['sourcepackagename']
56 error_field = 'sourcepackagename'
57
58=== modified file 'lib/lp/bugs/browser/tests/test_bugtask.py'
59--- lib/lp/bugs/browser/tests/test_bugtask.py 2016-01-26 15:47:37 +0000
60+++ lib/lp/bugs/browser/tests/test_bugtask.py 2016-07-23 10:37:37 +0000
61@@ -1,4 +1,4 @@
62-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
63+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
64 # GNU Affero General Public License version 3 (see the file LICENSE).
65
66 __metaclass__ = type
67@@ -17,6 +17,10 @@
68 from pytz import UTC
69 import simplejson
70 import soupmatchers
71+from testscenarios import (
72+ load_tests_apply_scenarios,
73+ WithScenarios,
74+ )
75 from testtools.matchers import (
76 LessThan,
77 Not,
78@@ -27,6 +31,7 @@
79 getUtility,
80 )
81 from zope.event import notify
82+from zope.formlib.interfaces import ConversionError
83 from zope.interface import providedBy
84 from zope.security.proxy import removeSecurityProxy
85
86@@ -1316,11 +1321,24 @@
87 view.form_fields['assignee'].field.vocabularyName)
88
89
90-class TestBugTaskEditView(TestCaseWithFactory):
91+class TestBugTaskEditView(WithScenarios, TestCaseWithFactory):
92 """Test the bug task edit form."""
93
94 layer = DatabaseFunctionalLayer
95
96+ scenarios = [
97+ ("spn_picker", {"features": {}, "allow_binarypackagename": True}),
98+ ("dsp_picker", {
99+ "features": {u"disclosure.dsp_picker.enabled": u"on"},
100+ "allow_binarypackagename": False,
101+ }),
102+ ]
103+
104+ def setUp(self):
105+ super(TestBugTaskEditView, self).setUp()
106+ if self.features:
107+ self.useFixture(FeatureFixture(self.features))
108+
109 def test_retarget_already_exists_error(self):
110 user = self.factory.makePerson()
111 login_person(user)
112@@ -1448,6 +1466,8 @@
113 def test_retarget_sourcepackage_to_binary_name(self):
114 # The sourcepackagename of a SourcePackage task can be changed
115 # to a binarypackagename, which gets mapped back to the source.
116+ # (This is not allowed for the DistributionSourcePackage picker,
117+ # where the vocabulary takes care of doing an appropriate mapping.)
118 ds = self.factory.makeDistroSeries()
119 das = self.factory.makeDistroArchSeries(distroseries=ds)
120 sp1 = self.factory.makeSourcePackage(distroseries=ds, publish=True)
121@@ -1462,15 +1482,23 @@
122
123 view = self.createNameChangingViewForSourcePackageTask(
124 bug_task, bpr.binarypackagename.name)
125- self.assertEqual([], view.errors)
126- self.assertEqual(sp2, bug_task.target)
127- notifications = view.request.response.notifications
128- self.assertEqual(1, len(notifications))
129- expected = html_escape(
130- "'%s' is a binary package. This bug has been assigned to its "
131- "source package '%s' instead."
132- % (bpr.binarypackagename.name, spn.name))
133- self.assertTrue(notifications.pop().message.startswith(expected))
134+ if self.allow_binarypackagename:
135+ self.assertEqual([], view.errors)
136+ self.assertEqual(sp2, bug_task.target)
137+ notifications = view.request.response.notifications
138+ self.assertEqual(1, len(notifications))
139+ expected = html_escape(
140+ "'%s' is a binary package. This bug has been assigned to its "
141+ "source package '%s' instead."
142+ % (bpr.binarypackagename.name, spn.name))
143+ self.assertTrue(notifications.pop().message.startswith(expected))
144+ else:
145+ self.assertEqual(1, len(view.errors))
146+ self.assertIsInstance(view.errors[0], ConversionError)
147+ self.assertEqual(
148+ "Launchpad doesn't know of any source package named "
149+ "'binarypackage-100413' in Distribution-100372.",
150+ view.errors[0].error_name)
151
152 def test_retarget_sourcepackage_to_distroseries(self):
153 # A SourcePackage task can be changed to a DistroSeries one.
154@@ -2536,3 +2564,6 @@
155 bug.date_last_message = datetime(2001, 1, 1, tzinfo=UTC)
156 self.assertEqual(
157 'on 2001-01-01', item.model['last_updated'])
158+
159+
160+load_tests = load_tests_apply_scenarios
161
162=== modified file 'lib/lp/bugs/browser/widgets/bugtask.py'
163--- lib/lp/bugs/browser/widgets/bugtask.py 2016-07-23 10:37:37 +0000
164+++ lib/lp/bugs/browser/widgets/bugtask.py 2016-07-23 10:37:37 +0000
165@@ -520,7 +520,7 @@
166 try:
167 self.context.vocabulary.setDistribution(distribution)
168 return self.context.vocabulary.getTermByToken(input).value
169- except NotFoundError:
170+ except LookupError:
171 raise ConversionError(
172 "Launchpad doesn't know of any source package named"
173 " '%s' in %s." % (input, distribution.displayname))