Skip to content

Commit 503528d

Browse files
author
Robert Segal
committed
Adding accounts endpoints
1 parent 7ecc4f0 commit 503528d

9 files changed

Lines changed: 193 additions & 23 deletions

File tree

mpt_api_client/mpt_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
44
from mpt_api_client.resources import (
5+
Accounts,
6+
AsyncAccounts,
57
AsyncAudit,
68
AsyncBilling,
79
AsyncCatalog,
@@ -56,6 +58,11 @@ def billing(self) -> AsyncBilling:
5658
"""Billing MPT API Client."""
5759
return AsyncBilling(http_client=self.http_client)
5860

61+
@property
62+
def accounts(self) -> AsyncAccounts:
63+
"""Accounts MPT API Client."""
64+
return AsyncAccounts(http_client=self.http_client)
65+
5966

6067
class MPTClient:
6168
"""MPT API Client."""
@@ -104,3 +111,8 @@ def audit(self) -> Audit:
104111
def billing(self) -> Billing:
105112
"""Billing MPT API Client."""
106113
return Billing(http_client=self.http_client)
114+
115+
@property
116+
def accounts(self) -> Accounts:
117+
"""Accounts MPT API Client."""
118+
return Accounts(http_client=self.http_client)

mpt_api_client/resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from mpt_api_client.resources.accounts import Accounts, AsyncAccounts
12
from mpt_api_client.resources.audit import AsyncAudit, Audit
23
from mpt_api_client.resources.billing import AsyncBilling, Billing
34
from mpt_api_client.resources.catalog import AsyncCatalog, Catalog
45
from mpt_api_client.resources.commerce import AsyncCommerce, Commerce
56

67
__all__ = [ # noqa: WPS410
8+
"Accounts",
9+
"AsyncAccounts",
710
"AsyncAudit",
811
"AsyncBilling",
912
"AsyncCatalog",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts
2+
3+
__all__ = ["Accounts", "AsyncAccounts"] # noqa: WPS410
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
AsyncUpdateMixin,
5+
CreateMixin,
6+
UpdateMixin,
7+
)
8+
from mpt_api_client.models import Model
9+
10+
11+
class Account(Model):
12+
"""Account resource."""
13+
14+
15+
class AccountsServiceConfig:
16+
"""Accounts service configuration."""
17+
18+
_endpoint = "/public/v1/accounts"
19+
_model_class = Account
20+
_collection_key = "data"
21+
22+
23+
class AccountsService(
24+
CreateMixin[Account],
25+
UpdateMixin[Account],
26+
Service[Account],
27+
AccountsServiceConfig,
28+
):
29+
"""Accounts service."""
30+
31+
32+
class AsyncAccountsService(
33+
AsyncCreateMixin[Account],
34+
AsyncUpdateMixin[Account],
35+
AsyncService[Account],
36+
AccountsServiceConfig,
37+
):
38+
"""Async Accounts service."""
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
2+
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
3+
4+
5+
class Accounts:
6+
"""Accounts MPT API Module."""
7+
8+
def __init__(self, *, http_client: HTTPClient):
9+
self.http_client = http_client
10+
11+
@property
12+
def accounts(self) -> AccountsService:
13+
"""Accounts service."""
14+
return AccountsService(http_client=self.http_client)
15+
16+
17+
class AsyncAccounts:
18+
"""Async Accounts MPT API Module."""
19+
20+
def __init__(self, *, http_client: AsyncHTTPClient):
21+
self.http_client = http_client
22+
23+
@property
24+
def accounts(self) -> AsyncAccountsService:
25+
"""Accounts service."""
26+
return AsyncAccountsService(http_client=self.http_client)

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ extend-ignore =
3232

3333

3434
per-file-ignores =
35+
mpt_api_client/resources/accounts/*.py: WPS215
3536
mpt_api_client/resources/audit/*.py: WPS215
3637
mpt_api_client/resources/billing/*.py: WPS215 WPS202 WPS214 WPS204
3738
mpt_api_client/resources/catalog/*.py: WPS110 WPS215 WPS214
3839
mpt_api_client/resources/commerce/*.py: WPS215
3940
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
4041
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
4142
mpt_api_client/http/mixins.py: WPS202
43+
mpt_api_client/mpt_client.py: WPS235
4244
tests/http/test_async_service.py: WPS204 WPS202
4345
tests/http/test_service.py: WPS204 WPS202
4446
tests/http/test_mixins.py: WPS204 WPS202
4547
tests/resources/catalog/test_products.py: WPS202 WPS210
4648
tests/resources/*/test_mixins.py: WPS118 WPS202 WPS204
49+
tests/test_mpt.py: WPS210 WPS218 WPS235
4750

4851
tests/*:
4952
# Allow magic strings.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
4+
5+
6+
@pytest.fixture
7+
def account_service(http_client):
8+
return AccountsService(http_client=http_client)
9+
10+
11+
@pytest.fixture
12+
def async_account_service(async_http_client):
13+
return AsyncAccountsService(http_client=async_http_client)
14+
15+
16+
@pytest.mark.parametrize("method", ["get", "create", "update"])
17+
def test_mixins_present(account_service, method):
18+
assert hasattr(account_service, method)
19+
20+
21+
@pytest.mark.parametrize("method", ["get", "create", "update"])
22+
def test_async_mixins_present(async_account_service, method):
23+
assert hasattr(async_account_service, method)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
4+
from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts
5+
6+
7+
@pytest.fixture
8+
def accounts(http_client):
9+
return Accounts(http_client=http_client)
10+
11+
12+
@pytest.fixture
13+
def async_accounts(async_http_client):
14+
return AsyncAccounts(http_client=async_http_client)
15+
16+
17+
@pytest.mark.parametrize(
18+
("property_name", "expected_service_class"), [("accounts", AccountsService)]
19+
)
20+
def test_accounts_properties(accounts, property_name, expected_service_class):
21+
"""Test that Accounts properties return correct instances."""
22+
service = getattr(accounts, property_name)
23+
24+
assert isinstance(service, expected_service_class)
25+
assert service.http_client is accounts.http_client
26+
27+
28+
@pytest.mark.parametrize(
29+
("property_name", "expected_service_class"), [("accounts", AsyncAccountsService)]
30+
)
31+
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
32+
"""Test that AsyncAccounts properties return correct instances."""
33+
service = getattr(async_accounts, property_name)
34+
35+
assert isinstance(service, expected_service_class)
36+
assert service.http_client is async_accounts.http_client
37+
38+
39+
def test_accounts_initialization(http_client):
40+
accounts = Accounts(http_client=http_client)
41+
42+
assert accounts.http_client is http_client
43+
assert isinstance(accounts, Accounts)
44+
45+
46+
def test_async_accounts_initialization(async_http_client):
47+
accounts = AsyncAccounts(http_client=async_http_client)
48+
49+
assert accounts.http_client is async_http_client
50+
assert isinstance(accounts, AsyncAccounts)

tests/test_mpt.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
44
from mpt_api_client.mpt_client import AsyncMPTClient, MPTClient
55
from mpt_api_client.resources import (
6+
Accounts,
7+
AsyncAccounts,
68
AsyncAudit,
79
AsyncBilling,
810
AsyncCatalog,
@@ -15,18 +17,27 @@
1517
from tests.conftest import API_TOKEN, API_URL
1618

1719

18-
def test_mpt_client() -> None:
19-
mpt = MPTClient.from_config(base_url=API_URL, api_token=API_TOKEN)
20-
commerce = mpt.commerce
21-
catalog = mpt.catalog
22-
audit = mpt.audit
23-
billing = mpt.billing
20+
def get_mpt_client():
21+
return MPTClient.from_config(base_url=API_URL, api_token=API_TOKEN)
2422

25-
assert isinstance(mpt, MPTClient)
26-
assert isinstance(commerce, Commerce)
27-
assert isinstance(catalog, Catalog)
28-
assert isinstance(audit, Audit)
29-
assert isinstance(billing, Billing)
23+
24+
def get_async_mpt_client():
25+
return AsyncMPTClient.from_config(base_url=API_URL, api_token=API_TOKEN)
26+
27+
28+
@pytest.mark.parametrize(
29+
("domain_module", "domain_type"),
30+
[
31+
(get_mpt_client(), MPTClient),
32+
(get_mpt_client().commerce, Commerce),
33+
(get_mpt_client().catalog, Catalog),
34+
(get_mpt_client().audit, Audit),
35+
(get_mpt_client().billing, Billing),
36+
(get_mpt_client().accounts, Accounts),
37+
],
38+
)
39+
def test_mpt_client(domain_module, domain_type) -> None:
40+
assert isinstance(domain_module, domain_type)
3041

3142

3243
def test_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -39,18 +50,19 @@ def test_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None:
3950
assert isinstance(mpt.http_client, HTTPClient)
4051

4152

42-
def test_async_mpt_client() -> None:
43-
mpt = AsyncMPTClient.from_config(base_url=API_URL, api_token=API_TOKEN)
44-
commerce = mpt.commerce
45-
catalog = mpt.catalog
46-
audit = mpt.audit
47-
billing = mpt.billing
48-
49-
assert isinstance(mpt, AsyncMPTClient)
50-
assert isinstance(commerce, AsyncCommerce)
51-
assert isinstance(catalog, AsyncCatalog)
52-
assert isinstance(audit, AsyncAudit)
53-
assert isinstance(billing, AsyncBilling)
53+
@pytest.mark.parametrize(
54+
("domain_module", "domain_type"),
55+
[
56+
(get_async_mpt_client(), AsyncMPTClient),
57+
(get_async_mpt_client().commerce, AsyncCommerce),
58+
(get_async_mpt_client().catalog, AsyncCatalog),
59+
(get_async_mpt_client().audit, AsyncAudit),
60+
(get_async_mpt_client().billing, AsyncBilling),
61+
(get_async_mpt_client().accounts, AsyncAccounts),
62+
],
63+
)
64+
def test_async_mpt_client(domain_module, domain_type) -> None:
65+
assert isinstance(domain_module, domain_type)
5466

5567

5668
def test_async_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None:

0 commit comments

Comments
 (0)