diff --git a/mpt_api_client/mpt_client.py b/mpt_api_client/mpt_client.py index 5fcb410..a5eb358 100644 --- a/mpt_api_client/mpt_client.py +++ b/mpt_api_client/mpt_client.py @@ -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: @@ -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: diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index 194ca62..dedec67 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -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