← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/git-repository-target-widget-dsp-vocab into lp:launchpad.

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

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #42298 in Launchpad itself: "package picker lists unpublished (invalid) packages"
  https://bugs.launchpad.net/launchpad/+bug/42298

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/git-repository-target-widget-dsp-vocab/+merge/305162

Convert GitRepositoryTargetWidget to use the DistributionSourcePackage picker if the appropriate feature flag is set.  This is pretty much the same as in LaunchpadTargetWidget.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/git-repository-target-widget-dsp-vocab into lp:launchpad.
=== 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 @@
-# Copyright 2015 Canonical Ltd.  This software is licensed under the
+# Copyright 2015-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -41,6 +41,7 @@
     )
 from lp.registry.interfaces.person import IPerson
 from lp.registry.interfaces.product import IProduct
+from lp.services.features import getFeatureFlag
 from lp.services.webapp.interfaces import (
     IAlwaysSubmittedWidget,
     IMultiLineWidgetLayout,
@@ -57,6 +58,12 @@
     def setUpSubWidgets(self):
         if self._widgets_set_up:
             return
+        if bool(getFeatureFlag("disclosure.dsp_picker.enabled")):
+            # Replace the default field with a field that uses the better
+            # vocabulary.
+            package_vocab = "DistributionSourcePackage"
+        else:
+            package_vocab = "BinaryAndSourcePackageName"
         fields = [
             Choice(
                 __name__="project", title=u"Project",
@@ -67,7 +74,7 @@
                 default=getUtility(ILaunchpadCelebrities).ubuntu),
             Choice(
                 __name__="package", title=u"Package",
-                required=False, vocabulary="BinaryAndSourcePackageName"),
+                required=False, vocabulary=package_vocab),
             ]
         if not self._read_only:
             self.distribution_widget = CustomWidgetFactory(
@@ -182,6 +189,9 @@
                         "Launchpad" % entered_name))
             try:
                 if self.package_widget.hasInput():
+                    if bool(getFeatureFlag('disclosure.dsp_picker.enabled')):
+                        self.package_widget.vocabulary.setDistribution(
+                            distribution)
                     package_name = self.package_widget.getInputValue()
                 else:
                     package_name = None

=== 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 @@
-# Copyright 2015 Canonical Ltd.  This software is licensed under the
+# Copyright 2015-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -24,9 +24,11 @@
     GitRepositoryTargetWidget,
     )
 from lp.registry.vocabularies import (
+    DistributionSourcePackageVocabulary,
     DistributionVocabulary,
     ProductVocabulary,
     )
+from lp.services.features.testing import FeatureFixture
 from lp.services.webapp.escaping import html_escape
 from lp.services.webapp.servers import LaunchpadTestRequest
 from lp.soyuz.model.binaryandsourcepackagename import (
@@ -78,7 +80,7 @@
         # The render template is setup.
         self.assertTrue(
             self.widget.template.filename.endswith("gitrepository-target.pt"),
-            "Template was not setup.")
+            "Template was not set up.")
 
     def test_default_option(self):
         # This project field is the default option.
@@ -107,6 +109,15 @@
         self.assertIsNone(getattr(self.widget, "package_widget", None))
         self.assertIsNone(getattr(self.widget, "project_widget", None))
 
+    def test_setUpSubWidgets_dsp_picker_feature_flag(self):
+        # The DistributionSourcePackageVocabulary is used when the
+        # disclosure.dsp_picker.enabled is true.
+        with FeatureFixture({u"disclosure.dsp_picker.enabled": u"on"}):
+            self.widget.setUpSubWidgets()
+        self.assertIsInstance(
+            self.widget.package_widget.context.vocabulary,
+            DistributionSourcePackageVocabulary)
+
     def test_setUpOptions_default_project_checked(self):
         # The radio button options are composed of the setup widgets with
         # the project widget set as the default.
@@ -323,6 +334,16 @@
         self.widget.request = LaunchpadTestRequest(form=form)
         self.assertEqual(self.package, self.widget.getInputValue())
 
+    def test_getInputValue_package_dsp_dsp_picker_feature_flag(self):
+        # The field value is the package when the package radio button
+        # is selected and the package sub field has valid input.
+        form = self.form
+        form["field.target"] = "package"
+        self.widget.request = LaunchpadTestRequest(form=form)
+        with FeatureFixture({u"disclosure.dsp_picker.enabled": u"on"}):
+            self.widget.setUpSubWidgets()
+            self.assertEqual(self.package, self.widget.getInputValue())
+
     def test_getInputValue_package_invalid(self):
         # An error is raised when the package is not published in the distro.
         form = self.form


Follow ups