← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~adeuring/launchpad/bug-594247-unittests-for-searchtasks-3 into lp:launchpad/devel

 

Abel Deuring has proposed merging lp:~adeuring/launchpad/bug-594247-unittests-for-searchtasks-3 into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


This branch adds more unit tests for BugTaskSet.search().

I modified the testing factory method makeBug(): It is now possible to pass a distribution as the bug target. Without this change, tests of bug tasks for bugs without an upstream bugtask would have been somehwat pointless: Without this change, any bug created via makeBug() or makeBugTask() has at least one bugtask targeted to a product. In other words, a search for bugtasks without a related upstream task would never return anything.

test: ./bin/test -vvt lp.bugs.tests.test_bugtask_search

no lint
-- 
https://code.launchpad.net/~adeuring/launchpad/bug-594247-unittests-for-searchtasks-3/+merge/39523
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~adeuring/launchpad/bug-594247-unittests-for-searchtasks-3 into lp:launchpad/devel.
=== modified file 'lib/lp/bugs/tests/test_bugtask_search.py'
--- lib/lp/bugs/tests/test_bugtask_search.py	2010-10-22 13:25:22 +0000
+++ lib/lp/bugs/tests/test_bugtask_search.py	2010-10-28 13:06:31 +0000
@@ -14,6 +14,7 @@
     LaunchpadFunctionalLayer,
     )
 
+from lp.bugs.interfaces.bug import CreateBugParams
 from lp.bugs.interfaces.bugattachment import BugAttachmentType
 from lp.bugs.interfaces.bugtask import (
     BugTaskImportance,
@@ -173,6 +174,66 @@
         expected = self.resultValuesForBugtasks(self.bugtasks[:2])
         self.assertEqual(expected, search_result)
 
+    def setUpSearchTests(self):
+        # Set text fields indexed by Bug.fti, BugTask.fti or
+        # MessageChunk.fti to values we can search for.
+        for bugtask, number in zip(self.bugtasks, ('one', 'two', 'three')):
+            commenter = self.bugtasks[0].bug.owner
+            with person_logged_in(commenter):
+                bugtask.statusexplanation = 'status explanation %s' % number
+                bugtask.bug.title = 'bug title %s' % number
+                bugtask.bug.newMessage(
+                    owner=commenter, content='comment %s' % number)
+
+    def test_fulltext_search(self):
+        # Full text searches find text indexed by Bug.fti...
+        self.setUpSearchTests()
+        params = self.getBugTaskSearchParams(user=None, searchtext='one title')
+        search_result = self.runSearch(params)
+        expected = self.resultValuesForBugtasks(self.bugtasks[:1])
+        self.assertEqual(expected, search_result)
+        # ... by BugTask.fti ...
+        params = self.getBugTaskSearchParams(
+            user=None, searchtext='one explanation')
+        search_result = self.runSearch(params)
+        self.assertEqual(expected, search_result)
+        # ...and by MessageChunk.fti
+        params = self.getBugTaskSearchParams(
+            user=None, searchtext='one comment')
+        search_result = self.runSearch(params)
+        self.assertEqual(expected, search_result)
+
+    def test_fast_fulltext_search(self):
+        # Fast full text searches find text indexed by Bug.fti...
+        self.setUpSearchTests()
+        params = self.getBugTaskSearchParams(
+            user=None, fast_searchtext='one title')
+        search_result = self.runSearch(params)
+        expected = self.resultValuesForBugtasks(self.bugtasks[:1])
+        self.assertEqual(expected, search_result)
+        # ... but not text indexed by BugTask.fti ...
+        params = self.getBugTaskSearchParams(
+            user=None, fast_searchtext='one explanation')
+        search_result = self.runSearch(params)
+        self.assertEqual([], search_result)
+        # ..or by MessageChunk.fti
+        params = self.getBugTaskSearchParams(
+            user=None, fast_searchtext='one comment')
+        search_result = self.runSearch(params)
+        self.assertEqual([], search_result)
+
+    def test_has_no_upstream_bugtask(self):
+        # Search results can be limited to bugtasks of bugs that do
+        # not have a related upstream task.
+        #
+        bug = self.makeBugWithOneTarget()
+
+        params = self.getBugTaskSearchParams(
+            user=None, has_no_upstream_bugtask=True)
+        search_result = self.runSearch(params)
+        expected = self.resultValuesForBugtasks(self.bugtasks)
+        self.assertEqual(expected, search_result)
+
 
 class ProductAndDistributionTests:
     """Tests which are useful for distributions and products."""
@@ -203,6 +264,7 @@
     def makeBugTasks(self, bugtarget):
         self.bugtasks = []
         with person_logged_in(self.owner):
+            assert(bug.default_bugtask.target == bugtarget)
             self.bugtasks.append(
                 self.factory.makeBugTask(target=bugtarget))
             self.bugtasks[-1].importance = BugTaskImportance.HIGH
@@ -323,6 +385,8 @@
 
             product = self.factory.makeProduct(owner=self.owner)
             product.project = self.searchtarget
+            self.bugtasks.append(
+                self.factory.makeBugTask(target=product))
             self.bugtasks[-1].importance = BugTaskImportance.LOW
             self.bugtasks[-1].transitionToStatus(
             BugTaskStatus.NEW, self.owner)

=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py	2010-10-27 22:33:01 +0000
+++ lib/lp/testing/factory.py	2010-10-28 13:06:31 +0000
@@ -1333,19 +1333,25 @@
     def makeBug(self, product=None, owner=None, bug_watch_url=None,
                 private=False, date_closed=None, title=None,
                 date_created=None, description=None, comment=None,
-                status=None):
+                status=None, distribution=None):
         """Create and return a new, arbitrary Bug.
 
         The bug returned uses default values where possible. See
         `IBugSet.new` for more information.
 
-        :param product: If the product is not set, one is created
-            and this is used as the primary bug target.
+        :param product: If the product is not set, and if the parameter
+            distribution is not set, a product is created and this is
+            used as the primary bug target.
         :param owner: The reporter of the bug. If not set, one is created.
         :param bug_watch_url: If specified, create a bug watch pointing
             to this URL.
+        :param distribution: If set, the distribution is used as the
+            default bug target.
+
+        At least one of the parameters distribution and product must be
+        None, otherwise, an assertion error will be raised.
         """
-        if product is None:
+        if product is None and distribution is None:
             product = self.makeProduct()
         if owner is None:
             owner = self.makePerson()
@@ -1357,7 +1363,8 @@
             owner, title, comment=comment, private=private,
             datecreated=date_created, description=description,
             status=status)
-        create_bug_params.setBugTarget(product=product)
+        create_bug_params.setBugTarget(
+            product=product, distribution=distribution)
         bug = getUtility(IBugSet).createBug(create_bug_params)
         if bug_watch_url is not None:
             # fromText() creates a bug watch associated with the bug.