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.users import AsyncUsersService, UsersService


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

@property
def users(self) -> UsersService:
"""Users service."""
return UsersService(http_client=self.http_client)


class AsyncAccounts:
"""Async Accounts MPT API Module."""
Expand All @@ -24,3 +30,8 @@ def __init__(self, *, http_client: AsyncHTTPClient):
def accounts(self) -> AsyncAccountsService:
"""Accounts service."""
return AsyncAccountsService(http_client=self.http_client)

@property
def users(self) -> AsyncUsersService:
"""Users service."""
return AsyncUsersService(http_client=self.http_client)
52 changes: 52 additions & 0 deletions mpt_api_client/resources/accounts/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ def validate(self, resource_id: str, resource_data: ResourceData | None = None)
)


class BlockableMixin[Model]:
"""Blockable mixin for blocking and unblocking resources."""

def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Block a resource.
Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "block", json=resource_data
)

def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Unblock a resource.
Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "unblock", json=resource_data
)


class AsyncActivatableMixin[Model]:
"""Async activatable mixin for activating, enabling, disabling and deactivating resources."""

Expand Down Expand Up @@ -138,3 +164,29 @@ async def validate(self, resource_id: str, resource_data: ResourceData | None =
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "validate", json=resource_data
)


class AsyncBlockableMixin[Model]:
"""Asynchronous Blockable mixin for blocking and unblocking resources."""

async def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Block a resource.
Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "block", json=resource_data
)

async def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
"""Unblock a resource.
Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
resource_id, "POST", "unblock", json=resource_data
)
81 changes: 81 additions & 0 deletions mpt_api_client/resources/accounts/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncDeleteMixin,
AsyncUpdateMixin,
DeleteMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.models.model import ResourceData
from mpt_api_client.resources.accounts.mixins import (
AsyncBlockableMixin,
BlockableMixin,
)


class User(Model):
"""User resource."""


class UsersServiceConfig:
"""Users service configuration."""

_endpoint = "/public/v1/accounts/users"
_model_class = User
_collection_key = "data"


class UsersService(
UpdateMixin[User],
DeleteMixin,
BlockableMixin[User],
Service[User],
UsersServiceConfig,
):
"""Users service."""

def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
"""Perform SSO action for a user.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action(resource_id, "POST", "sso", json=resource_data)

def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
"""Perform SSO check action for a user.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action(resource_id, "POST", "sso-check", json=resource_data)


class AsyncUsersService(
AsyncUpdateMixin[User],
AsyncDeleteMixin,
AsyncBlockableMixin[User],
AsyncService[User],
UsersServiceConfig,
):
"""Async Users service."""

async def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
"""Perform SSO action for a user.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action(resource_id, "POST", "sso", json=resource_data)

async def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> User:
"""Perform SSO check action for a user.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action(resource_id, "POST", "sso-check", json=resource_data)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ extend-ignore =


per-file-ignores =

mpt_api_client/mpt_client.py: WPS214 WPS235
mpt_api_client/http/mixins.py: WPS202
mpt_api_client/resources/*: WPS215
mpt_api_client/resources/accounts/*.py: WPS202 WPS215
mpt_api_client/resources/billing/*.py: WPS202 WPS204 WPS214 WPS215
mpt_api_client/resources/catalog/*.py: WPS110 WPS214 WPS215
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
Expand Down
13 changes: 11 additions & 2 deletions tests/resources/accounts/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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.users import AsyncUsersService, UsersService


@pytest.fixture
Expand All @@ -15,7 +16,11 @@ def async_accounts(async_http_client):


@pytest.mark.parametrize(
("property_name", "expected_service_class"), [("accounts", AccountsService)]
("property_name", "expected_service_class"),
[
("accounts", AccountsService),
("users", UsersService),
],
)
def test_accounts_properties(accounts, property_name, expected_service_class):
"""Test that Accounts properties return correct instances."""
Expand All @@ -26,7 +31,11 @@ def test_accounts_properties(accounts, property_name, expected_service_class):


@pytest.mark.parametrize(
("property_name", "expected_service_class"), [("accounts", AsyncAccountsService)]
("property_name", "expected_service_class"),
[
("accounts", AsyncAccountsService),
("users", AsyncUsersService),
],
)
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
"""Test that AsyncAccounts properties return correct instances."""
Expand Down
Loading