@@ -60,7 +60,7 @@ def obtain_challenge_input(self, metadata):
6060@pytest .mark .asyncio
6161async def test__get_challenges ():
6262 with mock .patch (
63- "google.oauth2._client_async._token_endpoint_request"
63+ "google.oauth2._client_async._token_endpoint_request" , new_callable = AsyncMock
6464 ) as mock_token_endpoint_request :
6565 await _reauth_async ._get_challenges (MOCK_REQUEST , ["SAML" ], "token" )
6666 mock_token_endpoint_request .assert_called_with (
@@ -75,7 +75,7 @@ async def test__get_challenges():
7575@pytest .mark .asyncio
7676async def test__get_challenges_with_scopes ():
7777 with mock .patch (
78- "google.oauth2._client_async._token_endpoint_request"
78+ "google.oauth2._client_async._token_endpoint_request" , new_callable = AsyncMock
7979 ) as mock_token_endpoint_request :
8080 await _reauth_async ._get_challenges (
8181 MOCK_REQUEST , ["SAML" ], "token" , requested_scopes = ["scope" ]
@@ -95,7 +95,7 @@ async def test__get_challenges_with_scopes():
9595@pytest .mark .asyncio
9696async def test__send_challenge_result ():
9797 with mock .patch (
98- "google.oauth2._client_async._token_endpoint_request"
98+ "google.oauth2._client_async._token_endpoint_request" , new_callable = AsyncMock
9999 ) as mock_token_endpoint_request :
100100 await _reauth_async ._send_challenge_result (
101101 MOCK_REQUEST , "123" , "1" , {"credential" : "password" }, "token"
@@ -171,7 +171,7 @@ async def test__run_next_challenge_success():
171171 "google.oauth2.challenges.AVAILABLE_CHALLENGES" , {"PASSWORD" : mock_challenge }
172172 ):
173173 with mock .patch (
174- "google.oauth2._reauth_async._send_challenge_result"
174+ "google.oauth2._reauth_async._send_challenge_result" , new_callable = AsyncMock
175175 ) as mock_send_challenge_result :
176176 await _reauth_async ._run_next_challenge (
177177 CHALLENGES_RESPONSE_TEMPLATE , MOCK_REQUEST , "token"
@@ -185,6 +185,7 @@ async def test__run_next_challenge_success():
185185async def test__obtain_rapt_authenticated ():
186186 with mock .patch (
187187 "google.oauth2._reauth_async._get_challenges" ,
188+ new_callable = AsyncMock ,
188189 return_value = CHALLENGES_RESPONSE_AUTHENTICATED ,
189190 ):
190191 new_rapt_token = await _reauth_async ._obtain_rapt (MOCK_REQUEST , "token" , None )
@@ -195,10 +196,12 @@ async def test__obtain_rapt_authenticated():
195196async def test__obtain_rapt_authenticated_after_run_next_challenge ():
196197 with mock .patch (
197198 "google.oauth2._reauth_async._get_challenges" ,
199+ new_callable = AsyncMock ,
198200 return_value = CHALLENGES_RESPONSE_TEMPLATE ,
199201 ):
200202 with mock .patch (
201203 "google.oauth2._reauth_async._run_next_challenge" ,
204+ new_callable = AsyncMock ,
202205 side_effect = [
203206 CHALLENGES_RESPONSE_TEMPLATE ,
204207 CHALLENGES_RESPONSE_AUTHENTICATED ,
@@ -216,7 +219,7 @@ async def test__obtain_rapt_unsupported_status():
216219 challenges_response = copy .deepcopy (CHALLENGES_RESPONSE_TEMPLATE )
217220 challenges_response ["status" ] = "STATUS_UNSPECIFIED"
218221 with mock .patch (
219- "google.oauth2._reauth_async._get_challenges" , return_value = challenges_response
222+ "google.oauth2._reauth_async._get_challenges" , new_callable = AsyncMock , return_value = challenges_response
220223 ):
221224 with pytest .raises (exceptions .ReauthFailError ) as excinfo :
222225 await _reauth_async ._obtain_rapt (MOCK_REQUEST , "token" , None )
@@ -227,6 +230,7 @@ async def test__obtain_rapt_unsupported_status():
227230async def test__obtain_rapt_not_interactive ():
228231 with mock .patch (
229232 "google.oauth2._reauth_async._get_challenges" ,
233+ new_callable = AsyncMock ,
230234 return_value = CHALLENGES_RESPONSE_TEMPLATE ,
231235 ):
232236 with mock .patch ("google.oauth2.reauth.is_interactive" , return_value = False ):
@@ -239,6 +243,7 @@ async def test__obtain_rapt_not_interactive():
239243async def test__obtain_rapt_not_authenticated ():
240244 with mock .patch (
241245 "google.oauth2._reauth_async._get_challenges" ,
246+ new_callable = AsyncMock ,
242247 return_value = CHALLENGES_RESPONSE_TEMPLATE ,
243248 ):
244249 with mock .patch ("google.oauth2.reauth.RUN_CHALLENGE_RETRY_LIMIT" , 0 ):
@@ -251,10 +256,11 @@ async def test__obtain_rapt_not_authenticated():
251256async def test_get_rapt_token ():
252257 with mock .patch (
253258 "google.oauth2._client_async.refresh_grant" ,
259+ new_callable = AsyncMock ,
254260 return_value = ("token" , None , None , None ),
255261 ) as mock_refresh_grant :
256262 with mock .patch (
257- "google.oauth2._reauth_async._obtain_rapt" , return_value = "new_rapt_token"
263+ "google.oauth2._reauth_async._obtain_rapt" , new_callable = AsyncMock , return_value = "new_rapt_token"
258264 ) as mock_obtain_rapt :
259265 assert (
260266 await _reauth_async .get_rapt_token (
@@ -282,7 +288,7 @@ async def test_get_rapt_token():
282288@pytest .mark .asyncio
283289async def test_refresh_grant_failed ():
284290 with mock .patch (
285- "google.oauth2._client_async._token_endpoint_request_no_throw"
291+ "google.oauth2._client_async._token_endpoint_request_no_throw" , new_callable = AsyncMock
286292 ) as mock_token_request :
287293 mock_token_request .return_value = (False , {"error" : "Bad request" }, True )
288294 with pytest .raises (exceptions .RefreshError ) as excinfo :
@@ -314,14 +320,14 @@ async def test_refresh_grant_failed():
314320@pytest .mark .asyncio
315321async def test_refresh_grant_success ():
316322 with mock .patch (
317- "google.oauth2._client_async._token_endpoint_request_no_throw"
323+ "google.oauth2._client_async._token_endpoint_request_no_throw" , new_callable = AsyncMock
318324 ) as mock_token_request :
319325 mock_token_request .side_effect = [
320326 (False , {"error" : "invalid_grant" , "error_subtype" : "rapt_required" }, True ),
321327 (True , {"access_token" : "access_token" }, None ),
322328 ]
323329 with mock .patch (
324- "google.oauth2._reauth_async.get_rapt_token" , return_value = "new_rapt_token"
330+ "google.oauth2._reauth_async.get_rapt_token" , new_callable = AsyncMock , return_value = "new_rapt_token"
325331 ):
326332 assert await _reauth_async .refresh_grant (
327333 MOCK_REQUEST ,
@@ -342,7 +348,7 @@ async def test_refresh_grant_success():
342348@pytest .mark .asyncio
343349async def test_refresh_grant_reauth_refresh_disabled ():
344350 with mock .patch (
345- "google.oauth2._client_async._token_endpoint_request_no_throw"
351+ "google.oauth2._client_async._token_endpoint_request_no_throw" , new_callable = AsyncMock
346352 ) as mock_token_request :
347353 mock_token_request .side_effect = [
348354 (
0 commit comments