← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/global-bugs-search into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/global-bugs-search into lp:launchpad.

Commit message:
Export MaloneApplication.searchTasks on the webservice.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #434244 in Launchpad itself: "No search method on bugs collection in API"
  https://bugs.launchpad.net/launchpad/+bug/434244

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/global-bugs-search/+merge/324122

MaloneApplication was very close to being a valid IHasBugs implementation, so I just adjusted things a little until it actually is one.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/global-bugs-search into lp:launchpad.
=== modified file 'lib/lp/bugs/interfaces/malone.py'
--- lib/lp/bugs/interfaces/malone.py	2013-01-07 02:40:55 +0000
+++ lib/lp/bugs/interfaces/malone.py	2017-05-16 16:46:25 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Interfaces pertaining to the launchpad Malone application."""
@@ -20,7 +20,10 @@
 from zope.interface import Attribute
 
 from lp.bugs.interfaces.bug import IBug
-from lp.bugs.interfaces.bugtarget import IBugTarget
+from lp.bugs.interfaces.bugtarget import (
+    IBugTarget,
+    IHasBugs,
+    )
 from lp.services.webapp.interfaces import ILaunchpadApplication
 
 
@@ -30,13 +33,10 @@
     ]
 
 
-class IMaloneApplication(ILaunchpadApplication):
+class IMaloneApplication(ILaunchpadApplication, IHasBugs):
     """Application root for malone."""
     export_as_webservice_collection(IBug)
 
-    def searchTasks(search_params):
-        """Search IBugTasks with the given search parameters."""
-
     @call_with(user=REQUEST_USER)
     @operation_parameters(
         bug_id=copy_field(IBug['id']),

=== modified file 'lib/lp/bugs/tests/test_searchtasks_webservice.py'
--- lib/lp/bugs/tests/test_searchtasks_webservice.py	2012-10-09 10:28:02 +0000
+++ lib/lp/bugs/tests/test_searchtasks_webservice.py	2017-05-16 16:46:25 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Webservice unit tests related to Launchpad Bugs."""
@@ -124,6 +124,29 @@
         self.assertEqual(response['total_size'], 2)
 
 
+class TestMaloneApplicationSearchTasks(TestCaseWithFactory):
+    """Test the searchTasks operation on the top-level /bugs collection."""
+
+    layer = DatabaseFunctionalLayer
+
+    def test_global_search_by_tag(self):
+        project1 = self.factory.makeProduct()
+        project2 = self.factory.makeProduct()
+        bug1 = self.factory.makeBug(target=project1, tags=["foo"])
+        self.factory.makeBug(target=project1, tags=["bar"])
+        bug3 = self.factory.makeBug(target=project2, tags=["foo"])
+        self.factory.makeBug(target=project2, tags=["baz"])
+        webservice = LaunchpadWebServiceCaller(
+            "launchpad-library", "salgado-change-anything")
+        response = webservice.named_get(
+            "/bugs", "searchTasks", api_version="devel", tags="foo").jsonBody()
+        self.assertEqual(2, response["total_size"])
+        self.assertContentEqual(
+            [bug1.id, bug3.id],
+            [int(entry["bug_link"].split("/")[-1])
+             for entry in response["entries"]])
+
+
 class TestGetBugData(TestCaseWithFactory):
     """Tests for the /bugs getBugData operation."""
 

=== modified file 'lib/lp/systemhomes.py'
--- lib/lp/systemhomes.py	2015-07-08 16:05:11 +0000
+++ lib/lp/systemhomes.py	2017-05-16 16:46:25 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Content classes for the 'home pages' of the subsystems of Launchpad."""
@@ -40,6 +40,7 @@
     IPrivateMaloneApplication,
     )
 from lp.bugs.model.bug import Bug
+from lp.bugs.model.bugtarget import HasBugsBase
 from lp.code.interfaces.codehosting import (
     IBazaarApplication,
     ICodehostingApplication,
@@ -117,14 +118,18 @@
 
 
 @implementer(IMaloneApplication)
-class MaloneApplication:
+class MaloneApplication(HasBugsBase):
 
     def __init__(self):
         self.title = 'Malone: the Launchpad bug tracker'
 
-    def searchTasks(self, search_params):
-        """See `IMaloneApplication`."""
-        return getUtility(IBugTaskSet).search(search_params)
+    def _customizeSearchParams(self, search_params):
+        """See `HasBugsBase`."""
+        pass
+
+    def getBugSummaryContextWhereClause(self):
+        """See `HasBugsBase`."""
+        return True
 
     def getBugData(self, user, bug_id, related_bug=None):
         """See `IMaloneApplication`."""


References