Add tests for distcint with count

This commit is contained in:
Alan Boudreault
2016-03-03 15:17:04 -05:00
parent 84c9c8c04b
commit dabb8d412b
2 changed files with 10 additions and 0 deletions

View File

@@ -485,6 +485,13 @@ class TestQuerySetDistinct(BaseQuerySetUsage):
q = TestModel.objects.distinct(['test_id']).filter(test_id__in=[52])
self.assertEqual(len(q), 0)
def test_distinct_with_explicit_count(self):
q = TestModel.objects.distinct(['test_id'])
self.assertEqual(q.count(), 3)
q = TestModel.objects.distinct(['test_id']).filter(test_id__in=[1, 2])
self.assertEqual(q.count(), 2)
class TestQuerySetOrdering(BaseQuerySetUsage):

View File

@@ -64,6 +64,9 @@ class SelectStatementTests(unittest.TestCase):
ss = SelectStatement('table', distinct_fields=['field1', 'field2'])
self.assertEqual(six.text_type(ss), 'SELECT DISTINCT "field1", "field2" FROM table')
ss = SelectStatement('table', distinct_fields=['field1'], count=True)
self.assertEqual(six.text_type(ss), 'SELECT DISTINCT COUNT("field1") FROM table')
def test_context(self):
ss = SelectStatement('table')
ss.add_where_clause(WhereClause('a', EqualsOperator(), 'b'))