Skip to content
Open
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
20 changes: 16 additions & 4 deletions mpt_api_client/mpt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ def __init__(
self.http_client = http_client or AsyncHTTPClient()

@classmethod
def from_config(cls, api_token: str, base_url: str) -> Self:
def from_config(
cls,
api_token: str,
base_url: str,
timeout: float = 60.0,
) -> Self:
"""Create MPT client from configuration.

Args:
api_token: MPT API Token
base_url: MPT Base URL
timeout: HTTP request timeout in seconds. Defaults to 60.0.

Returns:
MPT Client

"""
return cls(AsyncHTTPClient(base_url=base_url, api_token=api_token))
return cls(AsyncHTTPClient(base_url=base_url, api_token=api_token, timeout=timeout))

@property
def catalog(self) -> AsyncCatalog:
Expand Down Expand Up @@ -88,18 +94,24 @@ def __init__(
self.http_client = http_client or HTTPClient()

@classmethod
def from_config(cls, api_token: str, base_url: str) -> Self:
def from_config(
cls,
api_token: str,
base_url: str,
timeout: float = 60.0,
) -> Self:
"""Create MPT client from configuration.

Args:
api_token: MPT API Token
base_url: MPT Base URL
timeout: HTTP request timeout in seconds. Defaults to 60.0.

Returns:
MPT Client

"""
return cls(HTTPClient(base_url=base_url, api_token=api_token))
return cls(HTTPClient(base_url=base_url, api_token=api_token, timeout=timeout))

@property
def commerce(self) -> Commerce:
Expand Down
35 changes: 23 additions & 12 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,49 @@ def base_url():


@pytest.fixture
def mpt_vendor(base_url):
return MPTClient.from_config(api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url) # type: ignore
def api_timeout():
return float(os.getenv("MPT_API_TIMEOUT", "60.0"))


@pytest.fixture
def async_mpt_vendor(base_url):
def mpt_vendor(base_url, api_timeout):
return MPTClient.from_config(
api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url, timeout=api_timeout
) # type: ignore


@pytest.fixture
def async_mpt_vendor(base_url, api_timeout):
return AsyncMPTClient.from_config(
api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url
api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url, timeout=api_timeout
) # type: ignore


@pytest.fixture
def mpt_ops(base_url):
return MPTClient.from_config(api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url) # type: ignore
def mpt_ops(base_url, api_timeout):
return MPTClient.from_config(
api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url, timeout=api_timeout
) # type: ignore


@pytest.fixture
def async_mpt_ops(base_url):
def async_mpt_ops(base_url, api_timeout):
return AsyncMPTClient.from_config(
api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url
api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url, timeout=api_timeout
) # type: ignore


@pytest.fixture
def mpt_client(base_url):
return MPTClient.from_config(api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url) # type: ignore
def mpt_client(base_url, api_timeout):
return MPTClient.from_config(
api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url, timeout=api_timeout
) # type: ignore


@pytest.fixture
def async_mpt_client(base_url):
def async_mpt_client(base_url, api_timeout):
return AsyncMPTClient.from_config(
api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url
api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url, timeout=api_timeout
) # type: ignore


Expand Down
Loading