From 7d44aeb388a33ac56353a658b41a6119e93931ff Mon Sep 17 00:00:00 2001
From: David Wobrock <david.wobrock@gmail.com>
Date: Tue, 31 Dec 2019 10:32:27 +0100
Subject: [PATCH] Refs #31097 -- Added tests for filter in ArrayAgg and
 StringAgg.

---
 tests/postgres_tests/test_aggregates.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

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=';'))