Skip to content
Merged
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
11 changes: 11 additions & 0 deletions mpt_api_client/resources/accounts/accounts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
from mpt_api_client.resources.accounts.api_tokens import ApiTokensService, AsyncApiTokensService
from mpt_api_client.resources.accounts.licensees import AsyncLicenseesService, LicenseesService
from mpt_api_client.resources.accounts.sellers import AsyncSellersService, SellersService
from mpt_api_client.resources.accounts.user_groups import (
Expand Down Expand Up @@ -40,6 +41,11 @@ def user_groups(self) -> UserGroupsService:
"""User Groups service."""
return UserGroupsService(http_client=self.http_client)

@property
def api_tokens(self) -> ApiTokensService:
"""API Tokens service."""
return ApiTokensService(http_client=self.http_client)


class AsyncAccounts:
"""Async Accounts MPT API Module."""
Expand Down Expand Up @@ -71,3 +77,8 @@ def licensees(self) -> AsyncLicenseesService:
def user_groups(self) -> AsyncUserGroupsService:
"""User Groups service."""
return AsyncUserGroupsService(http_client=self.http_client)

@property
def api_tokens(self) -> AsyncApiTokensService:
"""API Tokens service."""
return AsyncApiTokensService(http_client=self.http_client)
45 changes: 45 additions & 0 deletions mpt_api_client/resources/accounts/api_tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.accounts.mixins import AsyncEnablableMixin, EnablableMixin


class ApiToken(Model):
"""API Token Model."""


class ApiTokensServiceConfig:
"""API Tokens Service Configuration."""

_endpoint = "/public/v1/accounts/api-tokens"
_model_class = ApiToken
_collection_key = "data"


class ApiTokensService(
CreateMixin[ApiToken],
DeleteMixin,
UpdateMixin[ApiToken],
EnablableMixin[ApiToken],
Service[ApiToken],
ApiTokensServiceConfig,
):
"""API Tokens Service."""


class AsyncApiTokensService(
AsyncCreateMixin[ApiToken],
AsyncDeleteMixin,
AsyncUpdateMixin[ApiToken],
AsyncEnablableMixin[ApiToken],
AsyncService[ApiToken],
ApiTokensServiceConfig,
):
"""Async API Tokens Service."""
6 changes: 6 additions & 0 deletions tests/resources/accounts/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts
from mpt_api_client.resources.accounts.api_tokens import (
ApiTokensService,
AsyncApiTokensService,
)
from mpt_api_client.resources.accounts.licensees import AsyncLicenseesService, LicenseesService
from mpt_api_client.resources.accounts.sellers import AsyncSellersService, SellersService
from mpt_api_client.resources.accounts.user_groups import (
Expand Down Expand Up @@ -29,6 +33,7 @@ def async_accounts(async_http_client):
("sellers", SellersService),
("licensees", LicenseesService),
("user_groups", UserGroupsService),
("api_tokens", ApiTokensService),
],
)
def test_accounts_properties(accounts, property_name, expected_service_class):
Expand All @@ -47,6 +52,7 @@ def test_accounts_properties(accounts, property_name, expected_service_class):
("sellers", AsyncSellersService),
("licensees", AsyncLicenseesService),
("user_groups", AsyncUserGroupsService),
("api_tokens", AsyncApiTokensService),
],
)
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
Expand Down
32 changes: 32 additions & 0 deletions tests/resources/accounts/test_api_tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from mpt_api_client.resources.accounts.api_tokens import (
ApiTokensService,
AsyncApiTokensService,
)


@pytest.fixture
def api_tokens_service(http_client):
return ApiTokensService(http_client=http_client)


@pytest.fixture
def async_api_tokens_service(async_http_client):
return AsyncApiTokensService(http_client=async_http_client)


@pytest.mark.parametrize(
"method",
["get", "create", "update", "delete", "enable", "disable"],
)
def test_api_tokens_mixins_present(api_tokens_service, method):
assert hasattr(api_tokens_service, method)


@pytest.mark.parametrize(
"method",
["get", "create", "update", "delete", "enable", "disable"],
)
def test_async_api_tokens_mixins_present(async_api_tokens_service, method):
assert hasattr(async_api_tokens_service, method)