~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/tests/test_bugtask_search.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-04 16:19:40 UTC
  • mfrom: (14616.2.2 bug-909318)
  • Revision ID: launchpad@pqm.canonical.com-20120104161940-wxc81swjnsofjakb
[r=gmb][bug=909318] bug fix: invalid SQL query when a bugtask search
 consisting of a UNION of two or more sub-.queries is ordered by a value that
 requires to join another table.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1339
1339
    accepts exactly one instance.
1340
1340
    """
1341
1341
 
 
1342
    def setUpTwoSearchParams(self, orderby=None):
 
1343
        # Prepare the test data for the tests in this class.
 
1344
        params1 = self.getBugTaskSearchParams(
 
1345
            user=None, status=BugTaskStatus.FIXCOMMITTED, orderby=orderby)
 
1346
        subscriber = self.factory.makePerson()
 
1347
        self.subscribeToTarget(subscriber)
 
1348
        params2 = self.getBugTaskSearchParams(
 
1349
            user=None, status=BugTaskStatus.NEW,
 
1350
            structural_subscriber=subscriber, orderby=orderby)
 
1351
        return params1, params2
 
1352
 
1342
1353
    def test_two_param_objects(self):
1343
1354
        # We can pass more than one BugTaskSearchParams instance to
1344
1355
        # BugTaskSet.search().
1345
 
        params1 = self.getBugTaskSearchParams(
1346
 
            user=None, status=BugTaskStatus.FIXCOMMITTED)
1347
 
        subscriber = self.factory.makePerson()
1348
 
        self.subscribeToTarget(subscriber)
1349
 
        params2 = self.getBugTaskSearchParams(
1350
 
            user=None, status=BugTaskStatus.NEW,
1351
 
            structural_subscriber=subscriber)
 
1356
        params1, params2 = self.setUpTwoSearchParams()
1352
1357
        search_result = self.runSearch(params1, params2)
1353
1358
        expected = self.resultValuesForBugtasks(self.bugtasks[1:])
1354
1359
        self.assertEqual(expected, search_result)
1355
1360
 
 
1361
    def test_two_param_objects_sorting_needs_extra_join(self):
 
1362
        # If result ordering needs an extra join, the join
 
1363
        # is added to the union of the result sets for the two
 
1364
        # BugTaskSearchParams instances.
 
1365
        params1, params2 = self.setUpTwoSearchParams(orderby='reporter')
 
1366
        search_result = self.runSearch(params1, params2)
 
1367
 
 
1368
        def sortkey(bugtask):
 
1369
            return bugtask.owner.name
 
1370
 
 
1371
        expected_bugtasks = sorted(self.bugtasks[1:], key=sortkey)
 
1372
        expected = self.resultValuesForBugtasks(expected_bugtasks)
 
1373
        self.assertEqual(expected, search_result)
 
1374
 
1356
1375
 
1357
1376
class PreloadBugtaskTargets(MultipleParams):
1358
1377
    """Preload bug targets during a BugTaskSet.search() query."""