Skip to content

Commit 0dc6b17

Browse files
authored
feat!: Update helper methods for client breaking changes (#78)
* feat!: Update helper methods for client breaking changes * Cleanup
1 parent d3df7da commit 0dc6b17

File tree

2 files changed

+25
-59
lines changed

2 files changed

+25
-59
lines changed

src/arcadepy/resources/auth.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,7 @@ def status(
168168
cast_to=AuthorizationResponse,
169169
)
170170

171-
def wait_for_completion(
172-
self,
173-
auth_response_or_id: AuthorizationResponse | str,
174-
scopes: list[str] | None = None,
175-
) -> AuthorizationResponse:
171+
def wait_for_completion(self, auth_response_or_id: AuthorizationResponse | str) -> AuthorizationResponse:
176172
"""
177173
Waits for the authorization process to complete, for example:
178174
@@ -182,23 +178,19 @@ def wait_for_completion(
182178
```
183179
"""
184180
auth_id_val: str
185-
scopes_val: str | NotGiven = NOT_GIVEN
186181

187182
if isinstance(auth_response_or_id, AuthorizationResponse):
188-
if not auth_response_or_id.authorization_id:
183+
if not auth_response_or_id.id:
189184
raise ValueError("Authorization ID is required")
190-
auth_id_val = auth_response_or_id.authorization_id
191-
scopes_val = " ".join(auth_response_or_id.scopes) if auth_response_or_id.scopes else NOT_GIVEN
185+
auth_id_val = auth_response_or_id.id
192186
auth_response = auth_response_or_id
193187
else:
194188
auth_id_val = auth_response_or_id
195-
scopes_val = " ".join(scopes) if scopes else NOT_GIVEN
196189
auth_response = AuthorizationResponse()
197190

198191
while auth_response.status != "completed":
199192
auth_response = self.status(
200-
authorization_id=auth_id_val,
201-
scopes=scopes_val,
193+
id=auth_id_val,
202194
wait=_DEFAULT_LONGPOLL_WAIT_TIME,
203195
)
204196
return auth_response
@@ -349,7 +341,6 @@ async def status(
349341
async def wait_for_completion(
350342
self,
351343
auth_response_or_id: AuthorizationResponse | str,
352-
scopes: list[str] | None = None,
353344
) -> AuthorizationResponse:
354345
"""
355346
Waits for the authorization process to complete, for example:
@@ -360,23 +351,19 @@ async def wait_for_completion(
360351
```
361352
"""
362353
auth_id_val: str
363-
scopes_val: str | NotGiven = NOT_GIVEN
364354

365355
if isinstance(auth_response_or_id, AuthorizationResponse):
366-
if not auth_response_or_id.authorization_id:
356+
if not auth_response_or_id.id:
367357
raise ValueError("Authorization ID is required")
368-
auth_id_val = auth_response_or_id.authorization_id
369-
scopes_val = " ".join(auth_response_or_id.scopes) if auth_response_or_id.scopes else NOT_GIVEN
358+
auth_id_val = auth_response_or_id.id
370359
auth_response = auth_response_or_id
371360
else:
372361
auth_id_val = auth_response_or_id
373-
scopes_val = " ".join(scopes) if scopes else NOT_GIVEN
374362
auth_response = AuthorizationResponse()
375363

376364
while auth_response.status != "completed":
377365
auth_response = await self.status(
378-
authorization_id=auth_id_val,
379-
scopes=scopes_val,
366+
id=auth_id_val,
380367
wait=_DEFAULT_LONGPOLL_WAIT_TIME,
381368
)
382369
return auth_response
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)