summaryrefslogtreecommitdiff
path: root/tests/db_functions
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-12-08 02:03:14 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-12 05:51:33 +0100
commitb0ad41198b3e333f57351e3fce5a1fb47f23f376 (patch)
treeb68005963b6261679db534b102d4327b584d12e2 /tests/db_functions
parentfcf95e592774a6ededec35481a2061474d467a2b (diff)
Fixed #34013 -- Added QuerySet.order_by() support for annotation transforms.
Thanks Eugene Morozov and Ben Nace for the reports.
Diffstat (limited to 'tests/db_functions')
-rw-r--r--tests/db_functions/comparison/test_json_object.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/db_functions/comparison/test_json_object.py b/tests/db_functions/comparison/test_json_object.py
index 7a10657317..9a3d48288c 100644
--- a/tests/db_functions/comparison/test_json_object.py
+++ b/tests/db_functions/comparison/test_json_object.py
@@ -12,7 +12,12 @@ from ..models import Article, Author
class JSONObjectTests(TestCase):
@classmethod
def setUpTestData(cls):
- Author.objects.create(name="Ivan Ivanov", alias="iivanov")
+ Author.objects.bulk_create(
+ [
+ Author(name="Ivan Ivanov", alias="iivanov"),
+ Author(name="Bertha Berthy", alias="bberthy"),
+ ]
+ )
def test_empty(self):
obj = Author.objects.annotate(json_object=JSONObject()).first()
@@ -88,6 +93,18 @@ class JSONObjectTests(TestCase):
obj = Article.objects.annotate(json_object=JSONObject(text=F("text"))).first()
self.assertEqual(obj.json_object, {"text": "x" * 4000})
+ def test_order_by_key(self):
+ qs = Author.objects.annotate(attrs=JSONObject(alias=F("alias"))).order_by(
+ "attrs__alias"
+ )
+ self.assertQuerySetEqual(qs, Author.objects.order_by("alias"))
+
+ def test_order_by_nested_key(self):
+ qs = Author.objects.annotate(
+ attrs=JSONObject(nested=JSONObject(alias=F("alias")))
+ ).order_by("-attrs__nested__alias")
+ self.assertQuerySetEqual(qs, Author.objects.order_by("-alias"))
+
@skipIfDBFeature("has_json_object_function")
class JSONObjectNotSupportedTests(TestCase):