MCPcopy Create free account
hub / github.com/tortoise/tortoise-orm / test_create

Function test_create

tests/fields/test_json.py:33–51  ·  view source on GitHub ↗

Test JSON field creation and retrieval.

(db)

Source from the content-addressed store, hash-verified

31
32@pytest.mark.asyncio
33async def test_create(db):
34 """Test JSON field creation and retrieval."""
35 obj0 = await testmodels.JSONFields.create(data={"some": ["text", 3]})
36 obj = await testmodels.JSONFields.get(id=obj0.id)
37 assert obj.data == {"some": ["text", 3]}
38 assert obj.data_null is None
39 await obj.save()
40 obj2 = await testmodels.JSONFields.get(id=obj.id)
41 assert obj == obj2
42 obj3 = await testmodels.JSONFields.create(data="{}", data_decimal=Decimal(0))
43 obj3 = await testmodels.JSONFields.get(id=obj3.id)
44 assert str(obj3.data_decimal) == "0"
45 pyd_model = MyPydanticModel(name="", idx=Index(fields=["data"]))
46 obj4 = await testmodels.JSONFields.create(data="{}", data_index=pyd_model)
47 obj4 = await testmodels.JSONFields.get(id=obj4.id)
48 assert obj4.data_index == {
49 "idx": {"expressions": [], "extra": "", "fields": ["data"], "name": None, "type": ""},
50 "name": "",
51 }
52
53
54@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 5

IndexClass · 0.90
MyPydanticModelClass · 0.85
saveMethod · 0.80
createMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…