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/accounts_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 AccountsUserGroup(Model):
"""Account User Group Model."""


class AccountsUserGroupsServiceConfig:
"""Account User Groups Service Configuration."""

_endpoint = "/public/v1/accounts/{account_id}/users/{user_id}/groups"
_model_class = AccountsUserGroup
_collection_key = "data"


class AccountsUserGroupsService(
UpdateMixin[AccountsUserGroup],
DeleteMixin,
CreateMixin[AccountsUserGroup],
Service[AccountsUserGroup],
AccountsUserGroupsServiceConfig,
):
"""Account User Groups Service."""


class AsyncAccountsUserGroupsService(
AsyncUpdateMixin[AccountsUserGroup],
AsyncDeleteMixin,
AsyncCreateMixin[AccountsUserGroup],
AsyncService[AccountsUserGroup],
AccountsUserGroupsServiceConfig,
):
"""Asynchronous Account User Groups Service."""
26 changes: 25 additions & 1 deletion mpt_api_client/resources/accounts/accounts_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
UpdateMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.resources.accounts.accounts_user_groups import (
AccountsUserGroupsService,
AsyncAccountsUserGroupsService,
)
from mpt_api_client.resources.accounts.mixins import (
AsyncInvitableMixin,
InvitableMixin,
Expand All @@ -21,7 +25,7 @@ class AccountsUser(Model):
class AccountsUsersServiceConfig:
"""Account Users Service Configuration."""

_endpoint = "/public/v1/accounts/accounts/{account_id}/users"
_endpoint = "/public/v1/accounts/{account_id}/users"
_model_class = AccountsUser
_collection_key = "data"

Expand All @@ -36,6 +40,16 @@ class AccountsUsersService(
):
"""Account Users Service."""

def groups(self, user_id: str) -> AccountsUserGroupsService:
"""Return account user groups service."""
return AccountsUserGroupsService(
http_client=self.http_client,
endpoint_params={
"account_id": self.endpoint_params["account_id"],
"user_id": user_id,
},
)


class AsyncAccountsUsersService(
AsyncUpdateMixin[AccountsUser],
Expand All @@ -46,3 +60,13 @@ class AsyncAccountsUsersService(
AccountsUsersServiceConfig,
):
"""Asynchronous Account Users Service."""

def groups(self, user_id: str) -> AsyncAccountsUserGroupsService:
"""Return account user groups service."""
return AsyncAccountsUserGroupsService(
http_client=self.http_client,
endpoint_params={
"account_id": self.endpoint_params["account_id"],
"user_id": user_id,
},
)
52 changes: 52 additions & 0 deletions tests/resources/accounts/test_accounts_user_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest

from mpt_api_client.resources.accounts.accounts_user_groups import (
AccountsUserGroupsService,
AsyncAccountsUserGroupsService,
)


@pytest.fixture
def accounts_user_groups_service(http_client):
return AccountsUserGroupsService(
http_client=http_client,
endpoint_params={"account_id": "ACC-0000-0001", "user_id": "USR-0000-0001"},
)


@pytest.fixture
def async_accounts_user_groups_service(async_http_client):
return AsyncAccountsUserGroupsService(
http_client=async_http_client,
endpoint_params={"account_id": "ACC-0000-0001", "user_id": "USR-0000-0001"},
)


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


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


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


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

from mpt_api_client.resources.accounts.accounts_user_groups import (
AccountsUserGroupsService,
AsyncAccountsUserGroupsService,
)
from mpt_api_client.resources.accounts.accounts_users import (
AccountsUsersService,
AsyncAccountsUsersService,
Expand All @@ -21,13 +25,11 @@ def async_accounts_users_service(async_http_client):


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


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


@pytest.mark.parametrize(
Expand All @@ -44,3 +46,33 @@ def test_methods_present(accounts_users_service, method):
)
def test_async_methods_present(async_accounts_users_service, method):
assert hasattr(async_accounts_users_service, method)


@pytest.mark.parametrize(
("service_method", "expected_service_class"),
[("groups", AccountsUserGroupsService)],
)
def test_property_services(accounts_users_service, service_method, expected_service_class):
service = getattr(accounts_users_service, service_method)("USR-0000-0001")

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


@pytest.mark.parametrize(
("service_method", "expected_service_class"),
[("groups", AsyncAccountsUserGroupsService)],
)
def test_async_property_services(
async_accounts_users_service, service_method, expected_service_class
):
service = getattr(async_accounts_users_service, service_method)("USR-0000-0001")

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