Skip to content

Commit 723f1f6

Browse files
committed
feat!: Update helper methods for client breaking changes
1 parent 2a5b07f commit 723f1f6

File tree

2 files changed

+27
-59
lines changed

2 files changed

+27
-59
lines changed

src/arcadepy/resources/auth.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,7 @@ def status(
164164
cast_to=AuthorizationResponse,
165165
)
166166

167-
def wait_for_completion(
168-
self,
169-
auth_response_or_id: AuthorizationResponse | str,
170-
scopes: list[str] | None = None,
171-
) -> AuthorizationResponse:
167+
def wait_for_completion(self, auth_response_or_id: AuthorizationResponse | str) -> AuthorizationResponse:
172168
"""
173169
Waits for the authorization process to complete, for example:
174170
@@ -178,24 +174,21 @@ def wait_for_completion(
178174
```
179175
"""
180176
auth_id_val: str
181-
scopes_val: str | NotGiven = NOT_GIVEN
182177

183178
if isinstance(auth_response_or_id, AuthorizationResponse):
184-
if not auth_response_or_id.authorization_id:
179+
if not auth_response_or_id.id:
185180
raise ValueError("Authorization ID is required")
186-
auth_id_val = auth_response_or_id.authorization_id
187-
scopes_val = " ".join(auth_response_or_id.scopes) if auth_response_or_id.scopes else NOT_GIVEN
181+
auth_id_val = auth_response_or_id.id
188182
auth_response = auth_response_or_id
189183
else:
190184
auth_id_val = auth_response_or_id
191-
scopes_val = " ".join(scopes) if scopes else NOT_GIVEN
192185
auth_response = AuthorizationResponse()
193186

194187
while auth_response.status != "completed":
195188
auth_response = self.status(
196-
authorization_id=auth_id_val,
197-
scopes=scopes_val,
189+
id=auth_id_val,
198190
wait=_DEFAULT_LONGPOLL_WAIT_TIME,
191+
timeout=float(_DEFAULT_LONGPOLL_WAIT_TIME + 10),
199192
)
200193
return auth_response
201194

@@ -341,7 +334,6 @@ async def status(
341334
async def wait_for_completion(
342335
self,
343336
auth_response_or_id: AuthorizationResponse | str,
344-
scopes: list[str] | None = None,
345337
) -> AuthorizationResponse:
346338
"""
347339
Waits for the authorization process to complete, for example:
@@ -352,24 +344,21 @@ async def wait_for_completion(
352344
```
353345
"""
354346
auth_id_val: str
355-
scopes_val: str | NotGiven = NOT_GIVEN
356347

357348
if isinstance(auth_response_or_id, AuthorizationResponse):
358-
if not auth_response_or_id.authorization_id:
349+
if not auth_response_or_id.id:
359350
raise ValueError("Authorization ID is required")
360-
auth_id_val = auth_response_or_id.authorization_id
361-
scopes_val = " ".join(auth_response_or_id.scopes) if auth_response_or_id.scopes else NOT_GIVEN
351+
auth_id_val = auth_response_or_id.id
362352
auth_response = auth_response_or_id
363353
else:
364354
auth_id_val = auth_response_or_id
365-
scopes_val = " ".join(scopes) if scopes else NOT_GIVEN
366355
auth_response = AuthorizationResponse()
367356

368357
while auth_response.status != "completed":
369358
auth_response = await self.status(
370-
authorization_id=auth_id_val,
371-
scopes=scopes_val,
359+
id=auth_id_val,
372360
wait=_DEFAULT_LONGPOLL_WAIT_TIME,
361+
timeout=float(_DEFAULT_LONGPOLL_WAIT_TIME + 10),
373362
)
374363
return auth_response
375364

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
from typing import List, Union, Optional
21
from unittest.mock import Mock, AsyncMock
32

43
import pytest
54

6-
from arcadepy._types import NOT_GIVEN, NotGiven
75
from arcadepy._client import Arcade, AsyncArcade
86
from arcadepy.resources.auth import AuthResource, AsyncAuthResource
97
from 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
2211
def 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

5339
def 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
7961
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,
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

Comments
 (0)