@@ -211,9 +211,9 @@ def simple_query_data(simple_table):
211211
212212@pytest .fixture (scope = "module" )
213213def complex_query_data (complex_table ):
214- record_count = 20
214+ record_count = 500
215215 presets = [dict ()] * record_count
216- accounts = [str (uuid4 ()) for i in range (record_count // 4 )]
216+ accounts = [str (uuid4 ()) for i in range (4 )]
217217
218218 data = [
219219 complex_model_data_generator (account = accounts [i % 4 ], ** p )
@@ -386,6 +386,31 @@ def test_ordered_query_with_hash_key_complex(dynamo, complex_query_data, order):
386386 assert res_data == check_data
387387
388388
389+ @pytest .mark .parametrize ('order' , ('asc' , 'desc' ))
390+ def test_pagination_query_with_hash_key_complex (dynamo , complex_query_data , order ):
391+ page_size = 2
392+ middle_record = complex_query_data [(len (complex_query_data )// 2 )]
393+ query_rule = Rule (f"account == '{ middle_record ['account' ]} ' and sort_date_key >= '{ middle_record ['sort_date_key' ]} '" )
394+ res = ComplexKeyModel .query (query_rule , order = order , limit = page_size )
395+ res_data = [(m .account , m .sort_date_key ) for m in res ]
396+ check_data = sorted ([
397+ (m ["account" ], m ["sort_date_key" ])
398+ for m in complex_query_data
399+ if m ["account" ] == middle_record ['account' ] and m ["sort_date_key" ] >= middle_record ['sort_date_key' ]
400+ ], reverse = order == 'desc' )[:page_size ]
401+ assert res_data == check_data
402+ assert res .last_evaluated_key == check_data [- 1 ]
403+
404+ res = ComplexKeyModel .query (query_rule , order = order , limit = page_size , exclusive_start_key = res .last_evaluated_key )
405+ res_data = [(m .account , m .sort_date_key ) for m in res ]
406+ check_data = sorted ([
407+ (m ["account" ], m ["sort_date_key" ])
408+ for m in complex_query_data
409+ if m ["account" ] == middle_record ['account' ] and m ["sort_date_key" ] >= middle_record ['sort_date_key' ]
410+ ], reverse = order == 'desc' )[page_size :page_size * 2 ]
411+ assert res_data == check_data
412+
413+
389414def test_query_errors_with_nonprimary_key_complex (dynamo , complex_query_data ):
390415 data_by_expires = complex_query_data [:]
391416 data_by_expires .sort (key = lambda d : d ["expires" ])
0 commit comments