@@ -197,3 +197,120 @@ def test_iterate_entities_exactly_page(self, arkiv_client_http: Arkiv) -> None:
197197 # Verify all entity keys are present and unique
198198 result_keys = [entity .key for entity in entities ]
199199 assert set (result_keys ) == set (expected_keys )
200+
201+ def test_iterate_entities_max_results_within_single_page (
202+ self , arkiv_client_http : Arkiv
203+ ) -> None :
204+ """Test max_results limits iteration within a single page."""
205+ # Create 10 entities
206+ num_entities = 10
207+ batch_id , _ = create_test_entities (arkiv_client_http , num_entities )
208+
209+ # Query with max_results=3 and large page size
210+ # Should stop after 3 entities without fetching more
211+ query = f'batch_id = "{ batch_id } "'
212+ options = QueryOptions (
213+ attributes = KEY | ATTRIBUTES ,
214+ max_results = 3 ,
215+ max_results_per_page = 100 ,
216+ )
217+
218+ iterator = arkiv_client_http .arkiv .query_entities (query = query , options = options )
219+ entities = list (iterator )
220+
221+ assert len (entities ) == 3
222+ for entity in entities :
223+ assert entity .attributes is not None
224+ assert entity .attributes ["batch_id" ] == batch_id
225+
226+ def test_iterate_entities_max_results_across_pages (
227+ self , arkiv_client_http : Arkiv
228+ ) -> None :
229+ """Test max_results limits iteration across multiple pages."""
230+ # Create 10 entities
231+ num_entities = 10
232+ batch_id , _ = create_test_entities (arkiv_client_http , num_entities )
233+
234+ # Query with max_results=7 and page size of 3
235+ # Should iterate across 3 pages (3+3+1) and stop at 7
236+ query = f'batch_id = "{ batch_id } "'
237+ options = QueryOptions (
238+ attributes = KEY | ATTRIBUTES ,
239+ max_results = 7 ,
240+ max_results_per_page = 3 ,
241+ )
242+
243+ iterator = arkiv_client_http .arkiv .query_entities (query = query , options = options )
244+ entities = list (iterator )
245+
246+ assert len (entities ) == 7
247+ for entity in entities :
248+ assert entity .attributes is not None
249+ assert entity .attributes ["batch_id" ] == batch_id
250+
251+ def test_iterate_entities_max_results_equals_total (
252+ self , arkiv_client_http : Arkiv
253+ ) -> None :
254+ """Test max_results equal to total matching entities."""
255+ # Create 5 entities
256+ num_entities = 5
257+ batch_id , expected_keys = create_test_entities (arkiv_client_http , num_entities )
258+
259+ # Query with max_results=5 (exactly matching total)
260+ query = f'batch_id = "{ batch_id } "'
261+ options = QueryOptions (
262+ attributes = KEY | ATTRIBUTES ,
263+ max_results = 5 ,
264+ max_results_per_page = 10 ,
265+ )
266+
267+ iterator = arkiv_client_http .arkiv .query_entities (query = query , options = options )
268+ entities = list (iterator )
269+
270+ assert len (entities ) == 5
271+ result_keys = [entity .key for entity in entities ]
272+ assert set (result_keys ) == set (expected_keys )
273+
274+ def test_iterate_entities_max_results_exceeds_total (
275+ self , arkiv_client_http : Arkiv
276+ ) -> None :
277+ """Test max_results greater than total matching entities."""
278+ # Create 5 entities
279+ num_entities = 5
280+ batch_id , expected_keys = create_test_entities (arkiv_client_http , num_entities )
281+
282+ # Query with max_results=100 (more than available)
283+ query = f'batch_id = "{ batch_id } "'
284+ options = QueryOptions (
285+ attributes = KEY | ATTRIBUTES ,
286+ max_results = 100 ,
287+ max_results_per_page = 10 ,
288+ )
289+
290+ iterator = arkiv_client_http .arkiv .query_entities (query = query , options = options )
291+ entities = list (iterator )
292+
293+ # Should get all 5 entities (not artificially limited)
294+ assert len (entities ) == 5
295+ result_keys = [entity .key for entity in entities ]
296+ assert set (result_keys ) == set (expected_keys )
297+
298+ def test_iterate_entities_max_results_zero (self , arkiv_client_http : Arkiv ) -> None :
299+ """Test max_results=0 returns no entities."""
300+ # Create 5 entities
301+ num_entities = 5
302+ batch_id , _ = create_test_entities (arkiv_client_http , num_entities )
303+
304+ # Query with max_results=0
305+ query = f'batch_id = "{ batch_id } "'
306+ options = QueryOptions (
307+ attributes = KEY | ATTRIBUTES ,
308+ max_results = 0 ,
309+ max_results_per_page = 10 ,
310+ )
311+
312+ iterator = arkiv_client_http .arkiv .query_entities (query = query , options = options )
313+ entities = list (iterator )
314+
315+ # Should return no entities
316+ assert len (entities ) == 0
0 commit comments