@@ -37,22 +37,26 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
3737
3838 return wrapper
3939
40- @patch ("gateway_api.apim_app_auth.http.SessionManager " )
40+ @patch ("gateway_api.apim_app_auth.apim.APIMAppAuthStub " )
4141 @patch ("gateway_api.apim_app_auth.apim.jwt.encode" )
42- def test_auth (self , mock_jwt : MagicMock , mock_session_manager : MagicMock ) -> None :
43- mock_session_manager . with_session = self . mock_with_session
44-
42+ def test_auth (
43+ self , mock_jwt : MagicMock , mock_apmim_app_auth_stub : MagicMock
44+ ) -> None :
4545 expected_client_assertion = "client_assertion"
4646 mock_jwt .return_value = expected_client_assertion
4747
4848 expected_access_token = "access_token" # noqa S105 - Dummy value
4949 expected_expires_in = timedelta (seconds = 5 )
5050
51- self .mock_session .post .return_value .json .return_value = {
51+ (
52+ mock_apmim_app_auth_stub .return_value .session_post .return_value .json .return_value
53+ ) = {
5254 "access_token" : expected_access_token ,
5355 "expires_in" : expected_expires_in .total_seconds (),
5456 }
55- self .mock_session .post .return_value .status_code = 200
57+ mock_apmim_app_auth_stub .return_value .session_post .return_value .status_code = (
58+ 200
59+ )
5660
5761 expected_api_key = "api_key"
5862 expected_token_endpoint = "token_endpoint" # noqa S106 - Dummy value
@@ -63,7 +67,7 @@ def test_auth(self, mock_jwt: MagicMock, mock_session_manager: MagicMock) -> Non
6367 api_key = expected_api_key ,
6468 token_validity_threshold = timedelta (minutes = 5 ),
6569 token_endpoint = expected_token_endpoint ,
66- session_manager = mock_session_manager ,
70+ session_manager = Mock () ,
6771 )
6872
6973 @apim_authenticator .auth
@@ -128,24 +132,26 @@ def method(_: requests.Session) -> None:
128132
129133 method ()
130134
131- @patch ("gateway_api.apim_app_auth.http.SessionManager " )
135+ @patch ("gateway_api.apim_app_auth.apim.APIMAppAuthStub " )
132136 @patch ("gateway_api.apim_app_auth.apim.jwt.encode" )
133137 def test_auth_existing_invalid_token (
134- self , mock_jwt : MagicMock , mock_session_manager : MagicMock
138+ self , mock_jwt : MagicMock , mock_apmim_app_auth_stub : MagicMock
135139 ) -> None :
136- mock_session_manager .with_session = self .mock_with_session
137-
138140 expected_client_assertion = "client_assertion"
139141 mock_jwt .return_value = expected_client_assertion
140142
141143 expected_access_token = "access_token" # noqa S105 - Dummy value
142144 expected_expires_in = timedelta (seconds = 5 )
143145
144- self .mock_session .post .return_value .json .return_value = {
146+ (
147+ mock_apmim_app_auth_stub .return_value .session_post .return_value .json .return_value
148+ ) = {
145149 "access_token" : expected_access_token ,
146150 "expires_in" : expected_expires_in .total_seconds (),
147151 }
148- self .mock_session .post .return_value .status_code = 200
152+ mock_apmim_app_auth_stub .return_value .session_post .return_value .status_code = (
153+ 200
154+ )
149155
150156 expected_api_key = "api_key"
151157 expected_token_endpoint = "token_endpoint" # noqa S106 - Dummy value
@@ -156,7 +162,7 @@ def test_auth_existing_invalid_token(
156162 api_key = expected_api_key ,
157163 token_validity_threshold = timedelta (minutes = 5 ),
158164 token_endpoint = expected_token_endpoint ,
159- session_manager = mock_session_manager ,
165+ session_manager = Mock () ,
160166 )
161167
162168 apim_authenticator ._access_token = { # noqa SLF001 - Private access to support testing
@@ -223,17 +229,21 @@ def method(_: requests.Session) -> None:
223229 with pytest .raises (ApimAuthenticationException ):
224230 method ()
225231
232+ @patch ("gateway_api.apim_app_auth.apim.APIMAppAuthStub" )
226233 @patch ("gateway_api.apim_app_auth.http.SessionManager" )
227234 @patch ("gateway_api.apim_app_auth.apim.jwt.encode" )
228235 def test_auth_session_post_raises_exception (
229- self , mock_jwt : MagicMock , mock_session_manager : MagicMock
236+ self ,
237+ mock_jwt : MagicMock ,
238+ mock_session_manager : MagicMock ,
239+ mock_apim_app_auth_stub : MagicMock ,
230240 ) -> None :
231241 mock_session_manager .with_session = self .mock_with_session
232242
233243 mock_jwt .return_value = "client_assertion"
234244
235- self . mock_session . post .side_effect = requests . RequestException (
236- "Connection failed"
245+ mock_apim_app_auth_stub . return_value . session_post .side_effect = (
246+ requests . RequestException ( "Connection failed" )
237247 )
238248
239249 apim_authenticator = ApimAuthenticator (
0 commit comments