MCPcopy
hub / github.com/tortoise/tortoise-orm / test_annotate

Function test_annotate

tests/test_sql.py:65–77  ·  view source on GitHub ↗
(sql_context)

Source from the content-addressed store, hash-verified

63
64
65def test_annotate(sql_context):
66 db, dialect, is_psycopg = sql_context
67 sql = CharPkModel.all().annotate(id_plus_one=Concat(F("id"), "_postfix")).sql()
68 if dialect == "mysql":
69 expected = "SELECT `id`,CONCAT(`id`,%s) `id_plus_one` FROM `charpkmodel`"
70 elif dialect == "postgres":
71 if is_psycopg:
72 expected = 'SELECT "id",CONCAT("id"::text,%s::text) "id_plus_one" FROM "charpkmodel"'
73 else:
74 expected = 'SELECT "id",CONCAT("id"::text,$1::text) "id_plus_one" FROM "charpkmodel"'
75 else:
76 expected = 'SELECT "id",CONCAT("id",?) "id_plus_one" FROM "charpkmodel"'
77 assert sql == expected
78
79
80def test_annotate_concat_fields(sql_context):

Callers

nothing calls this directly

Calls 5

ConcatClass · 0.90
FClass · 0.90
sqlMethod · 0.45
annotateMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…