@@ -218,7 +218,7 @@ def test_get_config_blocks(self):
218218 self .assertEqual (1 , round (end_time - start_time ))
219219
220220
221- @mock .patch ('requests.get' )
221+ @mock .patch ('requests.Session. get' )
222222class PollingConfigManagerTest (base .BaseTest ):
223223 def test_init__no_sdk_key_no_datafile__fails (self , _ ):
224224 """ Test that initialization fails if there is no sdk_key or datafile provided. """
@@ -379,7 +379,7 @@ def test_fetch_datafile(self, _):
379379 test_response .status_code = 200
380380 test_response .headers = test_headers
381381 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 :
383383 project_config_manager = config_manager .PollingConfigManager (sdk_key = sdk_key )
384384 project_config_manager .stop ()
385385
@@ -392,7 +392,7 @@ def test_fetch_datafile(self, _):
392392 self .assertIsInstance (project_config_manager .get_config (), project_config .ProjectConfig )
393393
394394 # 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 :
396396 project_config_manager ._initialize_thread ()
397397 project_config_manager .start ()
398398 project_config_manager .stop ()
@@ -421,7 +421,7 @@ def raise_for_status(self):
421421 test_response .headers = test_headers
422422 test_response ._content = test_datafile
423423
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 :
425425 project_config_manager = config_manager .PollingConfigManager (sdk_key = sdk_key , logger = mock_logger )
426426 project_config_manager .stop ()
427427
@@ -434,7 +434,7 @@ def raise_for_status(self):
434434 self .assertIsInstance (project_config_manager .get_config (), project_config .ProjectConfig )
435435
436436 # 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 :
438438 project_config_manager ._initialize_thread ()
439439 project_config_manager .start ()
440440 project_config_manager .stop ()
@@ -462,7 +462,7 @@ def test_fetch_datafile__request_exception_raised(self, _):
462462 test_response .status_code = 200
463463 test_response .headers = test_headers
464464 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 :
466466 project_config_manager = config_manager .PollingConfigManager (sdk_key = sdk_key , logger = mock_logger )
467467 project_config_manager .stop ()
468468
@@ -476,7 +476,7 @@ def test_fetch_datafile__request_exception_raised(self, _):
476476
477477 # Call fetch_datafile again, but raise exception this time
478478 with mock .patch (
479- 'requests.get' ,
479+ 'requests.Session. get' ,
480480 side_effect = requests .exceptions .RequestException ('Error Error !!' ),
481481 ) as mock_requests :
482482 project_config_manager ._initialize_thread ()
@@ -506,7 +506,7 @@ def test_fetch_datafile__exception_polling_thread_failed(self, _):
506506 test_response .headers = test_headers
507507 test_response ._content = test_datafile
508508
509- with mock .patch ('requests.get' , return_value = test_response ):
509+ with mock .patch ('requests.Session. get' , return_value = test_response ):
510510 project_config_manager = config_manager .PollingConfigManager (sdk_key = sdk_key ,
511511 logger = mock_logger ,
512512 update_interval = 12345678912345 )
@@ -516,8 +516,9 @@ def test_fetch_datafile__exception_polling_thread_failed(self, _):
516516 # verify the error log message
517517 log_messages = [args [0 ] for args , _ in mock_logger .error .call_args_list ]
518518 for message in log_messages :
519+ print (message )
519520 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 :
521522 assert False
522523
523524 def test_is_running (self , _ ):
@@ -529,7 +530,7 @@ def test_is_running(self, _):
529530 project_config_manager .stop ()
530531
531532
532- @mock .patch ('requests.get' )
533+ @mock .patch ('requests.Session. get' )
533534class AuthDatafilePollingConfigManagerTest (base .BaseTest ):
534535 def test_init__datafile_access_token_none__fails (self , _ ):
535536 """ Test that initialization fails if datafile_access_token is None. """
@@ -569,7 +570,7 @@ def test_fetch_datafile(self, _):
569570 test_response ._content = test_datafile
570571
571572 # 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' ,
573574 return_value = test_response ) as mock_request :
574575 project_config_manager .fetch_datafile ()
575576
@@ -596,7 +597,7 @@ def test_fetch_datafile__request_exception_raised(self, _):
596597 test_response ._content = test_datafile
597598
598599 # 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 :
600601 project_config_manager = config_manager .AuthDatafilePollingConfigManager (
601602 datafile_access_token = datafile_access_token ,
602603 sdk_key = sdk_key ,
@@ -614,7 +615,7 @@ def test_fetch_datafile__request_exception_raised(self, _):
614615
615616 # Call fetch_datafile again, but raise exception this time
616617 with mock .patch (
617- 'requests.get' ,
618+ 'requests.Session. get' ,
618619 side_effect = requests .exceptions .RequestException ('Error Error !!' ),
619620 ) as mock_requests :
620621 project_config_manager ._initialize_thread ()
0 commit comments