Skip to content

Commit e4dcd85

Browse files
author
Robert Segal
committed
Added accounts api tokens endpoints
1 parent 7b59f65 commit e4dcd85

4 files changed

Lines changed: 102 additions & 2 deletions

File tree

mpt_api_client/resources/accounts/accounts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
22
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
3+
from mpt_api_client.resources.accounts.api_tokens import ApiTokensService, AsyncApiTokensService
34

45

56
class Accounts:
@@ -13,6 +14,11 @@ def accounts(self) -> AccountsService:
1314
"""Accounts service."""
1415
return AccountsService(http_client=self.http_client)
1516

17+
@property
18+
def api_tokens(self) -> ApiTokensService:
19+
"""API Tokens service."""
20+
return ApiTokensService(http_client=self.http_client)
21+
1622

1723
class AsyncAccounts:
1824
"""Async Accounts MPT API Module."""
@@ -24,3 +30,8 @@ def __init__(self, *, http_client: AsyncHTTPClient):
2430
def accounts(self) -> AsyncAccountsService:
2531
"""Accounts service."""
2632
return AsyncAccountsService(http_client=self.http_client)
33+
34+
@property
35+
def api_tokens(self) -> AsyncApiTokensService:
36+
"""API Tokens service."""
37+
return AsyncApiTokensService(http_client=self.http_client)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
AsyncDeleteMixin,
5+
AsyncUpdateMixin,
6+
CreateMixin,
7+
DeleteMixin,
8+
UpdateMixin,
9+
)
10+
from mpt_api_client.models import Model
11+
from mpt_api_client.resources.accounts.mixins import AsyncEnablableMixin, EnablableMixin
12+
13+
14+
class ApiToken(Model):
15+
"""API Token Model."""
16+
17+
18+
class ApiTokensServiceConfig:
19+
"""API Tokens Service Configuration."""
20+
21+
_endpoint = "/public/v1/accounts/api-tokens"
22+
_model_class = ApiToken
23+
_collection_key = "data"
24+
25+
26+
class ApiTokensService(
27+
CreateMixin[ApiToken],
28+
DeleteMixin,
29+
UpdateMixin[ApiToken],
30+
EnablableMixin[ApiToken],
31+
Service[ApiToken],
32+
ApiTokensServiceConfig,
33+
):
34+
"""API Tokens Service."""
35+
36+
37+
class AsyncApiTokensService(
38+
AsyncCreateMixin[ApiToken],
39+
AsyncDeleteMixin,
40+
AsyncUpdateMixin[ApiToken],
41+
AsyncEnablableMixin[ApiToken],
42+
AsyncService[ApiToken],
43+
ApiTokensServiceConfig,
44+
):
45+
"""Async API Tokens Service."""

tests/resources/accounts/test_accounts.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
44
from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts
5+
from mpt_api_client.resources.accounts.api_tokens import (
6+
ApiTokensService,
7+
AsyncApiTokensService,
8+
)
59

610

711
@pytest.fixture
@@ -15,7 +19,11 @@ def async_accounts(async_http_client):
1519

1620

1721
@pytest.mark.parametrize(
18-
("property_name", "expected_service_class"), [("accounts", AccountsService)]
22+
("property_name", "expected_service_class"),
23+
[
24+
("accounts", AccountsService),
25+
("api_tokens", ApiTokensService),
26+
],
1927
)
2028
def test_accounts_properties(accounts, property_name, expected_service_class):
2129
"""Test that Accounts properties return correct instances."""
@@ -26,7 +34,11 @@ def test_accounts_properties(accounts, property_name, expected_service_class):
2634

2735

2836
@pytest.mark.parametrize(
29-
("property_name", "expected_service_class"), [("accounts", AsyncAccountsService)]
37+
("property_name", "expected_service_class"),
38+
[
39+
("accounts", AsyncAccountsService),
40+
("api_tokens", AsyncApiTokensService),
41+
],
3042
)
3143
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
3244
"""Test that AsyncAccounts properties return correct instances."""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.accounts.api_tokens import (
4+
ApiTokensService,
5+
AsyncApiTokensService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def api_tokens_service(http_client):
11+
return ApiTokensService(http_client=http_client)
12+
13+
14+
@pytest.fixture
15+
def async_api_tokens_service(async_http_client):
16+
return AsyncApiTokensService(http_client=async_http_client)
17+
18+
19+
@pytest.mark.parametrize(
20+
"method",
21+
["get", "create", "update", "delete", "enable", "disable"],
22+
)
23+
def test_api_tokens_mixins_present(api_tokens_service, method):
24+
assert hasattr(api_tokens_service, method)
25+
26+
27+
@pytest.mark.parametrize(
28+
"method",
29+
["get", "create", "update", "delete", "enable", "disable"],
30+
)
31+
def test_async_api_tokens_mixins_present(async_api_tokens_service, method):
32+
assert hasattr(async_api_tokens_service, method)

0 commit comments

Comments
 (0)