diff --git a/mpt_api_client/resources/accounts/accounts_user_groups.py b/mpt_api_client/resources/accounts/accounts_user_groups.py new file mode 100644 index 00000000..b0ca2504 --- /dev/null +++ b/mpt_api_client/resources/accounts/accounts_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 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.""" diff --git a/mpt_api_client/resources/accounts/accounts_users.py b/mpt_api_client/resources/accounts/accounts_users.py index d46e451c..55b494af 100644 --- a/mpt_api_client/resources/accounts/accounts_users.py +++ b/mpt_api_client/resources/accounts/accounts_users.py @@ -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, @@ -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" @@ -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], @@ -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, + }, + ) diff --git a/tests/resources/accounts/test_accounts_user_groups.py b/tests/resources/accounts/test_accounts_user_groups.py new file mode 100644 index 00000000..6cd240d2 --- /dev/null +++ b/tests/resources/accounts/test_accounts_user_groups.py @@ -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) diff --git a/tests/resources/accounts/test_accounts_users.py b/tests/resources/accounts/test_accounts_users.py index e0f428b6..edb3e41f 100644 --- a/tests/resources/accounts/test_accounts_users.py +++ b/tests/resources/accounts/test_accounts_users.py @@ -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, @@ -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( @@ -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", + }