class EmptySearchQuerySetTestCase(TestCase): def setUp(self): super(EmptySearchQuerySetTestCase, self).setUp() self.esqs = EmptySearchQuerySet() def test_get_count(self): self.assertEqual(self.esqs.count(), 0) self.assertEqual(len(self.esqs.all()), 0) def test_filter(self): sqs = self.esqs.filter(content='foo') self.assertTrue(isinstance(sqs, EmptySearchQuerySet)) self.assertEqual(len(sqs), 0) def test_exclude(self): sqs = self.esqs.exclude(content='foo') self.assertTrue(isinstance(sqs, EmptySearchQuerySet)) self.assertEqual(len(sqs), 0) def test_slice(self): sqs = self.esqs.filter(content='foo') self.assertTrue(isinstance(sqs, EmptySearchQuerySet)) self.assertEqual(len(sqs), 0) self.assertEqual(sqs[:10], []) try: sqs[4] self.fail() except IndexError: pass def test_dictionary_lookup(self): """ Ensure doing a dictionary lookup raises a TypeError so EmptySearchQuerySets can be used in templates. """ self.assertRaises(TypeError, lambda: self.esqs['count'])
def setUp(self): super(EmptySearchQuerySetTestCase, self).setUp() self.esqs = EmptySearchQuerySet()