1
- from typing import List , Union , Optional
2
1
from unittest .mock import Mock , AsyncMock
3
2
4
3
import pytest
5
4
6
- from arcadepy ._types import NOT_GIVEN , NotGiven
7
5
from arcadepy ._client import Arcade , AsyncArcade
8
6
from arcadepy .resources .auth import AuthResource , AsyncAuthResource
9
7
from arcadepy .types .shared .authorization_response import AuthorizationResponse
10
8
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
-
20
9
21
10
@pytest .fixture
22
11
def sync_auth_resource () -> AuthResource :
@@ -32,64 +21,57 @@ def async_auth_resource() -> AsyncAuthResource:
32
21
return auth
33
22
34
23
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 :
39
25
auth = sync_auth_resource
40
26
auth .status = Mock (return_value = AuthorizationResponse (status = "completed" )) # type: ignore
41
27
42
- auth_response = AuthorizationResponse (status = "pending" , authorization_id = "auth_id123" , scopes = scopes )
28
+ auth_response = AuthorizationResponse (status = "pending" , id = "auth_id123" )
43
29
44
30
auth .wait_for_completion (auth_response )
45
31
46
32
auth .status .assert_called_with (
47
- authorization_id = "auth_id123" ,
48
- scopes = expected_scopes ,
33
+ id = "auth_id123" ,
49
34
wait = 45 ,
35
+ timeout = 55.0 ,
50
36
)
51
37
52
38
53
39
def test_wait_for_completion_raises_value_error_for_empty_authorization_id (sync_auth_resource : AuthResource ) -> None :
54
40
auth = sync_auth_resource
55
- auth_response = AuthorizationResponse (status = "pending" , authorization_id = "" , scopes = ["scope1" ])
41
+ auth_response = AuthorizationResponse (status = "pending" , id = "" , scopes = ["scope1" ])
56
42
57
43
with pytest .raises (ValueError , match = "Authorization ID is required" ):
58
44
auth .wait_for_completion (auth_response )
59
45
60
46
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 :
65
48
auth = sync_auth_resource
66
49
auth .status = Mock (return_value = AuthorizationResponse (status = "completed" )) # type: ignore
67
50
68
- auth .wait_for_completion ("auth_id456" , scopes )
51
+ auth .wait_for_completion ("auth_id456" )
69
52
70
53
auth .status .assert_called_with (
71
- authorization_id = "auth_id456" ,
72
- scopes = expected_scopes ,
54
+ id = "auth_id456" ,
73
55
wait = 45 ,
56
+ timeout = 55.0 ,
74
57
)
75
58
76
59
77
60
@pytest .mark .asyncio
78
- @parametrize_scopes
79
61
async 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 ,
81
63
) -> None :
82
64
auth = async_auth_resource
83
65
auth .status = AsyncMock (return_value = AuthorizationResponse (status = "completed" )) # type: ignore
84
66
85
- auth_response = AuthorizationResponse (status = "pending" , authorization_id = "auth_id789" , scopes = scopes )
67
+ auth_response = AuthorizationResponse (status = "pending" , id = "auth_id789" )
86
68
87
69
await auth .wait_for_completion (auth_response )
88
70
89
71
auth .status .assert_called_with (
90
- authorization_id = "auth_id789" ,
91
- scopes = expected_scopes ,
72
+ id = "auth_id789" ,
92
73
wait = 45 ,
74
+ timeout = 55.0 ,
93
75
)
94
76
95
77
@@ -98,24 +80,21 @@ async def test_async_wait_for_completion_raises_value_error_for_empty_authorizat
98
80
async_auth_resource : AsyncAuthResource ,
99
81
) -> None :
100
82
auth = async_auth_resource
101
- auth_response = AuthorizationResponse (status = "pending" , authorization_id = "" , scopes = ["scope1" ])
83
+ auth_response = AuthorizationResponse (status = "pending" , id = "" , scopes = ["scope1" ])
102
84
103
85
with pytest .raises (ValueError , match = "Authorization ID is required" ):
104
86
await auth .wait_for_completion (auth_response )
105
87
106
88
107
89
@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 :
112
91
auth = async_auth_resource
113
92
auth .status = AsyncMock (return_value = AuthorizationResponse (status = "completed" )) # type: ignore
114
93
115
- await auth .wait_for_completion ("auth_id321" , scopes )
94
+ await auth .wait_for_completion ("auth_id321" )
116
95
117
96
auth .status .assert_called_with (
118
- authorization_id = "auth_id321" ,
119
- scopes = expected_scopes ,
97
+ id = "auth_id321" ,
120
98
wait = 45 ,
99
+ timeout = 55.0 ,
121
100
)
0 commit comments