← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~sinzui/launchpad/ask-question-from-bug into lp:launchpad

 

Curtis Hovey has proposed merging lp:~sinzui/launchpad/ask-question-from-bug into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~sinzui/launchpad/ask-question-from-bug/+merge/77562

Disable ask/convert to question in Bugs when the project does not use Answers.

    Launchpad bug: https://bugs.launchpad.net/bugs/860565
    Pre-implementation: No one

If some project has not enabled answers then user still can ask questions
clicking on Bugs tab using the "Ask a question" link.

I saw this bug reported and knew it could be fixed in a few minutes. I also
realised that the convert to question rules probably ignored Answers too.

--------------------------------------------------------------------

RULES

    * Update the view to return None for the addquestion URL when the
      pillar does not use Answers.
    * Update the canBeAQuestion() method to check that the pillar uses
      answers.


QA

    * Visit https://bugs.qastaging.launchpad.net/bzr-tiplog
    * Verify "Ask a question" is not an action in the side bar.
    * Visit any bug with only one task
    * Verify the "Convert to question" action is not in the side bar.


LINT

    lib/lp/bugs/browser/bugtask.py
    lib/lp/bugs/browser/tests/test_buglisting.py
    lib/lp/bugs/model/bug.py
    lib/lp/bugs/tests/bugtarget-questiontarget.txt
    lib/lp/bugs/tests/test_bugtarget.py


TEST


    ./bin/test -vvc -t TestBugTaskSearchListingViewProduct \
        lp.bugs.browser.tests.test_buglisting
    ./bin/test -vvc lp.bugs.tests.test_bugtarget


IMPLEMENTATION

Return None for in addquestion_url() when the pillar does not use Answers.
    lib/lp/bugs/browser/bugtask.py
    lib/lp/bugs/browser/tests/test_buglisting.py

Return False for in canBeAQuestion() when the pillar does not use Answers.
Adding a new test to bugtarget-questiontarget.txt broke the mail checks in
the test. I decided to replace the section in the doctest with a unittest.
    lib/lp/bugs/model/bug.py
    lib/lp/bugs/tests/bugtarget-questiontarget.txt
    lib/lp/bugs/tests/test_bugtarget.py
-- 
https://code.launchpad.net/~sinzui/launchpad/ask-question-from-bug/+merge/77562
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~sinzui/launchpad/ask-question-from-bug into lp:launchpad.
=== modified file 'lib/lp/bugs/browser/bugtask.py'
--- lib/lp/bugs/browser/bugtask.py	2011-09-28 03:37:44 +0000
+++ lib/lp/bugs/browser/bugtask.py	2011-09-29 15:43:27 +0000
@@ -3057,8 +3057,11 @@
     def addquestion_url(self):
         """Return the URL for the +addquestion view for the context."""
         if IQuestionTarget.providedBy(self.context):
-            return canonical_url(
-                self.context, rootsite='answers', view_name='+addquestion')
+            answers_usage = IServiceUsage(self.context).answers_usage
+            if answers_usage == ServiceUsage.LAUNCHPAD:
+                return canonical_url(
+                    self.context, rootsite='answers',
+                    view_name='+addquestion')
         else:
             return None
 

=== modified file 'lib/lp/bugs/browser/tests/test_buglisting.py'
--- lib/lp/bugs/browser/tests/test_buglisting.py	2011-09-07 15:40:13 +0000
+++ lib/lp/bugs/browser/tests/test_buglisting.py	2011-09-29 15:43:27 +0000
@@ -248,6 +248,26 @@
             bug_target.ubuntu_packages[0], force_local_path=True)
         self.assertEqual(link, content.a['href'])
 
+    def test_ask_question_does_not_use_launchpad(self):
+        bug_target = self._makeBugTargetProduct(
+            bug_tracker='launchpad', packaging=True)
+        login_person(bug_target.owner)
+        bug_target.official_answers = False
+        view = create_initialized_view(
+            bug_target, '+bugs', principal=bug_target.owner)
+        self.assertEqual(None, view.addquestion_url)
+
+    def test_ask_question_uses_launchpad(self):
+        bug_target = self._makeBugTargetProduct(
+            bug_tracker='launchpad', packaging=True)
+        login_person(bug_target.owner)
+        bug_target.official_answers = True
+        view = create_initialized_view(
+            bug_target, '+bugs', principal=bug_target.owner)
+        url = canonical_url(
+            bug_target, rootsite='answers', view_name='+addquestion')
+        self.assertEqual(url, view.addquestion_url)
+
 
 class TestBugTaskSearchListingViewDSP(BugTargetTestCase):
 

=== modified file 'lib/lp/bugs/model/bug.py'
--- lib/lp/bugs/model/bug.py	2011-09-27 14:59:19 +0000
+++ lib/lp/bugs/model/bug.py	2011-09-29 15:43:27 +0000
@@ -1387,7 +1387,9 @@
         if len(non_invalid_bugtasks) != 1:
             return None
         [valid_bugtask] = non_invalid_bugtasks
-        if valid_bugtask.pillar.bug_tracking_usage == ServiceUsage.LAUNCHPAD:
+        pillar = valid_bugtask.pillar
+        if (pillar.bug_tracking_usage == ServiceUsage.LAUNCHPAD
+            and pillar.answers_usage == ServiceUsage.LAUNCHPAD):
             return valid_bugtask
         else:
             return None
@@ -1660,8 +1662,9 @@
         f_flag_str = 'disclosure.enhanced_private_bug_subscriptions.enabled'
         f_flag = bool(getFeatureFlag(f_flag_str))
         if f_flag:
-            # Before we update the privacy or security_related status, we need to
-            # reconcile the subscribers to avoid leaking private information.
+            # Before we update the privacy or security_related status, we
+            # need to reconcile the subscribers to avoid leaking private
+            # information.
             if (self.private != private
                     or self.security_related != security_related):
                 self.reconcileSubscribers(private, security_related, who)

=== modified file 'lib/lp/bugs/tests/bugtarget-questiontarget.txt'
--- lib/lp/bugs/tests/bugtarget-questiontarget.txt	2011-04-21 21:37:28 +0000
+++ lib/lp/bugs/tests/bugtarget-questiontarget.txt	2011-09-29 15:43:27 +0000
@@ -52,21 +52,6 @@
     >>> bug.canBeAQuestion()
     True
 
-A Firefox bug in Debian cannot be converted to a question because the
-distribution does not use Launchpad to track bugs.
-
-    >>> from lp.bugs.interfaces.bug import IBugSet
-    >>> firefox_bug = getUtility(IBugSet).get(8)
-    >>> firefox = firefox_bug.bugtasks[0].target
-    >>> IQuestionTarget.providedBy(firefox)
-    True
-
-    >>> firefox.distribution.bug_tracking_usage
-    <DBItem ServiceUsage.UNKNOWN, (10) Unknown>
-
-    >>> firefox_bug.canBeAQuestion()
-    False
-
 
 convertToQuestion()
 -------------------

=== modified file 'lib/lp/bugs/tests/test_bugtarget.py'
--- lib/lp/bugs/tests/test_bugtarget.py	2011-08-01 05:25:59 +0000
+++ lib/lp/bugs/tests/test_bugtarget.py	2011-09-29 15:43:27 +0000
@@ -178,6 +178,36 @@
     test.globs['question_target'] = ubuntu.getSourcePackage('mozilla-firefox')
 
 
+class BugTargetQuestionTargetTestCase(TestCaseWithFactory):
+    """Converting a bug into a question."""
+
+    layer = DatabaseFunctionalLayer
+
+    def test_canBeAQuestion_does_not_use_bugs(self):
+        bug = self.factory.makeBug()
+        pillar = bug.bugtasks[0].pillar
+        with person_logged_in(pillar.owner):
+            pillar.official_malone = False
+            pillar.official_answers = True
+        self.assertFalse(bug.canBeAQuestion())
+
+    def test_canBeAQuestion_does_not_use_answers(self):
+        bug = self.factory.makeBug()
+        pillar = bug.bugtasks[0].pillar
+        with person_logged_in(pillar.owner):
+            pillar.official_malone = True
+            pillar.official_answers = False
+        self.assertFalse(bug.canBeAQuestion())
+
+    def test_canBeAQuestion_uses_answers_and_bugs(self):
+        bug = self.factory.makeBug()
+        pillar = bug.bugtasks[0].pillar
+        with person_logged_in(pillar.owner):
+            pillar.official_malone = True
+            pillar.official_answers = True
+        self.assertTrue(bug.canBeAQuestion())
+
+
 class TestBugTargetSearchTasks(TestCaseWithFactory):
     """Tests of IHasBugs.searchTasks()."""