@@ -169,3 +169,47 @@ async def test_get_multi_by_cursor_desc_with_cursor_filter(async_session, test_d
169
169
assert (
170
170
record ["id" ] < first_page_last_id
171
171
), "Each ID in the second page should be less than the last ID of the first page"
172
+
173
+
174
+ @pytest .mark .asyncio
175
+ async def test_get_multi_by_cursor_descending_order (async_session , test_data ):
176
+ for item in test_data :
177
+ async_session .add (ModelTest (** item ))
178
+ await async_session .commit ()
179
+
180
+ crud = FastCRUD (ModelTest )
181
+
182
+ first_page = await crud .get_multi_by_cursor (
183
+ db = async_session ,
184
+ limit = 2 ,
185
+ sort_column = "id" ,
186
+ sort_order = "desc"
187
+ )
188
+ next_cursor = first_page ["next_cursor" ]
189
+ item1 , item2 = first_page ["data" ][0 ]["id" ], first_page ["data" ][1 ]["id" ]
190
+
191
+ assert len (first_page ["data" ]) == 2
192
+ assert first_page ["data" ][0 ]["id" ] == 11 # Should start with highest ID
193
+ assert first_page ["data" ][1 ]["id" ] == 10
194
+ assert first_page ["next_cursor" ] == 10 # Next cursor should be the last ID in the result
195
+
196
+ while next_cursor is not None :
197
+ next_page = await crud .get_multi_by_cursor (
198
+ db = async_session ,
199
+ cursor = next_cursor ,
200
+ limit = 2 ,
201
+ sort_column = "id" ,
202
+ sort_order = "desc"
203
+ )
204
+ next_cursor = next_page ["next_cursor" ]
205
+ if len (next_page ["data" ]) == 2 :
206
+ assert next_page ["data" ][0 ]["id" ] == item1 - 2
207
+ assert next_page ["data" ][1 ]["id" ] == item2 - 2
208
+ assert next_cursor == item2 - 2
209
+ item1 -= 2
210
+ item2 -= 2
211
+ else :
212
+ assert next_page ["data" ][0 ]["id" ] == item1 - 2
213
+ assert next_cursor is None
214
+
215
+
0 commit comments