71
75
self.store.execute(
72
76
"INSERT INTO testresult VALUES (?, ?, ?, ?)",
73
77
(self.test_case, status, output, date_created,),
76
81
def removeTestResult(self, **kwargs):
77
where_condition = self.getWhereCondition(**kwargs)
79
"DELETE FROM testresult WHERE %s"
82
query = self.getTestResultQuery(**kwargs)
83
self.store.execute("DELETE FROM testresult WHERE %s" % query)
82
85
def countTestResults(self, **kwargs):
83
where_condition = self.getWhereCondition(**kwargs)
86
query = self.getTestResultQuery(**kwargs)
84
87
return self.store.execute(
85
"SELECT COUNT(*) FROM testresult WHERE %s"
86
% where_condition).get_one()[0]
88
"SELECT COUNT(*) FROM testresult WHERE %s" % query).get_one()[0]
88
def searchTestResults(self, **kwargs):
90
def getTestResult(self, **kwargs):
92
"test_case", "status", "output", "date_created", "date_deleted"]
95
93
select_expression = ", ".join(keys)
96
where_condition = self.getWhereCondition(**kwargs)
94
query = self.getTestResultQuery(**kwargs)
97
95
values = self.store.execute(
98
"SELECT %s FROM testresult WHERE %s"
99
% (select_expression, where_condition)).get_all()
96
"SELECT %s FROM testresult WHERE %s ORDER BY date_created"
97
% (select_expression, query)).get_all()
99
self.fail("One test result expected, %d found" % len(values))
101
return [dict(zip(keys, value)) for value in values]
101
return dict(zip(keys, values[0]))
103
103
def assertCountTestResults(self, count, **kwargs):
104
104
test_result_count = self.countTestResults(**kwargs)
175
171
# Add test results in reversed order
176
172
self.insertTestResult(status=0, date_created=second_date)
177
173
self.insertTestResult(status=0, date_created=first_date)
178
self.assertCountTestResults(1)
180
175
# Only the first test result should exist
181
test_results = self.searchTestResults(date_created=first_date)
182
self.assertEquals(len(test_results), 1)
183
test_result = test_results[0]
176
test_result = self.getTestResult(date_created=first_date)
184
177
self.assertEquals(test_result["status"], 0)
185
178
self.assertEquals(test_result["date_created"], first_date)
187
test_results = self.searchTestResults(date_created=second_date)
188
self.assertEquals(len(test_results), 0)
191
class TestTestResultRemove(TestResultTestCase):
193
def test_deleteOneResult(self):
194
self.assertCountTestResults(0)
195
self.insertTestResult()
196
self.assertCountTestResults(1)
197
self.removeTestResult()
198
self.assertCountTestResults(0)
200
def test_deleteFirstOfTwoResults(self):
201
first_date = datetime(2010, 1, 1)
202
self.assertCountTestResults(0, date_created=first_date)
203
second_date = datetime(2010, 1, 2)
204
self.assertCountTestResults(0, date_created=second_date)
206
# There should be two rows after creating different test results
207
self.insertTestResult(status=0, date_created=first_date)
208
self.insertTestResult(status=1, date_created=second_date)
209
self.assertCountTestResults(2)
211
# There should only be one test result
212
# after removing the first one
213
self.removeTestResult(date_created=first_date)
214
self.assertCountTestResults(1)
216
# The date_created of the second test result should no longer exist
217
removed_results = self.searchTestResults(date_created=second_date)
218
self.assertEquals(removed_results, [])
220
# Instead, the date_created of the second test result should now
221
# be the same as the first test result
222
remaining_results = self.searchTestResults(date_created=first_date)
223
self.assertNotEquals(remaining_results, [])
225
# There should no longer be any test results
226
# after removing the last one
227
self.removeTestResult(date_created=first_date)
228
self.assertCountTestResults(0)
230
def test_deleteSecondOfTwoResults(self):
231
first_date = datetime(2010, 1, 1)
232
self.assertCountTestResults(0, date_created=first_date)
233
second_date = datetime(2010, 1, 2)
234
self.assertCountTestResults(0, date_created=second_date)
236
# There should be two test results after creating different ones
237
self.insertTestResult(status=0, date_created=first_date)
238
self.insertTestResult(status=1, date_created=second_date)
239
self.assertCountTestResults(2)
241
# The date_deleted of the first test result
242
# should be the same as the date_created of the second test result
243
first_result = self.searchTestResults(date_created=first_date)[0]
244
second_result = self.searchTestResults(date_created=second_date)[0]
246
first_result["date_deleted"],
247
second_result["date_created"])
249
# There should only be one test result
250
# after removing the second one
251
self.removeTestResult(date_created=second_date)
252
self.assertCountTestResults(1)
254
# The date_deleted of the first test result
255
# should be adjusted to the same as the second test result
256
remaining_result = self.searchTestResults(date_created=first_date)[0]
258
remaining_result["date_deleted"],
259
second_result["date_deleted"])
261
# There should no longer be any test results
262
# after removing the last one
263
self.removeTestResult(date_created=first_date)
264
self.assertCountTestResults(0)
266
def test_deleteSecondOfThreeDifferentResults(self):
267
first_date = datetime(2010, 1, 1)
268
self.assertCountTestResults(0, date_created=first_date)
269
second_date = datetime(2010, 1, 2)
270
self.assertCountTestResults(0, date_created=second_date)
271
third_date = datetime(2010, 1, 3)
272
self.assertCountTestResults(0, date_created=third_date)
274
# There should be three test results after creating different ones
275
self.insertTestResult(status=0, date_created=first_date)
276
self.insertTestResult(status=1, date_created=second_date)
277
self.insertTestResult(status=2, date_created=third_date)
278
self.assertCountTestResults(3)
280
# There should only be two test results
281
# after removing the second one
282
self.removeTestResult(date_created=second_date)
283
self.assertCountTestResults(2)
285
# The date_deleted of the first test result
286
# should be the same as the date_created of the third test result
287
first_result = self.searchTestResults(date_created=first_date)[0]
288
self.assertEquals(first_result["date_deleted"], third_date)
290
# The date_created of the third test result
291
# should be the same as before
292
third_result = self.searchTestResults(date_created=third_date)[0]
293
self.assertEquals(third_result["date_created"], third_date)
295
def test_deleteSecondOfThreeSimilarResults(self):
296
first_date = datetime(2010, 1, 1)
297
self.assertCountTestResults(0, date_created=first_date)
298
second_date = datetime(2010, 1, 2)
299
self.assertCountTestResults(0, date_created=second_date)
300
third_date = datetime(2010, 1, 3)
301
self.assertCountTestResults(0, date_created=third_date)
303
# There should be three test results after creating different ones
304
self.insertTestResult(status=0, date_created=first_date)
305
self.insertTestResult(status=1, date_created=second_date)
306
self.insertTestResult(status=0, date_created=third_date)
307
self.assertCountTestResults(3)
309
third_result = self.searchTestResults(date_created=third_date)[0]
311
# There should only be one test result
312
# after removing the second one
313
self.removeTestResult(date_created=second_date)
314
self.assertCountTestResults(1)
316
# The date_created of the remaining test result
317
# should be the same as the date_created of the first test result
318
remaining_result = self.searchTestResults(date_created=first_date)[0]
319
self.assertNotEquals(remaining_result, None)
320
self.assertEquals(remaining_result["date_created"], first_date)
322
# The date_deleted of the remaining test result
323
# should be the same as the date_deleted of the third test result
325
remaining_result["date_deleted"],
326
third_result["date_deleted"])
180
self.assertCountTestResults(0, date_created=second_date)
329
183
def test_suite():