From 3772c2e0542e056d8470b1ec08fa331283e9d5d3 Mon Sep 17 00:00:00 2001 From: Robert Segal Date: Tue, 7 Oct 2025 06:43:26 -0600 Subject: [PATCH] Added Accounts account-users user group endpoints --- .../resources/accounts/account_user_groups.py | 42 ++++++++++++++++ .../resources/accounts/account_users.py | 18 +++++++ .../accounts/test_account_user_groups.py | 50 +++++++++++++++++++ .../resources/accounts/test_account_users.py | 32 ++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 mpt_api_client/resources/accounts/account_user_groups.py create mode 100644 tests/resources/accounts/test_account_user_groups.py diff --git a/mpt_api_client/resources/accounts/account_user_groups.py b/mpt_api_client/resources/accounts/account_user_groups.py new file mode 100644 index 0000000..e6b9737 --- /dev/null +++ b/mpt_api_client/resources/accounts/account_user_groups.py @@ -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.""" diff --git a/mpt_api_client/resources/accounts/account_users.py b/mpt_api_client/resources/accounts/account_users.py index 95d6ee9..7d2534e 100644 --- a/mpt_api_client/resources/accounts/account_users.py +++ b/mpt_api_client/resources/accounts/account_users.py @@ -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, @@ -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], @@ -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}, + ) diff --git a/tests/resources/accounts/test_account_user_groups.py b/tests/resources/accounts/test_account_user_groups.py new file mode 100644 index 0000000..deffc3e --- /dev/null +++ b/tests/resources/accounts/test_account_user_groups.py @@ -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) diff --git a/tests/resources/accounts/test_account_users.py b/tests/resources/accounts/test_account_users.py index 6054458..5607d42 100644 --- a/tests/resources/accounts/test_account_users.py +++ b/tests/resources/accounts/test_account_users.py @@ -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, @@ -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"}