From df8412d2e5c95fe8c8238ebde8e0dbb68fe2ec1d Mon Sep 17 00:00:00 2001 From: Rustam Kashapov Date: Sun, 15 May 2016 12:53:16 +0300 Subject: Fixed #26617 -- Added distinct argument to contrib.postgres's StringAgg. --- tests/postgres_tests/test_aggregates.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/postgres_tests') diff --git a/tests/postgres_tests/test_aggregates.py b/tests/postgres_tests/test_aggregates.py index 07e4ea0101..f6f48fdd61 100644 --- a/tests/postgres_tests/test_aggregates.py +++ b/tests/postgres_tests/test_aggregates.py @@ -111,6 +111,24 @@ class TestGeneralAggregate(PostgreSQLTestCase): self.assertEqual(values, {'stringagg': ''}) +class TestStringAggregateDistinct(PostgreSQLTestCase): + @classmethod + def setUpTestData(cls): + AggregateTestModel.objects.create(char_field='Foo') + AggregateTestModel.objects.create(char_field='Foo') + AggregateTestModel.objects.create(char_field='Bar') + + def test_string_agg_distinct_false(self): + values = AggregateTestModel.objects.aggregate(stringagg=StringAgg('char_field', delimiter=' ', distinct=False)) + self.assertEqual(values['stringagg'].count('Foo'), 2) + self.assertEqual(values['stringagg'].count('Bar'), 1) + + def test_string_agg_distinct_true(self): + values = AggregateTestModel.objects.aggregate(stringagg=StringAgg('char_field', delimiter=' ', distinct=True)) + self.assertEqual(values['stringagg'].count('Foo'), 1) + self.assertEqual(values['stringagg'].count('Bar'), 1) + + class TestStatisticsAggregate(PostgreSQLTestCase): @classmethod def setUpTestData(cls): -- cgit v1.3