Merge lp:~cjwatson/launchpad/git-repository-target-widget-dsp-vocab into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18185
Proposed branch: lp:~cjwatson/launchpad/git-repository-target-widget-dsp-vocab
Merge into: lp:launchpad
Diff against target: 113 lines (+35/-4)
2 files modified
lib/lp/code/browser/widgets/gitrepositorytarget.py (+12/-2)
lib/lp/code/browser/widgets/tests/test_gitrepositorytargetwidget.py (+23/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-repository-target-widget-dsp-vocab
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+305162@code.launchpad.net

Commit message

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

Description of the change

Convert GitRepositoryTargetWidget to use the DistributionSourcePackage picker if the appropriate feature flag is set. This is pretty much the same as in LaunchpadTargetWidget.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)
Revision history for this message
William Grant (wgrant) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/browser/widgets/gitrepositorytarget.py'
--- lib/lp/code/browser/widgets/gitrepositorytarget.py 2015-07-08 16:05:11 +0000
+++ lib/lp/code/browser/widgets/gitrepositorytarget.py 2016-09-08 02:59:42 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015 Canonical Ltd. This software is licensed under the1# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -41,6 +41,7 @@
41 )41 )
42from lp.registry.interfaces.person import IPerson42from lp.registry.interfaces.person import IPerson
43from lp.registry.interfaces.product import IProduct43from lp.registry.interfaces.product import IProduct
44from lp.services.features import getFeatureFlag
44from lp.services.webapp.interfaces import (45from lp.services.webapp.interfaces import (
45 IAlwaysSubmittedWidget,46 IAlwaysSubmittedWidget,
46 IMultiLineWidgetLayout,47 IMultiLineWidgetLayout,
@@ -57,6 +58,12 @@
57 def setUpSubWidgets(self):58 def setUpSubWidgets(self):
58 if self._widgets_set_up:59 if self._widgets_set_up:
59 return60 return
61 if bool(getFeatureFlag("disclosure.dsp_picker.enabled")):
62 # Replace the default field with a field that uses the better
63 # vocabulary.
64 package_vocab = "DistributionSourcePackage"
65 else:
66 package_vocab = "BinaryAndSourcePackageName"
60 fields = [67 fields = [
61 Choice(68 Choice(
62 __name__="project", title=u"Project",69 __name__="project", title=u"Project",
@@ -67,7 +74,7 @@
67 default=getUtility(ILaunchpadCelebrities).ubuntu),74 default=getUtility(ILaunchpadCelebrities).ubuntu),
68 Choice(75 Choice(
69 __name__="package", title=u"Package",76 __name__="package", title=u"Package",
70 required=False, vocabulary="BinaryAndSourcePackageName"),77 required=False, vocabulary=package_vocab),
71 ]78 ]
72 if not self._read_only:79 if not self._read_only:
73 self.distribution_widget = CustomWidgetFactory(80 self.distribution_widget = CustomWidgetFactory(
@@ -182,6 +189,9 @@
182 "Launchpad" % entered_name))189 "Launchpad" % entered_name))
183 try:190 try:
184 if self.package_widget.hasInput():191 if self.package_widget.hasInput():
192 if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
193 self.package_widget.vocabulary.setDistribution(
194 distribution)
185 package_name = self.package_widget.getInputValue()195 package_name = self.package_widget.getInputValue()
186 else:196 else:
187 package_name = None197 package_name = None
188198
=== modified file 'lib/lp/code/browser/widgets/tests/test_gitrepositorytargetwidget.py'
--- lib/lp/code/browser/widgets/tests/test_gitrepositorytargetwidget.py 2016-06-17 15:46:57 +0000
+++ lib/lp/code/browser/widgets/tests/test_gitrepositorytargetwidget.py 2016-09-08 02:59:42 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015 Canonical Ltd. This software is licensed under the1# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -24,9 +24,11 @@
24 GitRepositoryTargetWidget,24 GitRepositoryTargetWidget,
25 )25 )
26from lp.registry.vocabularies import (26from lp.registry.vocabularies import (
27 DistributionSourcePackageVocabulary,
27 DistributionVocabulary,28 DistributionVocabulary,
28 ProductVocabulary,29 ProductVocabulary,
29 )30 )
31from lp.services.features.testing import FeatureFixture
30from lp.services.webapp.escaping import html_escape32from lp.services.webapp.escaping import html_escape
31from lp.services.webapp.servers import LaunchpadTestRequest33from lp.services.webapp.servers import LaunchpadTestRequest
32from lp.soyuz.model.binaryandsourcepackagename import (34from lp.soyuz.model.binaryandsourcepackagename import (
@@ -78,7 +80,7 @@
78 # The render template is setup.80 # The render template is setup.
79 self.assertTrue(81 self.assertTrue(
80 self.widget.template.filename.endswith("gitrepository-target.pt"),82 self.widget.template.filename.endswith("gitrepository-target.pt"),
81 "Template was not setup.")83 "Template was not set up.")
8284
83 def test_default_option(self):85 def test_default_option(self):
84 # This project field is the default option.86 # This project field is the default option.
@@ -107,6 +109,15 @@
107 self.assertIsNone(getattr(self.widget, "package_widget", None))109 self.assertIsNone(getattr(self.widget, "package_widget", None))
108 self.assertIsNone(getattr(self.widget, "project_widget", None))110 self.assertIsNone(getattr(self.widget, "project_widget", None))
109111
112 def test_setUpSubWidgets_dsp_picker_feature_flag(self):
113 # The DistributionSourcePackageVocabulary is used when the
114 # disclosure.dsp_picker.enabled is true.
115 with FeatureFixture({u"disclosure.dsp_picker.enabled": u"on"}):
116 self.widget.setUpSubWidgets()
117 self.assertIsInstance(
118 self.widget.package_widget.context.vocabulary,
119 DistributionSourcePackageVocabulary)
120
110 def test_setUpOptions_default_project_checked(self):121 def test_setUpOptions_default_project_checked(self):
111 # The radio button options are composed of the setup widgets with122 # The radio button options are composed of the setup widgets with
112 # the project widget set as the default.123 # the project widget set as the default.
@@ -323,6 +334,16 @@
323 self.widget.request = LaunchpadTestRequest(form=form)334 self.widget.request = LaunchpadTestRequest(form=form)
324 self.assertEqual(self.package, self.widget.getInputValue())335 self.assertEqual(self.package, self.widget.getInputValue())
325336
337 def test_getInputValue_package_dsp_dsp_picker_feature_flag(self):
338 # The field value is the package when the package radio button
339 # is selected and the package sub field has valid input.
340 form = self.form
341 form["field.target"] = "package"
342 self.widget.request = LaunchpadTestRequest(form=form)
343 with FeatureFixture({u"disclosure.dsp_picker.enabled": u"on"}):
344 self.widget.setUpSubWidgets()
345 self.assertEqual(self.package, self.widget.getInputValue())
346
326 def test_getInputValue_package_invalid(self):347 def test_getInputValue_package_invalid(self):
327 # An error is raised when the package is not published in the distro.348 # An error is raised when the package is not published in the distro.
328 form = self.form349 form = self.form