Skip to content

Commit 10538e2

Browse files
authored
MPT-19342 E2E API client has exceptions in the execution creating users (#239)
2 parents 8c05542 + 3640a45 commit 10538e2

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

mpt_api_client/mpt_client.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,24 @@ def __init__(
2929
self.http_client = http_client or AsyncHTTPClient()
3030

3131
@classmethod
32-
def from_config(cls, api_token: str, base_url: str) -> Self:
32+
def from_config(
33+
cls,
34+
api_token: str,
35+
base_url: str,
36+
timeout: float = 60.0,
37+
) -> Self:
3338
"""Create MPT client from configuration.
3439
3540
Args:
3641
api_token: MPT API Token
3742
base_url: MPT Base URL
43+
timeout: HTTP request timeout in seconds. Defaults to 60.0.
3844
3945
Returns:
4046
MPT Client
4147
4248
"""
43-
return cls(AsyncHTTPClient(base_url=base_url, api_token=api_token))
49+
return cls(AsyncHTTPClient(base_url=base_url, api_token=api_token, timeout=timeout))
4450

4551
@property
4652
def catalog(self) -> AsyncCatalog:
@@ -88,18 +94,24 @@ def __init__(
8894
self.http_client = http_client or HTTPClient()
8995

9096
@classmethod
91-
def from_config(cls, api_token: str, base_url: str) -> Self:
97+
def from_config(
98+
cls,
99+
api_token: str,
100+
base_url: str,
101+
timeout: float = 60.0,
102+
) -> Self:
92103
"""Create MPT client from configuration.
93104
94105
Args:
95106
api_token: MPT API Token
96107
base_url: MPT Base URL
108+
timeout: HTTP request timeout in seconds. Defaults to 60.0.
97109
98110
Returns:
99111
MPT Client
100112
101113
"""
102-
return cls(HTTPClient(base_url=base_url, api_token=api_token))
114+
return cls(HTTPClient(base_url=base_url, api_token=api_token, timeout=timeout))
103115

104116
@property
105117
def commerce(self) -> Commerce:

tests/e2e/conftest.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,49 @@ def base_url():
1616

1717

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

2222

2323
@pytest.fixture
24-
def async_mpt_vendor(base_url):
24+
def mpt_vendor(base_url, api_timeout):
25+
return MPTClient.from_config(
26+
api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url, timeout=api_timeout
27+
) # type: ignore
28+
29+
30+
@pytest.fixture
31+
def async_mpt_vendor(base_url, api_timeout):
2532
return AsyncMPTClient.from_config(
26-
api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url
33+
api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url, timeout=api_timeout
2734
) # type: ignore
2835

2936

3037
@pytest.fixture
31-
def mpt_ops(base_url):
32-
return MPTClient.from_config(api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url) # type: ignore
38+
def mpt_ops(base_url, api_timeout):
39+
return MPTClient.from_config(
40+
api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url, timeout=api_timeout
41+
) # type: ignore
3342

3443

3544
@pytest.fixture
36-
def async_mpt_ops(base_url):
45+
def async_mpt_ops(base_url, api_timeout):
3746
return AsyncMPTClient.from_config(
38-
api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url
47+
api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url, timeout=api_timeout
3948
) # type: ignore
4049

4150

4251
@pytest.fixture
43-
def mpt_client(base_url):
44-
return MPTClient.from_config(api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url) # type: ignore
52+
def mpt_client(base_url, api_timeout):
53+
return MPTClient.from_config(
54+
api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url, timeout=api_timeout
55+
) # type: ignore
4556

4657

4758
@pytest.fixture
48-
def async_mpt_client(base_url):
59+
def async_mpt_client(base_url, api_timeout):
4960
return AsyncMPTClient.from_config(
50-
api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url
61+
api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url, timeout=api_timeout
5162
) # type: ignore
5263

5364

0 commit comments

Comments
 (0)