1+ from typing import List
2+
13from fastapi import FastAPI
24from httpx import AsyncClient
35from sqlmodel .sql .expression import Select
79from fastapi_amis_admin .crud .parser import LabelField , PropertyField
810from fastapi_amis_admin .models import Field
911from tests .conftest import async_db as db
10- from tests .models import Article , ArticleContent , Category , User
12+ from tests .models import Article , ArticleContent , Category , Tag , User
1113
1214
1315async def test_pk_name (app : FastAPI , async_client : AsyncClient , fake_users ):
@@ -273,7 +275,7 @@ class ArticleCrud(SQLModelCrud):
273275 assert items ["description" ] == "Description_1"
274276
275277
276- async def test_read_fields_relationship (app : FastAPI , async_client : AsyncClient , fake_articles ):
278+ async def test_read_fields_relationship (app : FastAPI , async_client : AsyncClient , fake_articles , fake_article_tags ):
277279 class ArticleCrud (SQLModelCrud ):
278280 router_prefix = "/article"
279281 read_fields = [
@@ -282,6 +284,7 @@ class ArticleCrud(SQLModelCrud):
282284 PropertyField (name = "category" , type_ = Category ), # Relationship attribute
283285 # Article.category, # Relationship todo support
284286 PropertyField (name = "content_text" , type_ = str ), # property attribute
287+ PropertyField (name = "tags" , type_ = List [Tag ]), # property attribute
285288 ]
286289
287290 ins = ArticleCrud (Article , db .engine ).register_crud ()
@@ -293,15 +296,15 @@ class ArticleCrud(SQLModelCrud):
293296 assert "title" in ins .schema_read .__fields__
294297 assert "description" in ins .schema_read .__fields__
295298 assert "category" in ins .schema_read .__fields__
299+ assert "tags" in ins .schema_read .__fields__
296300 # test api
297301 res = await async_client .get ("/article/item/1" )
298302 items = res .json ()["data" ]
299- print (items )
300303 assert "id" not in items
301304 assert "category" in items
302305 assert items ["category" ]["name" ] == "Category_1"
303306 assert "content_text" in items
304- # assert items["user "]["username "] == "User_1 "
307+ assert items ["tags " ][0 ][ "name " ] == "Tag_1 "
305308
306309
307310async def test_update_fields_relationship (app : FastAPI , async_client : AsyncClient , fake_articles , async_session ):
0 commit comments