som types fixes, fix for wrong prefixes in model_row for complex relations, test load_all with repeating tables, add docs

This commit is contained in:
collerek
2021-03-04 13:12:07 +01:00
parent a8ae50276e
commit 4e27f07a7e
11 changed files with 90 additions and 29 deletions

View File

@ -124,7 +124,8 @@ async def create_user(user: User):
@app.post("/users2/", response_model=User)
async def create_user2(user: User):
return (await user.save()).dict(exclude={"password"})
user = await user.save()
return user.dict(exclude={"password"})
@app.post("/users3/", response_model=UserBase)

View File

@ -1,4 +1,4 @@
from typing import Any, List, Sequence, cast
from typing import Any, Sequence, cast
import databases
import pytest

View File

@ -108,3 +108,17 @@ async def test_model_multiple_instances_of_same_table_in_schema():
assert len(classes[0].dict().get("students")) == 2
assert classes[0].teachers[0].category.department.name == "Law Department"
assert classes[0].students[0].category.department.name == "Math Department"
@pytest.mark.asyncio
async def test_load_all_multiple_instances_of_same_table_in_schema():
async with database:
await create_data()
math_class = await SchoolClass.objects.get(name="Math")
assert math_class.name == "Math"
await math_class.load_all(follow=True)
assert math_class.students[0].name == "Jane"
assert len(math_class.dict().get("students")) == 2
assert math_class.teachers[0].category.department.name == "Law Department"
assert math_class.students[0].category.department.name == "Math Department"