From c63f13de0332131864ff0b75bb77fb230ef4c392 Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Tue, 26 May 2026 12:16:19 +0100 Subject: [PATCH] Migrate account users to /accounts/accounts/{id}/users The platform removed the deprecated /v1/accounts/account-users/* and /v1/accounts/{id}/users/* endpoint families (now 404). Re-point the account-scoped users and user-groups services to the surviving /v1/accounts/accounts/{id}/users[/...] prefix and delete the account-users service and its sub-resource, along with their unit tests. Verified with live API probes (old paths return 404, new path returns 200) and the accounts_users e2e suite passes end to end. --- .../resources/accounts/account_user_groups.py | 38 ----------- .../resources/accounts/account_users.py | 66 ------------------ mpt_api_client/resources/accounts/accounts.py | 14 ---- .../accounts/accounts_user_groups.py | 2 +- .../resources/accounts/accounts_users.py | 2 +- .../accounts/test_account_user_groups.py | 58 ---------------- .../resources/accounts/test_account_users.py | 68 ------------------- .../unit/resources/accounts/test_accounts.py | 6 -- .../accounts/test_accounts_user_groups.py | 8 +-- .../resources/accounts/test_accounts_users.py | 4 +- 10 files changed, 8 insertions(+), 258 deletions(-) delete mode 100644 mpt_api_client/resources/accounts/account_user_groups.py delete mode 100644 mpt_api_client/resources/accounts/account_users.py delete mode 100644 tests/unit/resources/accounts/test_account_user_groups.py delete mode 100644 tests/unit/resources/accounts/test_account_users.py diff --git a/mpt_api_client/resources/accounts/account_user_groups.py b/mpt_api_client/resources/accounts/account_user_groups.py deleted file mode 100644 index d1980489..00000000 --- a/mpt_api_client/resources/accounts/account_user_groups.py +++ /dev/null @@ -1,38 +0,0 @@ -from mpt_api_client.http import AsyncService, Service -from mpt_api_client.http.mixins import ( - AsyncCollectionMixin, - AsyncManagedResourceMixin, - CollectionMixin, - ManagedResourceMixin, -) -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( - ManagedResourceMixin[AccountUserGroup], - CollectionMixin[AccountUserGroup], - Service[AccountUserGroup], - AccountUserGroupsServiceConfig, -): - """Account User Groups service.""" - - -class AsyncAccountUserGroupsService( - AsyncManagedResourceMixin[AccountUserGroup], - AsyncCollectionMixin[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 deleted file mode 100644 index fa9f88d6..00000000 --- a/mpt_api_client/resources/accounts/account_users.py +++ /dev/null @@ -1,66 +0,0 @@ -from mpt_api_client.http import AsyncService, Service -from mpt_api_client.http.mixins import ( - AsyncCollectionMixin, - AsyncCreateMixin, - AsyncGetMixin, - CollectionMixin, - CreateMixin, - GetMixin, -) -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, -) - - -class AccountUser(Model): - """Account User Model.""" - - -class AccountUsersServiceConfig: - """Account Users Service Configuration.""" - - _endpoint = "/public/v1/accounts/account-users" - _model_class = AccountUser - _collection_key = "data" - - -class AccountUsersService( - CreateMixin[AccountUser], - InvitableMixin[AccountUser], - GetMixin[AccountUser], - CollectionMixin[AccountUser], - Service[AccountUser], - AccountUsersServiceConfig, -): - """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], - AsyncInvitableMixin[AccountUser], - AsyncGetMixin[AccountUser], - AsyncCollectionMixin[AccountUser], - AsyncService[AccountUser], - 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/mpt_api_client/resources/accounts/accounts.py b/mpt_api_client/resources/accounts/accounts.py index 3f12aa3c..fc46a61e 100644 --- a/mpt_api_client/resources/accounts/accounts.py +++ b/mpt_api_client/resources/accounts/accounts.py @@ -1,9 +1,5 @@ from mpt_api_client.http import AsyncHTTPClient, HTTPClient from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService -from mpt_api_client.resources.accounts.account_users import ( - AccountUsersService, - AsyncAccountUsersService, -) from mpt_api_client.resources.accounts.api_tokens import ApiTokensService, AsyncApiTokensService from mpt_api_client.resources.accounts.buyers import AsyncBuyersService, BuyersService from mpt_api_client.resources.accounts.cloud_tenants import ( @@ -72,11 +68,6 @@ def buyers(self) -> BuyersService: """Buyers service.""" return BuyersService(http_client=self.http_client) - @property - def account_users(self) -> AccountUsersService: - """Account Users service.""" - return AccountUsersService(http_client=self.http_client) - @property def erp_links(self) -> ErpLinksService: """ERP Links service.""" @@ -134,11 +125,6 @@ def buyers(self) -> AsyncBuyersService: """Buyers service.""" return AsyncBuyersService(http_client=self.http_client) - @property - def account_users(self) -> AsyncAccountUsersService: - """Account Users service.""" - return AsyncAccountUsersService(http_client=self.http_client) - @property def erp_links(self) -> AsyncErpLinksService: """ERP Links service.""" diff --git a/mpt_api_client/resources/accounts/accounts_user_groups.py b/mpt_api_client/resources/accounts/accounts_user_groups.py index d63af07b..08d7a972 100644 --- a/mpt_api_client/resources/accounts/accounts_user_groups.py +++ b/mpt_api_client/resources/accounts/accounts_user_groups.py @@ -21,7 +21,7 @@ class AccountsUserGroup(Model): class AccountsUserGroupsServiceConfig: """Account User Groups Service Configuration.""" - _endpoint = "/public/v1/accounts/{account_id}/users/{user_id}/groups" + _endpoint = "/public/v1/accounts/accounts/{account_id}/users/{user_id}/groups" _model_class = AccountsUserGroup _collection_key = "data" diff --git a/mpt_api_client/resources/accounts/accounts_users.py b/mpt_api_client/resources/accounts/accounts_users.py index 8f5f3bc4..ed02cbe2 100644 --- a/mpt_api_client/resources/accounts/accounts_users.py +++ b/mpt_api_client/resources/accounts/accounts_users.py @@ -23,7 +23,7 @@ class AccountsUser(Model): class AccountsUsersServiceConfig: """Account Users Service Configuration.""" - _endpoint = "/public/v1/accounts/{account_id}/users" + _endpoint = "/public/v1/accounts/accounts/{account_id}/users" _model_class = AccountsUser _collection_key = "data" diff --git a/tests/unit/resources/accounts/test_account_user_groups.py b/tests/unit/resources/accounts/test_account_user_groups.py deleted file mode 100644 index 6a8061cb..00000000 --- a/tests/unit/resources/accounts/test_account_user_groups.py +++ /dev/null @@ -1,58 +0,0 @@ -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): - result = account_user_groups_service.path == ( - "/public/v1/accounts/account-users/ACC-0000-0001/groups" - ) - - assert result is True - - -def test_async_endpoint(async_account_user_groups_service): - result = async_account_user_groups_service.path == ( - "/public/v1/accounts/account-users/ACC-0000-0001/groups" - ) - - assert result is True - - -@pytest.mark.parametrize( - "method", - ["create", "update", "delete"], -) -def test_mixins_present(account_user_groups_service, method): - result = hasattr(account_user_groups_service, method) - - assert result is True - - -@pytest.mark.parametrize( - "method", - ["create", "update", "delete"], -) -def test_async_mixins_present(async_account_user_groups_service, method): - result = hasattr(async_account_user_groups_service, method) - - assert result is True diff --git a/tests/unit/resources/accounts/test_account_users.py b/tests/unit/resources/accounts/test_account_users.py deleted file mode 100644 index 998676f4..00000000 --- a/tests/unit/resources/accounts/test_account_users.py +++ /dev/null @@ -1,68 +0,0 @@ -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, -) - - -@pytest.fixture -def account_users_service(http_client): - return AccountUsersService(http_client=http_client) - - -@pytest.fixture -def async_account_users_service(http_client): - return AsyncAccountUsersService(http_client=http_client) - - -@pytest.mark.parametrize( - "method", - ["get", "create", "accept_invite", "resend_invite", "send_new_invite"], -) -def test_methods_present(account_users_service, method): - result = hasattr(account_users_service, method) - - assert result is True - - -@pytest.mark.parametrize( - "method", - ["get", "create", "accept_invite", "resend_invite", "send_new_invite"], -) -def test_async_methods_present(async_account_users_service, method): - result = hasattr(async_account_users_service, method) - - assert result is True - - -@pytest.mark.parametrize( - ("service_method", "expected_service_class"), - [ - ("groups", AccountUserGroupsService), - ], -) -def test_property_services(account_users_service, service_method, expected_service_class): - result = getattr(account_users_service, service_method)("ACC-0000-0001") - - assert isinstance(result, expected_service_class) - assert result.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 -): - result = getattr(async_account_users_service, service_method)("ACC-0000-0001") - - assert isinstance(result, expected_service_class) - assert result.endpoint_params == {"account_user_id": "ACC-0000-0001"} diff --git a/tests/unit/resources/accounts/test_accounts.py b/tests/unit/resources/accounts/test_accounts.py index 03148bfe..91aa72d1 100644 --- a/tests/unit/resources/accounts/test_accounts.py +++ b/tests/unit/resources/accounts/test_accounts.py @@ -1,10 +1,6 @@ import pytest from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService -from mpt_api_client.resources.accounts.account_users import ( - AccountUsersService, - AsyncAccountUsersService, -) from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts from mpt_api_client.resources.accounts.api_tokens import ( ApiTokensService, @@ -48,7 +44,6 @@ def async_accounts(async_http_client): ("modules", ModulesService), ("cloud_tenants", CloudTenantsService), ("buyers", BuyersService), - ("account_users", AccountUsersService), ("erp_links", ErpLinksService), ], ) @@ -71,7 +66,6 @@ def test_accounts_properties(accounts, property_name, expected_service_class): ("modules", AsyncModulesService), ("cloud_tenants", AsyncCloudTenantsService), ("buyers", AsyncBuyersService), - ("account_users", AsyncAccountUsersService), ("erp_links", AsyncErpLinksService), ], ) diff --git a/tests/unit/resources/accounts/test_accounts_user_groups.py b/tests/unit/resources/accounts/test_accounts_user_groups.py index f7b68909..d5e540a3 100644 --- a/tests/unit/resources/accounts/test_accounts_user_groups.py +++ b/tests/unit/resources/accounts/test_accounts_user_groups.py @@ -29,7 +29,7 @@ def async_accounts_user_groups_service(async_http_client): def test_endpoint(accounts_user_groups_service): result = ( accounts_user_groups_service.path - == "/public/v1/accounts/ACC-0000-0001/users/USR-0000-0001/groups" + == "/public/v1/accounts/accounts/ACC-0000-0001/users/USR-0000-0001/groups" ) assert result is True @@ -38,7 +38,7 @@ def test_endpoint(accounts_user_groups_service): def test_async_endpoint(async_accounts_user_groups_service): result = ( async_accounts_user_groups_service.path - == "/public/v1/accounts/ACC-0000-0001/users/USR-0000-0001/groups" + == "/public/v1/accounts/accounts/ACC-0000-0001/users/USR-0000-0001/groups" ) assert result is True @@ -74,7 +74,7 @@ def test_account_user_groups_update(accounts_user_groups_service): # noqa: AAA0 with respx.mock: mock_route = respx.put( - f"https://api.example.com/public/v1/accounts/ACC-0000-0001/users/{user_id}/groups" + f"https://api.example.com/public/v1/accounts/accounts/ACC-0000-0001/users/{user_id}/groups" ).mock( return_value=httpx.Response( status_code=httpx.codes.OK, @@ -101,7 +101,7 @@ async def test_async_account_user_groups_update(async_accounts_user_groups_servi with respx.mock: mock_route = respx.put( - f"https://api.example.com/public/v1/accounts/ACC-0000-0001/users/{user_id}/groups" + f"https://api.example.com/public/v1/accounts/accounts/ACC-0000-0001/users/{user_id}/groups" ).mock( return_value=httpx.Response( status_code=httpx.codes.OK, diff --git a/tests/unit/resources/accounts/test_accounts_users.py b/tests/unit/resources/accounts/test_accounts_users.py index 7a604139..c3746975 100644 --- a/tests/unit/resources/accounts/test_accounts_users.py +++ b/tests/unit/resources/accounts/test_accounts_users.py @@ -25,13 +25,13 @@ def async_accounts_users_service(async_http_client): def test_endpoint(accounts_users_service): - result = accounts_users_service.path == "/public/v1/accounts/ACC-0000-0001/users" + result = accounts_users_service.path == "/public/v1/accounts/accounts/ACC-0000-0001/users" assert result is True def test_async_endpoint(async_accounts_users_service): - result = async_accounts_users_service.path == "/public/v1/accounts/ACC-0000-0001/users" + result = async_accounts_users_service.path == "/public/v1/accounts/accounts/ACC-0000-0001/users" assert result is True