diff --git a/test/test_dbcore.py b/test/test_dbcore.py index d2bdb907b..b0063dffb 100644 --- a/test/test_dbcore.py +++ b/test/test_dbcore.py @@ -470,8 +470,12 @@ class SortFromStringsTest(unittest.TestCase): class ResultsIteratorTest(unittest.TestCase): def setUp(self): self.db = TestDatabase1(':memory:') - TestModel1().add(self.db) - TestModel1().add(self.db) + model = TestModel1() + model['foo'] = 'baz' + model.add(self.db) + model = TestModel1() + model['foo'] = 'bar' + model.add(self.db) def tearDown(self): self.db._connection().close() @@ -493,6 +497,38 @@ class ResultsIteratorTest(unittest.TestCase): list(it2) self.assertEqual(len(list(it1)), 1) + def test_slow_query(self): + q = dbcore.query.SubstringQuery('foo', 'ba', False) + objs = self.db._fetch(TestModel1, q) + self.assertEqual(len(list(objs)), 2) + + def test_slow_query_negative(self): + q = dbcore.query.SubstringQuery('foo', 'qux', False) + objs = self.db._fetch(TestModel1, q) + self.assertEqual(len(list(objs)), 0) + + def test_iterate_slow_sort(self): + s = dbcore.query.SlowFieldSort('foo') + res = self.db._fetch(TestModel1, sort=s) + objs = list(res) + self.assertEqual(objs[0].foo, 'bar') + self.assertEqual(objs[1].foo, 'baz') + + def test_unsorted_subscript(self): + objs = self.db._fetch(TestModel1) + self.assertEqual(objs[0].foo, 'baz') + self.assertEqual(objs[1].foo, 'bar') + + def test_slow_sort_subscript(self): + s = dbcore.query.SlowFieldSort('foo') + objs = self.db._fetch(TestModel1, sort=s) + self.assertEqual(objs[0].foo, 'bar') + self.assertEqual(objs[1].foo, 'baz') + + def test_length(self): + objs = self.db._fetch(TestModel1) + self.assertEqual(len(objs), 2) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)