summaryrefslogtreecommitdiff
path: root/tests/aggregation_regress/tests.py
diff options
context:
space:
mode:
authorRyan Heard <ryanwheard@gmail.com>2021-07-02 15:09:13 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-03-04 12:55:37 +0100
commitc6b4d62fa2c7f73b87f6ae7e8cf1d64ee5312dc5 (patch)
tree238bd8c3045c8d4577e09bd913de9748dcd49968 /tests/aggregation_regress/tests.py
parent795da6306a048b18c0158496b0d49e8e4f197a32 (diff)
Fixed #29865 -- Added logical XOR support for Q() and querysets.
Diffstat (limited to 'tests/aggregation_regress/tests.py')
-rw-r--r--tests/aggregation_regress/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
index fb9d4ca92b..92a66298e4 100644
--- a/tests/aggregation_regress/tests.py
+++ b/tests/aggregation_regress/tests.py
@@ -1704,6 +1704,28 @@ class AggregationTests(TestCase):
attrgetter("pk"),
)
+ def test_filter_aggregates_xor_connector(self):
+ q1 = Q(price__gt=50)
+ q2 = Q(authors__count__gt=1)
+ query = Book.objects.annotate(Count("authors")).filter(q1 ^ q2).order_by("pk")
+ self.assertQuerysetEqual(
+ query,
+ [self.b1.pk, self.b4.pk, self.b6.pk],
+ attrgetter("pk"),
+ )
+
+ def test_filter_aggregates_negated_xor_connector(self):
+ q1 = Q(price__gt=50)
+ q2 = Q(authors__count__gt=1)
+ query = (
+ Book.objects.annotate(Count("authors")).filter(~(q1 ^ q2)).order_by("pk")
+ )
+ self.assertQuerysetEqual(
+ query,
+ [self.b2.pk, self.b3.pk, self.b5.pk],
+ attrgetter("pk"),
+ )
+
def test_ticket_11293_q_immutable(self):
"""
Splitting a q object to parts for where/having doesn't alter