Skip to content

Commit 923e259

Browse files
🐛 Fix with_auth returning invalid client.
1 parent 1b384a5 commit 923e259

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/lapidary/runtime/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(
4949

5050
def with_auth(self, auth: httpx.Auth | None) -> typing.Self:
5151
return APIClient(
52-
self.ops,
52+
self._api_model,
5353
self._client,
5454
self._base_url,
5555
middlewares=self._middlewares,
@@ -126,7 +126,7 @@ def __init__(
126126
api_class: type[API_T],
127127
):
128128
self._api_class = api_class
129-
self._adapters = {}
129+
self._adapters: dict[str, OperationAdapter] = {}
130130

131131
def get(self, name: str) -> OperationAdapter:
132132
try:

tests/test_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ServerErrorModel(ModelBase):
5151

5252
DATE = dt.datetime(2024, 7, 28, 0, 55, tzinfo=dt.timezone.utc)
5353

54+
5455
# server
5556

5657

@@ -288,3 +289,13 @@ async def test_create_error(client: CatClient):
288289
with pytest.raises(UnexpectedResponse) as error:
289290
await client.cat_create(body=Cat(id=1, name='Benny'))
290291
assert error.value.response.status_code == 422
292+
293+
294+
def test_with_auth_returns_same_model():
295+
client = lapidary.runtime.client.for_api(CatClient, httpx.AsyncClient(), 'https://example.com')
296+
client2 = client.with_auth(httpx.BasicAuth('x', 'y'))
297+
298+
assert client._api_model is client2._api_model
299+
assert client._client is client2._client
300+
assert client._base_url is client2._base_url
301+
assert client._auth is not client2._auth

0 commit comments

Comments
 (0)