~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/tests/test_bugtask.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-10-19 20:19:27 UTC
  • mfrom: (14130.1.4 bug-828572)
  • Revision ID: launchpad@pqm.canonical.com-20111019201927-d4ha25d9h8lek4dy
[r=flacoste][bug=828572] Since we've finished transitioning to the
        new statuses,
        we don't need the heuristic for INCOMPLETE bug searches any more.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
from lazr.lifecycle.event import ObjectModifiedEvent
10
10
from lazr.lifecycle.snapshot import Snapshot
 
11
from testtools.testcase import ExpectedException
11
12
from testtools.matchers import Equals
12
13
from zope.component import getUtility
13
14
from zope.event import notify
18
19
from canonical.launchpad.searchbuilder import (
19
20
    all,
20
21
    any,
 
22
    not_equals,
21
23
    )
22
24
from canonical.launchpad.webapp.interfaces import ILaunchBag
23
25
from canonical.testing.layers import (
41
43
from lp.bugs.model.bugtask import (
42
44
    bug_target_from_key,
43
45
    bug_target_to_key,
 
46
    BugTaskSet,
44
47
    build_tag_search_clause,
45
48
    IllegalTarget,
46
49
    validate_new_target,
192
195
                            new=bug_task.importance))
193
196
 
194
197
 
 
198
class TestBugTaskSetStatusSearchClauses(TestCase):
 
199
    # BugTaskSets contain a utility function that generates SQL WHERE clauses
 
200
    # used to find sets of bugs.  These tests exercise that utility function.
 
201
 
 
202
    def searchClause(self, status_spec):
 
203
        return BugTaskSet._buildStatusClause(status_spec)
 
204
 
 
205
    def test_simple_queries(self):
 
206
        # WHERE clauses for simple status values are straightforward.
 
207
        self.assertEqual(
 
208
            '(BugTask.status = 10)',
 
209
            self.searchClause(BugTaskStatus.NEW))
 
210
        self.assertEqual(
 
211
            '(BugTask.status = 16)',
 
212
            self.searchClause(BugTaskStatus.OPINION))
 
213
        self.assertEqual(
 
214
            '(BugTask.status = 22)',
 
215
            self.searchClause(BugTaskStatus.INPROGRESS))
 
216
 
 
217
    def test_INCOMPLETE_query(self):
 
218
        # Since we don't really store INCOMPLETE in the DB but instead store
 
219
        # values with finer shades of meaning, asking for INCOMPLETE will
 
220
        # result in a clause that actually matches multiple statuses.
 
221
        self.assertEqual(
 
222
            '(BugTask.status IN (13,14))',
 
223
            self.searchClause(BugTaskStatus.INCOMPLETE))
 
224
 
 
225
    def test_negative_query(self):
 
226
        # If a negative is requested then the WHERE clause is simply wrapped
 
227
        # in a "NOT".
 
228
        status = BugTaskStatus.INCOMPLETE
 
229
        base_query = self.searchClause(status)
 
230
        expected_negative_query = '(NOT {0})'.format(base_query)
 
231
        self.assertEqual(
 
232
            expected_negative_query,
 
233
            self.searchClause(not_equals(status)))
 
234
 
 
235
    def test_any_query(self):
 
236
        # An "any" object may be passed in containing a set of statuses to
 
237
        # return.  The resulting SQL uses IN in an effort to be optimal.
 
238
        self.assertEqual(
 
239
            '(BugTask.status IN (10,16))',
 
240
            self.searchClause(any(BugTaskStatus.NEW, BugTaskStatus.OPINION)))
 
241
 
 
242
    def test_any_query_with_INCOMPLETE(self):
 
243
        # Since INCOMPLETE is not a single-value status (see above) an "any"
 
244
        # query that includes INCOMPLETE will cause more enum values to be
 
245
        # included in the IN clause than were given.  Note that we go to a bit
 
246
        # of effort to generate an IN expression instead of a series of
 
247
        # ORed-together equality checks.
 
248
        self.assertEqual(
 
249
            '(BugTask.status IN (10,13,14))',
 
250
            self.searchClause(
 
251
                any(BugTaskStatus.NEW, BugTaskStatus.INCOMPLETE)))
 
252
 
 
253
    def test_all_query(self):
 
254
        # Since status is single-valued, asking for "all" statuses in a set
 
255
        # doesn't make any sense.
 
256
        with ExpectedException(ValueError):
 
257
            self.searchClause(
 
258
                all(BugTaskStatus.NEW, BugTaskStatus.INCOMPLETE))
 
259
 
 
260
    def test_bad_value(self):
 
261
        # If an unrecognized status is provided then an error is raised.
 
262
        with ExpectedException(ValueError):
 
263
            self.searchClause('this-is-not-a-status')
 
264
 
 
265
 
195
266
class TestBugTaskTagSearchClauses(TestCase):
196
267
 
197
268
    def searchClause(self, tag_spec):