fix(api-client): fix base_url joining for client v2 (#1998)
This commit is contained in:
parent
d9725003c5
commit
6f0ab7d8f2
|
@ -1,5 +1,4 @@
|
|||
from typing import Optional
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from loguru import logger
|
||||
from requests import Response
|
||||
|
@ -51,7 +50,9 @@ class Session(BaseSession):
|
|||
|
||||
def create_url(self, url):
|
||||
"""Create the URL based off this partial path."""
|
||||
return urljoin(self.base_url, url)
|
||||
if self.base_url is None:
|
||||
return url
|
||||
return f"{self.base_url.rstrip('/')}/{url.lstrip('/')}"
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import pytest
|
||||
|
||||
from libretime_api_client._client import Session
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"base_url, url, expected",
|
||||
[
|
||||
(None, "/path", "/path"),
|
||||
(None, "http://host/path", "http://host/path"),
|
||||
("http://host", "path", "http://host/path"),
|
||||
("http://host", "/path", "http://host/path"),
|
||||
("http://host/", "path", "http://host/path"),
|
||||
("http://host/", "/path", "http://host/path"),
|
||||
],
|
||||
)
|
||||
def test_session_create_url(base_url, url, expected):
|
||||
session = Session(base_url=base_url)
|
||||
assert session.create_url(url) == expected
|
|
@ -1,11 +1,20 @@
|
|||
import pytest
|
||||
|
||||
from libretime_api_client.v2 import ApiClient
|
||||
|
||||
|
||||
def test_api_client(requests_mock):
|
||||
api_client = ApiClient(base_url="http://localhost:8080", api_key="test-key")
|
||||
@pytest.mark.parametrize(
|
||||
"base_url",
|
||||
[
|
||||
("http://localhost:8080"),
|
||||
("http://localhost:8080/base"),
|
||||
],
|
||||
)
|
||||
def test_api_client(requests_mock, base_url):
|
||||
api_client = ApiClient(base_url=base_url, api_key="test-key")
|
||||
|
||||
requests_mock.get(
|
||||
"http://localhost:8080/api/v2/version",
|
||||
f"{base_url}/api/v2/version",
|
||||
json={"api_version": "2.0.0"},
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue