1- from typing import List , Union , Optional
21from unittest .mock import Mock , AsyncMock
32
43import pytest
54
6- from arcadepy ._types import NOT_GIVEN , NotGiven
75from arcadepy ._client import Arcade , AsyncArcade
86from arcadepy .resources .auth import AuthResource , AsyncAuthResource
97from arcadepy .types .shared .authorization_response import AuthorizationResponse
108
11- parametrize_scopes = pytest .mark .parametrize (
12- "scopes, expected_scopes" ,
13- [
14- (["scope1" ], "scope1" ),
15- (["scope1" , "scope2" ], "scope1 scope2" ),
16- (None , NOT_GIVEN ),
17- ],
18- )
19-
209
2110@pytest .fixture
2211def sync_auth_resource () -> AuthResource :
@@ -32,64 +21,57 @@ def async_auth_resource() -> AsyncAuthResource:
3221 return auth
3322
3423
35- @parametrize_scopes
36- def test_wait_for_completion_calls_status_from_auth_response (
37- sync_auth_resource : AuthResource , scopes : Optional [List [str ]], expected_scopes : Union [str , NotGiven ]
38- ) -> None :
24+ def test_wait_for_completion_calls_status_from_auth_response (sync_auth_resource : AuthResource ) -> None :
3925 auth = sync_auth_resource
4026 auth .status = Mock (return_value = AuthorizationResponse (status = "completed" )) # type: ignore
4127
42- auth_response = AuthorizationResponse (status = "pending" , authorization_id = "auth_id123" , scopes = scopes )
28+ auth_response = AuthorizationResponse (status = "pending" , id = "auth_id123" )
4329
4430 auth .wait_for_completion (auth_response )
4531
4632 auth .status .assert_called_with (
47- authorization_id = "auth_id123" ,
48- scopes = expected_scopes ,
33+ id = "auth_id123" ,
4934 wait = 45 ,
35+ timeout = 55.0 ,
5036 )
5137
5238
5339def test_wait_for_completion_raises_value_error_for_empty_authorization_id (sync_auth_resource : AuthResource ) -> None :
5440 auth = sync_auth_resource
55- auth_response = AuthorizationResponse (status = "pending" , authorization_id = "" , scopes = ["scope1" ])
41+ auth_response = AuthorizationResponse (status = "pending" , id = "" , scopes = ["scope1" ])
5642
5743 with pytest .raises (ValueError , match = "Authorization ID is required" ):
5844 auth .wait_for_completion (auth_response )
5945
6046
61- @parametrize_scopes
62- def test_wait_for_completion_calls_status_with_auth_id (
63- sync_auth_resource : AuthResource , scopes : Optional [List [str ]], expected_scopes : Union [str , NotGiven ]
64- ) -> None :
47+ def test_wait_for_completion_calls_status_with_auth_id (sync_auth_resource : AuthResource ) -> None :
6548 auth = sync_auth_resource
6649 auth .status = Mock (return_value = AuthorizationResponse (status = "completed" )) # type: ignore
6750
68- auth .wait_for_completion ("auth_id456" , scopes )
51+ auth .wait_for_completion ("auth_id456" )
6952
7053 auth .status .assert_called_with (
71- authorization_id = "auth_id456" ,
72- scopes = expected_scopes ,
54+ id = "auth_id456" ,
7355 wait = 45 ,
56+ timeout = 55.0 ,
7457 )
7558
7659
7760@pytest .mark .asyncio
78- @parametrize_scopes
7961async def test_async_wait_for_completion_calls_status_from_auth_response (
80- async_auth_resource : AsyncAuthResource , scopes : Optional [ List [ str ]], expected_scopes : Union [ str , NotGiven ]
62+ async_auth_resource : AsyncAuthResource ,
8163) -> None :
8264 auth = async_auth_resource
8365 auth .status = AsyncMock (return_value = AuthorizationResponse (status = "completed" )) # type: ignore
8466
85- auth_response = AuthorizationResponse (status = "pending" , authorization_id = "auth_id789" , scopes = scopes )
67+ auth_response = AuthorizationResponse (status = "pending" , id = "auth_id789" )
8668
8769 await auth .wait_for_completion (auth_response )
8870
8971 auth .status .assert_called_with (
90- authorization_id = "auth_id789" ,
91- scopes = expected_scopes ,
72+ id = "auth_id789" ,
9273 wait = 45 ,
74+ timeout = 55.0 ,
9375 )
9476
9577
@@ -98,24 +80,21 @@ async def test_async_wait_for_completion_raises_value_error_for_empty_authorizat
9880 async_auth_resource : AsyncAuthResource ,
9981) -> None :
10082 auth = async_auth_resource
101- auth_response = AuthorizationResponse (status = "pending" , authorization_id = "" , scopes = ["scope1" ])
83+ auth_response = AuthorizationResponse (status = "pending" , id = "" , scopes = ["scope1" ])
10284
10385 with pytest .raises (ValueError , match = "Authorization ID is required" ):
10486 await auth .wait_for_completion (auth_response )
10587
10688
10789@pytest .mark .asyncio
108- @parametrize_scopes
109- async def test_async_wait_for_completion_calls_status_with_auth_id (
110- async_auth_resource : AsyncAuthResource , scopes : Optional [List [str ]], expected_scopes : Union [str , NotGiven ]
111- ) -> None :
90+ async def test_async_wait_for_completion_calls_status_with_auth_id (async_auth_resource : AsyncAuthResource ) -> None :
11291 auth = async_auth_resource
11392 auth .status = AsyncMock (return_value = AuthorizationResponse (status = "completed" )) # type: ignore
11493
115- await auth .wait_for_completion ("auth_id321" , scopes )
94+ await auth .wait_for_completion ("auth_id321" )
11695
11796 auth .status .assert_called_with (
118- authorization_id = "auth_id321" ,
119- scopes = expected_scopes ,
97+ id = "auth_id321" ,
12098 wait = 45 ,
99+ timeout = 55.0 ,
121100 )
0 commit comments