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
42 changes: 42 additions & 0 deletions mpt_api_client/resources/accounts/account_user_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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


class AccountUserGroup(Model):
"""Account User Group resource."""


class AccountUserGroupsServiceConfig:
"""Account User Groups service configuration."""

_endpoint = "/public/v1/accounts/account-users/{account_user_id}/groups"
_model_class = AccountUserGroup
_collection_key = "data"


class AccountUserGroupsService(
CreateMixin[AccountUserGroup],
DeleteMixin,
UpdateMixin[AccountUserGroup],
Service[AccountUserGroup],
AccountUserGroupsServiceConfig,
):
"""Account User Groups service."""


class AsyncAccountUserGroupsService(
AsyncCreateMixin[AccountUserGroup],
AsyncDeleteMixin,
AsyncUpdateMixin[AccountUserGroup],
AsyncService[AccountUserGroup],
AccountUserGroupsServiceConfig,
):
"""Async Account User Groups service."""
18 changes: 18 additions & 0 deletions mpt_api_client/resources/accounts/account_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
CreateMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.accounts.account_user_groups import (
AccountUserGroupsService,
AsyncAccountUserGroupsService,
)
from mpt_api_client.resources.accounts.mixins import (
AsyncInvitableMixin,
InvitableMixin,
Expand All @@ -30,6 +34,13 @@ class AccountUsersService(
):
"""Account Users Service."""

def groups(self, account_user_id: str) -> AccountUserGroupsService:
"""Return account user groups service."""
return AccountUserGroupsService(
http_client=self.http_client,
endpoint_params={"account_user_id": account_user_id},
)


class AsyncAccountUsersService(
AsyncCreateMixin[AccountUser],
Expand All @@ -38,3 +49,10 @@ class AsyncAccountUsersService(
AccountUsersServiceConfig,
):
"""Asynchronous Account Users Service."""

def groups(self, account_user_id: str) -> AsyncAccountUserGroupsService:
"""Return account user groups service."""
return AsyncAccountUserGroupsService(
http_client=self.http_client,
endpoint_params={"account_user_id": account_user_id},
)
50 changes: 50 additions & 0 deletions tests/resources/accounts/test_account_user_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest

from mpt_api_client.resources.accounts.account_user_groups import (
AccountUserGroupsService,
AsyncAccountUserGroupsService,
)


@pytest.fixture
def account_user_groups_service(http_client):
return AccountUserGroupsService(
http_client=http_client,
endpoint_params={"account_user_id": "ACC-0000-0001"},
)


@pytest.fixture
def async_account_user_groups_service(async_http_client):
return AsyncAccountUserGroupsService(
http_client=async_http_client,
endpoint_params={"account_user_id": "ACC-0000-0001"},
)


def test_endpoint(account_user_groups_service):
assert account_user_groups_service.endpoint == (
"/public/v1/accounts/account-users/ACC-0000-0001/groups"
)


def test_async_endpoint(async_account_user_groups_service):
assert async_account_user_groups_service.endpoint == (
"/public/v1/accounts/account-users/ACC-0000-0001/groups"
)


@pytest.mark.parametrize(
"method",
["create", "update", "delete"],
)
def test_mixins_present(account_user_groups_service, method):
assert hasattr(account_user_groups_service, method)


@pytest.mark.parametrize(
"method",
["create", "update", "delete"],
)
def test_async_mixins_present(async_account_user_groups_service, method):
assert hasattr(async_account_user_groups_service, method)
32 changes: 32 additions & 0 deletions tests/resources/accounts/test_account_users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest

from mpt_api_client.resources.accounts.account_user_groups import (
AccountUserGroupsService,
AsyncAccountUserGroupsService,
)
from mpt_api_client.resources.accounts.account_users import (
AccountUsersService,
AsyncAccountUsersService,
Expand Down Expand Up @@ -30,3 +34,31 @@ def test_methods_present(account_users_service, method):
)
def test_async_methods_present(async_account_users_service, method):
assert hasattr(async_account_users_service, method)


@pytest.mark.parametrize(
("service_method", "expected_service_class"),
[
("groups", AccountUserGroupsService),
],
)
def test_property_services(account_users_service, service_method, expected_service_class):
service = getattr(account_users_service, service_method)("ACC-0000-0001")

assert isinstance(service, expected_service_class)
assert service.endpoint_params == {"account_user_id": "ACC-0000-0001"}


@pytest.mark.parametrize(
("service_method", "expected_service_class"),
[
("groups", AsyncAccountUserGroupsService),
],
)
def test_async_property_services(
async_account_users_service, service_method, expected_service_class
):
service = getattr(async_account_users_service, service_method)("ACC-0000-0001")

assert isinstance(service, expected_service_class)
assert service.endpoint_params == {"account_user_id": "ACC-0000-0001"}