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

Proposed by Colin Watson on 2016-09-08
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 2016-09-08 Approve on 2016-09-09
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.
William Grant (wgrant) :
review: Approve (code)
William Grant (wgrant) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/widgets/gitrepositorytarget.py'
2--- lib/lp/code/browser/widgets/gitrepositorytarget.py 2015-07-08 16:05:11 +0000
3+++ lib/lp/code/browser/widgets/gitrepositorytarget.py 2016-09-08 02:59:42 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2015 Canonical Ltd. This software is licensed under the
6+# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 __metaclass__ = type
10@@ -41,6 +41,7 @@
11 )
12 from lp.registry.interfaces.person import IPerson
13 from lp.registry.interfaces.product import IProduct
14+from lp.services.features import getFeatureFlag
15 from lp.services.webapp.interfaces import (
16 IAlwaysSubmittedWidget,
17 IMultiLineWidgetLayout,
18@@ -57,6 +58,12 @@
19 def setUpSubWidgets(self):
20 if self._widgets_set_up:
21 return
22+ if bool(getFeatureFlag("disclosure.dsp_picker.enabled")):
23+ # Replace the default field with a field that uses the better
24+ # vocabulary.
25+ package_vocab = "DistributionSourcePackage"
26+ else:
27+ package_vocab = "BinaryAndSourcePackageName"
28 fields = [
29 Choice(
30 __name__="project", title=u"Project",
31@@ -67,7 +74,7 @@
32 default=getUtility(ILaunchpadCelebrities).ubuntu),
33 Choice(
34 __name__="package", title=u"Package",
35- required=False, vocabulary="BinaryAndSourcePackageName"),
36+ required=False, vocabulary=package_vocab),
37 ]
38 if not self._read_only:
39 self.distribution_widget = CustomWidgetFactory(
40@@ -182,6 +189,9 @@
41 "Launchpad" % entered_name))
42 try:
43 if self.package_widget.hasInput():
44+ if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
45+ self.package_widget.vocabulary.setDistribution(
46+ distribution)
47 package_name = self.package_widget.getInputValue()
48 else:
49 package_name = None
50
51=== modified file 'lib/lp/code/browser/widgets/tests/test_gitrepositorytargetwidget.py'
52--- lib/lp/code/browser/widgets/tests/test_gitrepositorytargetwidget.py 2016-06-17 15:46:57 +0000
53+++ lib/lp/code/browser/widgets/tests/test_gitrepositorytargetwidget.py 2016-09-08 02:59:42 +0000
54@@ -1,4 +1,4 @@
55-# Copyright 2015 Canonical Ltd. This software is licensed under the
56+# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
57 # GNU Affero General Public License version 3 (see the file LICENSE).
58
59 __metaclass__ = type
60@@ -24,9 +24,11 @@
61 GitRepositoryTargetWidget,
62 )
63 from lp.registry.vocabularies import (
64+ DistributionSourcePackageVocabulary,
65 DistributionVocabulary,
66 ProductVocabulary,
67 )
68+from lp.services.features.testing import FeatureFixture
69 from lp.services.webapp.escaping import html_escape
70 from lp.services.webapp.servers import LaunchpadTestRequest
71 from lp.soyuz.model.binaryandsourcepackagename import (
72@@ -78,7 +80,7 @@
73 # The render template is setup.
74 self.assertTrue(
75 self.widget.template.filename.endswith("gitrepository-target.pt"),
76- "Template was not setup.")
77+ "Template was not set up.")
78
79 def test_default_option(self):
80 # This project field is the default option.
81@@ -107,6 +109,15 @@
82 self.assertIsNone(getattr(self.widget, "package_widget", None))
83 self.assertIsNone(getattr(self.widget, "project_widget", None))
84
85+ def test_setUpSubWidgets_dsp_picker_feature_flag(self):
86+ # The DistributionSourcePackageVocabulary is used when the
87+ # disclosure.dsp_picker.enabled is true.
88+ with FeatureFixture({u"disclosure.dsp_picker.enabled": u"on"}):
89+ self.widget.setUpSubWidgets()
90+ self.assertIsInstance(
91+ self.widget.package_widget.context.vocabulary,
92+ DistributionSourcePackageVocabulary)
93+
94 def test_setUpOptions_default_project_checked(self):
95 # The radio button options are composed of the setup widgets with
96 # the project widget set as the default.
97@@ -323,6 +334,16 @@
98 self.widget.request = LaunchpadTestRequest(form=form)
99 self.assertEqual(self.package, self.widget.getInputValue())
100
101+ def test_getInputValue_package_dsp_dsp_picker_feature_flag(self):
102+ # The field value is the package when the package radio button
103+ # is selected and the package sub field has valid input.
104+ form = self.form
105+ form["field.target"] = "package"
106+ self.widget.request = LaunchpadTestRequest(form=form)
107+ with FeatureFixture({u"disclosure.dsp_picker.enabled": u"on"}):
108+ self.widget.setUpSubWidgets()
109+ self.assertEqual(self.package, self.widget.getInputValue())
110+
111 def test_getInputValue_package_invalid(self):
112 # An error is raised when the package is not published in the distro.
113 form = self.form