Skip to content

Commit eda001e

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

File tree

2 files changed

+21
-39
lines changed

2 files changed

+21
-39
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

tests/api_resources/test_auth_wait.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_wait_for_completion_calls_status_from_auth_response(
3939
auth = sync_auth_resource
4040
auth.status = Mock(return_value=AuthorizationResponse(status="completed")) # type: ignore
4141

42-
auth_response = AuthorizationResponse(status="pending", authorization_id="auth_id123", scopes=scopes)
42+
auth_response = AuthorizationResponse(status="pending", id="auth_id123", scopes=scopes)
4343

4444
auth.wait_for_completion(auth_response)
4545

@@ -52,43 +52,39 @@ def test_wait_for_completion_calls_status_from_auth_response(
5252

5353
def test_wait_for_completion_raises_value_error_for_empty_authorization_id(sync_auth_resource: AuthResource) -> None:
5454
auth = sync_auth_resource
55-
auth_response = AuthorizationResponse(status="pending", authorization_id="", scopes=["scope1"])
55+
auth_response = AuthorizationResponse(status="pending", id="", scopes=["scope1"])
5656

5757
with pytest.raises(ValueError, match="Authorization ID is required"):
5858
auth.wait_for_completion(auth_response)
5959

6060

6161
@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:
62+
def test_wait_for_completion_calls_status_with_auth_id(sync_auth_resource: AuthResource) -> None:
6563
auth = sync_auth_resource
6664
auth.status = Mock(return_value=AuthorizationResponse(status="completed")) # type: ignore
6765

68-
auth.wait_for_completion("auth_id456", scopes)
66+
auth.wait_for_completion("auth_id456")
6967

7068
auth.status.assert_called_with(
71-
authorization_id="auth_id456",
72-
scopes=expected_scopes,
69+
id="auth_id456",
7370
wait=45,
7471
)
7572

7673

7774
@pytest.mark.asyncio
7875
@parametrize_scopes
7976
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]
77+
async_auth_resource: AsyncAuthResource, scopes: Optional[List[str]]
8178
) -> None:
8279
auth = async_auth_resource
8380
auth.status = AsyncMock(return_value=AuthorizationResponse(status="completed")) # type: ignore
8481

85-
auth_response = AuthorizationResponse(status="pending", authorization_id="auth_id789", scopes=scopes)
82+
auth_response = AuthorizationResponse(status="pending", id="auth_id789", scopes=scopes)
8683

8784
await auth.wait_for_completion(auth_response)
8885

8986
auth.status.assert_called_with(
90-
authorization_id="auth_id789",
91-
scopes=expected_scopes,
87+
id="auth_id789",
9288
wait=45,
9389
)
9490

@@ -98,24 +94,21 @@ async def test_async_wait_for_completion_raises_value_error_for_empty_authorizat
9894
async_auth_resource: AsyncAuthResource,
9995
) -> None:
10096
auth = async_auth_resource
101-
auth_response = AuthorizationResponse(status="pending", authorization_id="", scopes=["scope1"])
97+
auth_response = AuthorizationResponse(status="pending", id="", scopes=["scope1"])
10298

10399
with pytest.raises(ValueError, match="Authorization ID is required"):
104100
await auth.wait_for_completion(auth_response)
105101

106102

107103
@pytest.mark.asyncio
108104
@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:
105+
async def test_async_wait_for_completion_calls_status_with_auth_id(async_auth_resource: AsyncAuthResource) -> None:
112106
auth = async_auth_resource
113107
auth.status = AsyncMock(return_value=AuthorizationResponse(status="completed")) # type: ignore
114108

115-
await auth.wait_for_completion("auth_id321", scopes)
109+
await auth.wait_for_completion("auth_id321")
116110

117111
auth.status.assert_called_with(
118-
authorization_id="auth_id321",
119-
scopes=expected_scopes,
112+
id="auth_id321",
120113
wait=45,
121114
)

0 commit comments

Comments
 (0)