Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle http:// urls for local development #83

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rossum_api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ async def _request(self, method: str, url: str, *args, **kwargs) -> httpx.Respon
base URL is prepended with base_url if needed
"""
# Do not force the calling site to always prepend the base URL
if not url.startswith("https://"):
if not url.startswith("https://") and not url.startswith("http://"):
url = f"{self.base_url}/{url}"
headers = kwargs.pop("headers", {})
headers["Authorization"] = f"token {self.token}"
Expand All @@ -471,7 +471,7 @@ async def _request(self, method: str, url: str, *args, **kwargs) -> httpx.Respon
async def _stream(self, method: str, url: str, *args, **kwargs) -> AsyncIterator[bytes]:
"""Performs a streaming HTTP call."""
# Do not force the calling site to alway prepend the base URL
if not url.startswith("https://"):
if not url.startswith("https://") and not url.startswith("http://"):
url = f"{self.base_url}/{url}"
headers = kwargs.pop("headers", {})
headers["Authorization"] = f"token {self.token}"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,15 @@ async def test_request_json_full_url(client, httpx_mock):
assert data == WORKSPACES[0]


@pytest.mark.asyncio
async def test_request_json_full_url_http(client, httpx_mock):
httpx_mock.add_response(
method="GET", url="http://localhost:8000/api/v1/workspaces/123", json=WORKSPACES[0]
)
data = await client.request_json("GET", "http://localhost:8000/api/v1/workspaces/123")
assert data == WORKSPACES[0]


@pytest.mark.asyncio
async def test_request_json_204(client, httpx_mock):
httpx_mock.add_response(
Expand Down
Loading