@@ -33,7 +33,8 @@ def setup_tear_down(engine):
3333 note = Table ("note" , metadata , autoload = True , autoload_with = engine )
3434 user_params = [{"id" : i , "name" : faker .name ()} for i in range (1 , 43 )]
3535 note_params = [
36- {"user_id" : i % 42 + 1 , "id" : math .ceil (i / 42 )} for i in range (0 , 84 )
36+ {"user_id" : i % 42 + 1 , "id" : math .ceil (i / 42 ), "content" : faker .text ()}
37+ for i in range (0 , 84 )
3738 ]
3839 engine .execute (user .insert (), * user_params )
3940 engine .execute (note .insert (), * note_params )
@@ -74,10 +75,10 @@ class Note(Base):
7475 [(0 , 5 , 9 , 1 ), (10 , 10 , 5 , 2 ), (40 , 10 , 5 , 5 )],
7576)
7677def test_pagination (session , user_cls , offset , limit , total_pages , page_number ):
77- from fastapi_sqla import with_pagination
78+ from fastapi_sqla import Paginate
7879
7980 query = session .query (user_cls ).options (joinedload ("notes" ))
80- result = with_pagination (session , offset , limit )(query )
81+ result = Paginate (session , offset , limit )(query )
8182
8283 assert result .meta .total_items == 42
8384 assert result .meta .offset == offset
@@ -99,9 +100,9 @@ def test_Pagination_with_custom_count(
99100 .statement .with_only_columns ([func .count ()])
100101 .scalar ()
101102 )
102- with_pagination = Pagination (query_count = query_count )
103+ pagination = Pagination (query_count = query_count )
103104 query = session .query (user_cls ).options (joinedload ("notes" ))
104- result = with_pagination (session , offset , limit )(query )
105+ result = pagination (session , offset , limit )(query )
105106
106107 assert result .meta .total_items == 42
107108 assert result .meta .offset == offset
@@ -112,8 +113,7 @@ def test_Pagination_with_custom_count(
112113@fixture
113114def app (user_cls , note_cls ):
114115 from sqlalchemy .orm import joinedload
115-
116- from fastapi_sqla import Paginated , Session , setup , with_pagination
116+ from fastapi_sqla import Page , Paginate , Session , setup
117117
118118 app = FastAPI ()
119119 setup (app )
@@ -122,19 +122,21 @@ class Note(BaseModel):
122122 id : int
123123 content : str
124124
125+ class Config :
126+ orm_mode = True
127+
125128 class User (BaseModel ):
126129 id : int
127130 name : str
128131 notes : List [Note ]
129132
130- @app .get ("/users" )
131- def all_users (
132- session : Session = Depends (),
133- paginated_result = Depends (with_pagination ),
134- reponse_model = Paginated [User ],
135- ):
133+ class Config :
134+ orm_mode = True
135+
136+ @app .get ("/users" , response_model = Page [User ])
137+ def all_users (session : Session = Depends (), paginate : Paginate = Depends ()):
136138 query = session .query (user_cls ).options (joinedload ("notes" ))
137- return paginated_result (query )
139+ return paginate (query )
138140
139141 return app
140142
@@ -156,7 +158,7 @@ async def client(app):
156158async def test_functional (client , offset , items_number ):
157159 result = await client .get ("/users" , params = {"offset" : offset })
158160
159- assert result .status_code == 200
161+ assert result .status_code == 200 , result . json ()
160162 users = result .json ()["data" ]
161163 assert len (users ) == items_number
162164 user_ids = [u ["id" ] for u in users ]
0 commit comments