From a0f120811e64021f963d865574e43b0c70aa3447 Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Thu, 18 May 2023 09:11:57 +0000 Subject: [PATCH] chore(internal): add tests for base url handling --- tests/test_client.py | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index 16bf5b78..1bc0a33e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -342,6 +342,32 @@ class Model2(BaseModel): assert isinstance(response, Model1) assert response.foo == 1 + def test_base_url_trailing_slash(self) -> None: + client = Finch( + base_url="http://localhost:5000/custom/path/", access_token=access_token, _strict_response_validation=True + ) + request = client._build_request( + FinalRequestOptions( + method="post", + url="/foo", + json_data={"foo": "bar"}, + ), + ) + assert request.url == "http://localhost:5000/custom/path/foo" + + def test_base_url_no_trailing_slash(self) -> None: + client = Finch( + base_url="http://localhost:5000/custom/path", access_token=access_token, _strict_response_validation=True + ) + request = client._build_request( + FinalRequestOptions( + method="post", + url="/foo", + json_data={"foo": "bar"}, + ), + ) + assert request.url == "http://localhost:5000/custom/path/foo" + class TestAsyncFinch: client = AsyncFinch(base_url=base_url, access_token=access_token, _strict_response_validation=True) @@ -658,3 +684,29 @@ class Model2(BaseModel): response = await self.client.get("/foo", cast_to=cast(Any, Union[Model1, Model2])) assert isinstance(response, Model1) assert response.foo == 1 + + def test_base_url_trailing_slash(self) -> None: + client = AsyncFinch( + base_url="http://localhost:5000/custom/path/", access_token=access_token, _strict_response_validation=True + ) + request = client._build_request( + FinalRequestOptions( + method="post", + url="/foo", + json_data={"foo": "bar"}, + ), + ) + assert request.url == "http://localhost:5000/custom/path/foo" + + def test_base_url_no_trailing_slash(self) -> None: + client = AsyncFinch( + base_url="http://localhost:5000/custom/path", access_token=access_token, _strict_response_validation=True + ) + request = client._build_request( + FinalRequestOptions( + method="post", + url="/foo", + json_data={"foo": "bar"}, + ), + ) + assert request.url == "http://localhost:5000/custom/path/foo"