192
195
new=bug_task.importance))
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.
202
def searchClause(self, status_spec):
203
return BugTaskSet._buildStatusClause(status_spec)
205
def test_simple_queries(self):
206
# WHERE clauses for simple status values are straightforward.
208
'(BugTask.status = 10)',
209
self.searchClause(BugTaskStatus.NEW))
211
'(BugTask.status = 16)',
212
self.searchClause(BugTaskStatus.OPINION))
214
'(BugTask.status = 22)',
215
self.searchClause(BugTaskStatus.INPROGRESS))
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.
222
'(BugTask.status IN (13,14))',
223
self.searchClause(BugTaskStatus.INCOMPLETE))
225
def test_negative_query(self):
226
# If a negative is requested then the WHERE clause is simply wrapped
228
status = BugTaskStatus.INCOMPLETE
229
base_query = self.searchClause(status)
230
expected_negative_query = '(NOT {0})'.format(base_query)
232
expected_negative_query,
233
self.searchClause(not_equals(status)))
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.
239
'(BugTask.status IN (10,16))',
240
self.searchClause(any(BugTaskStatus.NEW, BugTaskStatus.OPINION)))
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.
249
'(BugTask.status IN (10,13,14))',
251
any(BugTaskStatus.NEW, BugTaskStatus.INCOMPLETE)))
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):
258
all(BugTaskStatus.NEW, BugTaskStatus.INCOMPLETE))
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')
195
266
class TestBugTaskTagSearchClauses(TestCase):
197
268
def searchClause(self, tag_spec):