@@ -218,7 +218,7 @@ def test_get_config_blocks(self):
218
218
self .assertEqual (1 , round (end_time - start_time ))
219
219
220
220
221
- @mock .patch ('requests.get' )
221
+ @mock .patch ('requests.Session. get' )
222
222
class PollingConfigManagerTest (base .BaseTest ):
223
223
def test_init__no_sdk_key_no_datafile__fails (self , _ ):
224
224
""" Test that initialization fails if there is no sdk_key or datafile provided. """
@@ -379,7 +379,7 @@ def test_fetch_datafile(self, _):
379
379
test_response .status_code = 200
380
380
test_response .headers = test_headers
381
381
test_response ._content = test_datafile
382
- with mock .patch ('requests.get' , return_value = test_response ) as mock_request :
382
+ with mock .patch ('requests.Session. get' , return_value = test_response ) as mock_request :
383
383
project_config_manager = config_manager .PollingConfigManager (sdk_key = sdk_key )
384
384
project_config_manager .stop ()
385
385
@@ -392,7 +392,7 @@ def test_fetch_datafile(self, _):
392
392
self .assertIsInstance (project_config_manager .get_config (), project_config .ProjectConfig )
393
393
394
394
# Call fetch_datafile again and assert that request to URL is with If-Modified-Since header.
395
- with mock .patch ('requests.get' , return_value = test_response ) as mock_requests :
395
+ with mock .patch ('requests.Session. get' , return_value = test_response ) as mock_requests :
396
396
project_config_manager ._initialize_thread ()
397
397
project_config_manager .start ()
398
398
project_config_manager .stop ()
@@ -421,7 +421,7 @@ def raise_for_status(self):
421
421
test_response .headers = test_headers
422
422
test_response ._content = test_datafile
423
423
424
- with mock .patch ('requests.get' , return_value = test_response ) as mock_request :
424
+ with mock .patch ('requests.Session. get' , return_value = test_response ) as mock_request :
425
425
project_config_manager = config_manager .PollingConfigManager (sdk_key = sdk_key , logger = mock_logger )
426
426
project_config_manager .stop ()
427
427
@@ -434,7 +434,7 @@ def raise_for_status(self):
434
434
self .assertIsInstance (project_config_manager .get_config (), project_config .ProjectConfig )
435
435
436
436
# Call fetch_datafile again, but raise exception this time
437
- with mock .patch ('requests.get' , return_value = MockExceptionResponse ()) as mock_requests :
437
+ with mock .patch ('requests.Session. get' , return_value = MockExceptionResponse ()) as mock_requests :
438
438
project_config_manager ._initialize_thread ()
439
439
project_config_manager .start ()
440
440
project_config_manager .stop ()
@@ -462,7 +462,7 @@ def test_fetch_datafile__request_exception_raised(self, _):
462
462
test_response .status_code = 200
463
463
test_response .headers = test_headers
464
464
test_response ._content = test_datafile
465
- with mock .patch ('requests.get' , return_value = test_response ) as mock_request :
465
+ with mock .patch ('requests.Session. get' , return_value = test_response ) as mock_request :
466
466
project_config_manager = config_manager .PollingConfigManager (sdk_key = sdk_key , logger = mock_logger )
467
467
project_config_manager .stop ()
468
468
@@ -476,7 +476,7 @@ def test_fetch_datafile__request_exception_raised(self, _):
476
476
477
477
# Call fetch_datafile again, but raise exception this time
478
478
with mock .patch (
479
- 'requests.get' ,
479
+ 'requests.Session. get' ,
480
480
side_effect = requests .exceptions .RequestException ('Error Error !!' ),
481
481
) as mock_requests :
482
482
project_config_manager ._initialize_thread ()
@@ -506,7 +506,7 @@ def test_fetch_datafile__exception_polling_thread_failed(self, _):
506
506
test_response .headers = test_headers
507
507
test_response ._content = test_datafile
508
508
509
- with mock .patch ('requests.get' , return_value = test_response ):
509
+ with mock .patch ('requests.Session. get' , return_value = test_response ):
510
510
project_config_manager = config_manager .PollingConfigManager (sdk_key = sdk_key ,
511
511
logger = mock_logger ,
512
512
update_interval = 12345678912345 )
@@ -516,8 +516,9 @@ def test_fetch_datafile__exception_polling_thread_failed(self, _):
516
516
# verify the error log message
517
517
log_messages = [args [0 ] for args , _ in mock_logger .error .call_args_list ]
518
518
for message in log_messages :
519
+ print (message )
519
520
if "Thread for background datafile polling failed. " \
520
- "Error: timestamp too large to convert to C _PyTime_t " not in message :
521
+ "Error: timestamp too large to convert to C PyTime_t " not in message :
521
522
assert False
522
523
523
524
def test_is_running (self , _ ):
@@ -529,7 +530,7 @@ def test_is_running(self, _):
529
530
project_config_manager .stop ()
530
531
531
532
532
- @mock .patch ('requests.get' )
533
+ @mock .patch ('requests.Session. get' )
533
534
class AuthDatafilePollingConfigManagerTest (base .BaseTest ):
534
535
def test_init__datafile_access_token_none__fails (self , _ ):
535
536
""" Test that initialization fails if datafile_access_token is None. """
@@ -569,7 +570,7 @@ def test_fetch_datafile(self, _):
569
570
test_response ._content = test_datafile
570
571
571
572
# Call fetch_datafile and assert that request was sent with correct authorization header
572
- with mock .patch ('requests.get' ,
573
+ with mock .patch ('requests.Session. get' ,
573
574
return_value = test_response ) as mock_request :
574
575
project_config_manager .fetch_datafile ()
575
576
@@ -596,7 +597,7 @@ def test_fetch_datafile__request_exception_raised(self, _):
596
597
test_response ._content = test_datafile
597
598
598
599
# Call fetch_datafile and assert that request was sent with correct authorization header
599
- with mock .patch ('requests.get' , return_value = test_response ) as mock_request :
600
+ with mock .patch ('requests.Session. get' , return_value = test_response ) as mock_request :
600
601
project_config_manager = config_manager .AuthDatafilePollingConfigManager (
601
602
datafile_access_token = datafile_access_token ,
602
603
sdk_key = sdk_key ,
@@ -614,7 +615,7 @@ def test_fetch_datafile__request_exception_raised(self, _):
614
615
615
616
# Call fetch_datafile again, but raise exception this time
616
617
with mock .patch (
617
- 'requests.get' ,
618
+ 'requests.Session. get' ,
618
619
side_effect = requests .exceptions .RequestException ('Error Error !!' ),
619
620
) as mock_requests :
620
621
project_config_manager ._initialize_thread ()
0 commit comments