summaryrefslogtreecommitdiff
path: root/tests/queries
diff options
context:
space:
mode:
authorGagaro <gagaro42@gmail.com>2022-05-03 14:06:42 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-05-03 15:31:53 +0200
commit9d04711261156c487c6085171398070ea3df8122 (patch)
tree90a0e836a36e71d1ed7051aec67f1ac03ad296ec /tests/queries
parentdf22566748faa7bd16a9616617875e8370cbe4ee (diff)
downloaddjango-9d04711261156c487c6085171398070ea3df8122.tar.gz
Refs #30581 -- Added Q.flatten().
Diffstat (limited to 'tests/queries')
-rw-r--r--tests/queries/test_q.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/queries/test_q.py b/tests/queries/test_q.py
index 39645a6f31..42a00da3eb 100644
--- a/tests/queries/test_q.py
+++ b/tests/queries/test_q.py
@@ -1,5 +1,15 @@
-from django.db.models import BooleanField, Exists, F, OuterRef, Q
+from django.db.models import (
+ BooleanField,
+ Exists,
+ ExpressionWrapper,
+ F,
+ OuterRef,
+ Q,
+ Value,
+)
from django.db.models.expressions import RawSQL
+from django.db.models.functions import Lower
+from django.db.models.sql.where import NothingNode
from django.test import SimpleTestCase
from .models import Tag
@@ -188,3 +198,19 @@ class QTests(SimpleTestCase):
q = q1 & q2
path, args, kwargs = q.deconstruct()
self.assertEqual(Q(*args, **kwargs), q)
+
+ def test_flatten(self):
+ q = Q()
+ self.assertEqual(list(q.flatten()), [q])
+ q = Q(NothingNode())
+ self.assertEqual(list(q.flatten()), [q, q.children[0]])
+ q = Q(
+ ExpressionWrapper(
+ Q(RawSQL("id = 0", params=(), output_field=BooleanField()))
+ | Q(price=Value("4.55"))
+ | Q(name=Lower("category")),
+ output_field=BooleanField(),
+ )
+ )
+ flatten = list(q.flatten())
+ self.assertEqual(len(flatten), 7)