@@ -4273,112 +4273,116 @@ async def test_for_httpx_modified_user_agent_multiple_strings(self) -> None:
4273
4273
"User-Agent"
4274
4274
] == self .user_agent_httpx ["User-Agent" ] + " " + " " .join (user_agent )
4275
4275
4276
-
4277
- class TestRestGetPaginatedAsync :
4278
- @pytest .fixture (autouse = True , scope = "function" )
4279
- def init_syn (self , syn : Synapse ) -> None :
4280
- self .syn = syn
4281
-
4282
- async def test_rest_get_paginated_async_with_results (self ) -> None :
4283
- # Mock the rest_get_async method to return paginated results
4284
- mock_responses = [
4285
- {"results" : [{"id" : 1 }, {"id" : 2 }, {"id" : 3 }]},
4286
- {"results" : [{"id" : 4 }, {"id" : 5 }]},
4287
- {"results" : []},
4288
- ]
4289
- with patch .object (
4290
- self .syn , "rest_get_async" , return_value = mock_responses
4291
- ) as mock_rest_get :
4292
- # Test the paginated get
4293
- results = []
4294
- async for result in self .syn .rest_get_paginated_async ("/test/uri" , limit = 3 ):
4295
- results .append (result )
4296
-
4297
- # Verify results
4298
- assert len (results ) == 5
4299
- assert [r ["id" ] for r in results ] == [1 , 2 , 3 , 4 , 5 ]
4300
-
4301
- # Verify rest_get_async was called with correct parameters
4302
- assert mock_rest_get .call_count == 3
4303
- call_list = [
4304
- call (uri = "/test/uri" , params = {"offset" : 0 , "limit" : 3 }),
4305
- call (uri = "/test/uri" , params = {"offset" : 3 , "limit" : 3 }),
4306
- call (uri = "/test/uri" , params = {"offset" : 6 , "limit" : 3 }),
4276
+ class TestRestGetPaginatedAsync :
4277
+ @pytest .fixture (autouse = True , scope = "function" )
4278
+ def init_syn (self , syn : Synapse ) -> None :
4279
+ self .syn = syn
4280
+
4281
+ async def test_rest_get_paginated_async_with_results (self ) -> None :
4282
+ # Mock the rest_get_async method to return paginated results
4283
+ mock_responses = [
4284
+ {"results" : [{"id" : 1 }, {"id" : 2 }, {"id" : 3 }]},
4285
+ {"results" : [{"id" : 4 }, {"id" : 5 }]},
4286
+ {"results" : []},
4307
4287
]
4308
- mock_rest_get .assert_has_calls (call_list )
4309
-
4310
- async def test_rest_get_paginated_async_with_children (self ) -> None :
4311
- # Mock the rest_get_async method to return paginated results with "children" key
4312
- mock_responses = [
4313
- {"children" : [{"id" : 1 }, {"id" : 2 }]},
4314
- {"children" : [{"id" : 3 }]},
4315
- {"children" : []},
4316
- ]
4317
4288
4318
- with patch .object (
4319
- self .syn , "rest_get_async" , return_value = mock_responses
4320
- ) as mock_rest_get :
4321
- # Test the paginated get
4322
- results = []
4323
- async for result in self .syn .rest_get_paginated_async ("/test/uri" , limit = 2 ):
4324
- results .append (result )
4325
-
4326
- # Verify results
4327
- assert len (results ) == 3
4328
- assert [r ["id" ] for r in results ] == [1 , 2 , 3 ]
4329
-
4330
- # Verify rest_get_async was called with correct parameters
4331
- assert mock_rest_get .call_count == 3
4332
- call_list = [
4333
- call (uri = "/test/uri" , params = {"offset" : 0 , "limit" : 2 }),
4334
- call (uri = "/test/uri" , params = {"offset" : 2 , "limit" : 2 }),
4335
- call (uri = "/test/uri" , params = {"offset" : 4 , "limit" : 2 }),
4289
+ with patch .object (
4290
+ self .syn , "rest_get_async" , side_effect = mock_responses
4291
+ ) as mock_rest_get :
4292
+ # Test the paginated get
4293
+ results = []
4294
+ async for result in self .syn .rest_get_paginated_async (
4295
+ "/test/uri" , limit = 3
4296
+ ):
4297
+ results .append (result )
4298
+
4299
+ # Verify results
4300
+ assert len (results ) == 5
4301
+ assert [r ["id" ] for r in results ] == [1 , 2 , 3 , 4 , 5 ]
4302
+
4303
+ # Verify rest_get_async was called with correct parameters
4304
+ assert mock_rest_get .call_count == 3
4305
+ call_list = [
4306
+ call (uri = "/test/uri" , params = {"offset" : 0 , "limit" : 3 }),
4307
+ call (uri = "/test/uri" , params = {"offset" : 3 , "limit" : 3 }),
4308
+ call (uri = "/test/uri" , params = {"offset" : 5 , "limit" : 3 }),
4309
+ ]
4310
+ mock_rest_get .assert_has_calls (call_list )
4311
+
4312
+ async def test_rest_get_paginated_async_with_children (self ) -> None :
4313
+ # Mock the rest_get_async method to return paginated results with "children" key
4314
+ mock_responses = [
4315
+ {"children" : [{"id" : 1 }, {"id" : 2 }]},
4316
+ {"children" : [{"id" : 3 }]},
4317
+ {"children" : []},
4336
4318
]
4337
- mock_rest_get .assert_has_calls (call_list )
4338
4319
4339
- async def test_rest_get_paginated_async_empty_response (self ) -> None :
4340
- # Mock the rest_get_async method to return empty results immediately
4341
- with patch .object (
4342
- self .syn , "rest_get_async" , return_value = {"results" : []}
4343
- ) as mock_rest_get :
4344
- # Test the paginated get
4345
- results = []
4346
- async for result in self .syn .rest_get_paginated_async ("/test/uri" ):
4347
- results .append (result )
4348
-
4349
- # Verify no results were returned
4350
- assert len (results ) == 0
4351
-
4352
- # Verify rest_get_async was called once with default parameters
4353
- mock_rest_get .assert_called_once_with (
4354
- uri = "/test/uri" , params = {"offset" : 0 , "limit" : 20 }
4355
- )
4356
-
4357
- async def test_rest_get_paginated_async_custom_limit (self ) -> None :
4358
- # Mock the rest_get_async method to return paginated results
4359
- mock_responses = [
4360
- {"results" : [{"id" : 1 }, {"id" : 2 }]},
4361
- {"results" : []},
4362
- ]
4320
+ with patch .object (
4321
+ self .syn , "rest_get_async" , side_effect = mock_responses
4322
+ ) as mock_rest_get :
4323
+ # Test the paginated get
4324
+ results = []
4325
+ async for result in self .syn .rest_get_paginated_async (
4326
+ "/test/uri" , limit = 2
4327
+ ):
4328
+ results .append (result )
4329
+
4330
+ # Verify results
4331
+ assert len (results ) == 3
4332
+ assert [r ["id" ] for r in results ] == [1 , 2 , 3 ]
4333
+
4334
+ # Verify rest_get_async was called with correct parameters
4335
+ assert mock_rest_get .call_count == 3
4336
+ call_list = [
4337
+ call (uri = "/test/uri" , params = {"offset" : 0 , "limit" : 2 }),
4338
+ call (uri = "/test/uri" , params = {"offset" : 2 , "limit" : 2 }),
4339
+ call (uri = "/test/uri" , params = {"offset" : 3 , "limit" : 2 }),
4340
+ ]
4341
+ mock_rest_get .assert_has_calls (call_list )
4342
+
4343
+ async def test_rest_get_paginated_async_empty_response (self ) -> None :
4344
+ # Mock the rest_get_async method to return empty results immediately
4345
+ with patch .object (
4346
+ self .syn , "rest_get_async" , return_value = {"results" : []}
4347
+ ) as mock_rest_get :
4348
+ # Test the paginated get
4349
+ results = []
4350
+ async for result in self .syn .rest_get_paginated_async ("/test/uri" ):
4351
+ results .append (result )
4352
+
4353
+ # Verify no results were returned
4354
+ assert len (results ) == 0
4355
+
4356
+ # Verify rest_get_async was called once with default parameters
4357
+ mock_rest_get .assert_called_once_with (
4358
+ uri = "/test/uri" , params = {"offset" : 0 , "limit" : 20 }
4359
+ )
4363
4360
4364
- with patch .object (
4365
- self .syn , "rest_get_async" , return_value = mock_responses
4366
- ) as mock_rest_get :
4367
- # Test the paginated get with custom limit
4368
- results = []
4369
- async for result in self .syn .rest_get_paginated_async (
4370
- "/test/uri" , limit = 2 , offset = 5
4371
- ):
4372
- results .append (result )
4373
-
4374
- # Verify results
4375
- assert len (results ) == 2
4376
- assert [r ["id" ] for r in results ] == [1 , 2 ]
4377
-
4378
- # Verify rest_get_async was called with correct parameters
4379
- assert mock_rest_get .call_count == 2
4380
- call_list = [
4381
- call (uri = "/test/uri" , params = {"offset" : 5 , "limit" : 2 }),
4382
- call (uri = "/test/uri" , params = {"offset" : 7 , "limit" : 2 }),
4361
+ async def test_rest_get_paginated_async_custom_limit (self ) -> None :
4362
+ # Mock the rest_get_async method to return paginated results
4363
+ mock_responses = [
4364
+ {"results" : [{"id" : 1 }, {"id" : 2 }]},
4365
+ {"results" : []},
4383
4366
]
4384
- mock_rest_get .assert_has_calls (call_list )
4367
+
4368
+ with patch .object (
4369
+ self .syn , "rest_get_async" , side_effect = mock_responses
4370
+ ) as mock_rest_get :
4371
+ # Test the paginated get with custom limit
4372
+ results = []
4373
+ async for result in self .syn .rest_get_paginated_async (
4374
+ "/test/uri" , limit = 2 , offset = 5
4375
+ ):
4376
+ results .append (result )
4377
+
4378
+ # Verify results
4379
+ assert len (results ) == 2
4380
+ assert [r ["id" ] for r in results ] == [1 , 2 ]
4381
+
4382
+ # Verify rest_get_async was called with correct parameters
4383
+ assert mock_rest_get .call_count == 2
4384
+ call_list = [
4385
+ call (uri = "/test/uri" , params = {"offset" : 5 , "limit" : 2 }),
4386
+ call (uri = "/test/uri" , params = {"offset" : 7 , "limit" : 2 }),
4387
+ ]
4388
+ mock_rest_get .assert_has_calls (call_list )
0 commit comments