diff options
| author | David Wobrock <david.wobrock@gmail.com> | 2019-12-31 10:32:27 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-12-31 10:35:39 +0100 |
| commit | 7d44aeb388a33ac56353a658b41a6119e93931ff (patch) | |
| tree | 6bb59c47c38bd62141dc8845a621e527ff149876 /tests/postgres_tests | |
| parent | 307c63f9a7c90a21368d8361cd76f48f372413ab (diff) | |
Refs #31097 -- Added tests for filter in ArrayAgg and StringAgg.
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/test_aggregates.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/postgres_tests/test_aggregates.py b/tests/postgres_tests/test_aggregates.py index 9bd5b70a9e..9a042388bd 100644 --- a/tests/postgres_tests/test_aggregates.py +++ b/tests/postgres_tests/test_aggregates.py @@ -1,6 +1,6 @@ import json -from django.db.models import CharField +from django.db.models import CharField, Q from django.db.models.expressions import F, OuterRef, Subquery, Value from django.db.models.functions import Cast, Concat, Substr from django.test.utils import Approximate @@ -80,6 +80,12 @@ class TestGeneralAggregate(PostgreSQLTestCase): ) self.assertEqual(values, {'arrayagg': expected_output}) + def test_array_agg_filter(self): + values = AggregateTestModel.objects.aggregate( + arrayagg=ArrayAgg('integer_field', filter=Q(integer_field__gt=0)), + ) + self.assertEqual(values, {'arrayagg': [1, 2]}) + def test_array_agg_empty_result(self): AggregateTestModel.objects.all().delete() values = AggregateTestModel.objects.aggregate(arrayagg=ArrayAgg('char_field')) @@ -184,6 +190,16 @@ class TestGeneralAggregate(PostgreSQLTestCase): ) self.assertEqual(values, {'stringagg': expected_output}) + def test_string_agg_filter(self): + values = AggregateTestModel.objects.aggregate( + stringagg=StringAgg( + 'char_field', + delimiter=';', + filter=Q(char_field__endswith='3') | Q(char_field__endswith='1'), + ) + ) + self.assertEqual(values, {'stringagg': 'Foo1;Foo3'}) + def test_string_agg_empty_result(self): AggregateTestModel.objects.all().delete() values = AggregateTestModel.objects.aggregate(stringagg=StringAgg('char_field', delimiter=';')) |
