@@ -9,6 +9,7 @@ class TestGetPdsPatientDetails(unittest.TestCase):
99 def setUp (self ):
1010 self .test_patient_id = "9912003888"
1111 get_pds_service .__globals__ ["_pds_service" ] = None
12+ get_pds_service .__globals__ ["_pds_service_config" ] = None
1213
1314 self .logger_patcher = patch ("common.api_clients.get_pds_details.logger" )
1415 self .mock_logger = self .logger_patcher .start ()
@@ -25,6 +26,7 @@ def setUp(self):
2526
2627 def tearDown (self ):
2728 get_pds_service .__globals__ ["_pds_service" ] = None
29+ get_pds_service .__globals__ ["_pds_service_config" ] = None
2830 patch .stopall ()
2931
3032 def test_pds_get_patient_details_success (self ):
@@ -112,3 +114,46 @@ def test_whitespace_only_base_url_uses_authenticator(self):
112114 "ref" ,
113115 base_url = None ,
114116 )
117+
118+ @patch .dict ("os.environ" , {"PDS_ENV" : "ref" , "PDS_BASE_URL" : "https://mock-pds-v1.example/Patient" }, clear = False )
119+ def test_rebuilds_cached_service_when_base_url_changes (self ):
120+ pds_get_patient_details (self .test_patient_id )
121+
122+ self .mock_pds_service_class .reset_mock ()
123+ self .mock_pds_service_instance .get_patient_details .reset_mock ()
124+ new_instance = MagicMock ()
125+ self .mock_pds_service_class .return_value = new_instance
126+
127+ with patch .dict ("os.environ" , {"PDS_BASE_URL" : "https://mock-pds-v2.example/Patient" }, clear = False ):
128+ pds_get_patient_details ("1234567890" )
129+
130+ self .mock_auth_class .assert_not_called ()
131+ self .mock_pds_service_class .assert_called_once_with (
132+ None ,
133+ "ref" ,
134+ base_url = "https://mock-pds-v2.example/Patient" ,
135+ )
136+ new_instance .get_patient_details .assert_called_once_with ("1234567890" )
137+
138+ @patch .dict ("os.environ" , {"PDS_ENV" : "int" , "PDS_BASE_URL" : "" }, clear = False )
139+ def test_rebuilds_cached_service_when_environment_changes (self ):
140+ pds_get_patient_details (self .test_patient_id )
141+
142+ self .mock_pds_service_class .reset_mock ()
143+ self .mock_auth_class .reset_mock ()
144+ self .mock_pds_service_instance .get_patient_details .reset_mock ()
145+ new_auth = MagicMock ()
146+ new_service = MagicMock ()
147+ self .mock_auth_class .return_value = new_auth
148+ self .mock_pds_service_class .return_value = new_service
149+
150+ with patch .dict ("os.environ" , {"PDS_ENV" : "ref" , "PDS_BASE_URL" : "" }, clear = False ):
151+ pds_get_patient_details ("1234567890" )
152+
153+ self .mock_auth_class .assert_called_once_with (secret_manager_client = unittest .mock .ANY , environment = "ref" )
154+ self .mock_pds_service_class .assert_called_once_with (
155+ new_auth ,
156+ "ref" ,
157+ base_url = None ,
158+ )
159+ new_service .get_patient_details .assert_called_once_with ("1234567890" )
0 commit comments