← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:fix-packagename-option into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:fix-packagename-option into launchpad:master.

Commit message:
Fix handling of packagename_option on DSP:+filebug

If "In what package did you find this bug?" is set to "I don't know" on
DistributionSourcePackage:+filebug, then it's most coherent to treat
that as if the bug had been filed using the corresponding
Distribution:+filebug.

LP: #1847647

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1847647 in Launchpad itself: "DSP:+filebug ignores setting package name to "I don't know""
  https://bugs.launchpad.net/launchpad/+bug/1847647

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/374086
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:fix-packagename-option into launchpad:master.
diff --git a/lib/lp/bugs/browser/bugtarget.py b/lib/lp/bugs/browser/bugtarget.py
index 5915a66..82d49db 100644
--- a/lib/lp/bugs/browser/bugtarget.py
+++ b/lib/lp/bugs/browser/bugtarget.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2019 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """IBugTarget-related browser views."""
@@ -528,6 +528,8 @@ class FileBugViewBase(LaunchpadFormView):
         # enters a package name but then selects "I don't know".
         if self.request.form.get("packagename_option") == "none":
             packagename = None
+            if IDistributionSourcePackage.providedBy(context):
+                context = context.distribution
 
         linkified_ack = structured(FormattersAPI(
             self.getAcknowledgementMessage(self.context)).text_to_html(
diff --git a/lib/lp/bugs/browser/tests/test_bugtarget_filebug.py b/lib/lp/bugs/browser/tests/test_bugtarget_filebug.py
index f6c53ec..3c7946e 100644
--- a/lib/lp/bugs/browser/tests/test_bugtarget_filebug.py
+++ b/lib/lp/bugs/browser/tests/test_bugtarget_filebug.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2016 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2019 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -57,6 +57,7 @@ from lp.testing.pages import (
     find_main_content,
     find_tag_by_id,
     )
+from lp.testing.publication import test_traverse
 from lp.testing.views import (
     create_initialized_view,
     create_view,
@@ -833,6 +834,32 @@ class TestFileBugSourcePackage(WithScenarios, TestCaseWithFactory):
             for notification in view.request.response.notifications])
         self.assertIn("Thank you for your bug report.", msg)
 
+    def test_filebug_packagename_option_none(self):
+        # Setting "In what package did you find this bug?" to "I don't know"
+        # is honoured even if the context is a DistributionSourcePackage.
+        dsp = self.factory.makeDistributionSourcePackage()
+        user = self.factory.makePerson()
+        login_person(user)
+
+        view = create_initialized_view(
+            context=dsp, name='+filebug',
+            form={
+                'field.title': 'A bug',
+                'field.comment': 'A comment',
+                'packagename_option': 'none',
+                'field.packagename': dsp.name,
+                'field.actions.submit_bug': 'Submit Bug Report',
+                }, principal=user)
+        msg = "\n".join([
+            notification.message
+            for notification in view.request.response.notifications])
+        self.assertIn("Thank you for your bug report.", msg)
+
+        login_person(user)
+        bugtask, _, _ = test_traverse(
+            view.request.response.getHeader('Location'))
+        self.assertEqual(dsp.distribution, bugtask.target)
+
 
 class ProjectGroupFileBugGuidedViewTestCase(TestCaseWithFactory):