MCPcopy
hub / github.com/django/django / test_explicit_cast

Method test_explicit_cast

tests/db_functions/json/test_json_array.py:90–98  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

88
89 @unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL specific tests")
90 def test_explicit_cast(self):
91 qs = Author.objects.annotate(
92 json_array=JSONArray(Cast("age", CharField()))
93 ).values("json_array")
94 with self.assertNumQueries(1) as ctx:
95 self.assertSequenceEqual(qs, [{"json_array": ["30"]}])
96 sql = ctx.captured_queries[0]["sql"]
97 self.assertIn("::varchar", sql)
98 self.assertNotIn("::varchar)::varchar", sql)
99
100 def test_order_by_key(self):
101 qs = Author.objects.annotate(arr=JSONArray(F("alias"))).order_by("arr__0")

Callers

nothing calls this directly

Calls 6

JSONArrayClass · 0.90
CastClass · 0.90
CharFieldClass · 0.90
annotateMethod · 0.80
assertNumQueriesMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected