Skip to content

Commit

Permalink
fix(client): correct base_url setter implementation (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Dec 18, 2023
1 parent 18d5e21 commit 25e96d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/finch/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def base_url(self) -> URL:

@base_url.setter
def base_url(self, url: URL | str) -> None:
self._client.base_url = url if isinstance(url, URL) else URL(url)
self._base_url = self._enforce_trailing_slash(url if isinstance(url, URL) else URL(url))

@lru_cache(maxsize=None)
def platform_headers(self) -> Dict[str, str]:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,16 @@ class Model(BaseModel):
assert isinstance(response, Model)
assert response.foo == 2

def test_base_url_setter(self) -> None:
client = Finch(
base_url="https://example.com/from_init", access_token=access_token, _strict_response_validation=True
)
assert client.base_url == "https://example.com/from_init/"

client.base_url = "https://example.com/from_setter" # type: ignore[assignment]

assert client.base_url == "https://example.com/from_setter/"

def test_base_url_env(self) -> None:
with update_env(FINCH_BASE_URL="http://localhost:5000/from/env"):
client = Finch(access_token=access_token, _strict_response_validation=True)
Expand Down Expand Up @@ -1135,6 +1145,16 @@ class Model(BaseModel):
assert isinstance(response, Model)
assert response.foo == 2

def test_base_url_setter(self) -> None:
client = AsyncFinch(
base_url="https://example.com/from_init", access_token=access_token, _strict_response_validation=True
)
assert client.base_url == "https://example.com/from_init/"

client.base_url = "https://example.com/from_setter" # type: ignore[assignment]

assert client.base_url == "https://example.com/from_setter/"

def test_base_url_env(self) -> None:
with update_env(FINCH_BASE_URL="http://localhost:5000/from/env"):
client = AsyncFinch(access_token=access_token, _strict_response_validation=True)
Expand Down

0 comments on commit 25e96d6

Please sign in to comment.