Skip to content

Commit a8e0264

Browse files
author
Robert Segal
committed
Added Accounts accounts users endpoint
1 parent 7b59f65 commit a8e0264

File tree

7 files changed

+399
-0
lines changed

7 files changed

+399
-0
lines changed

mpt_api_client/resources/accounts/account.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
UpdateMixin,
77
)
88
from mpt_api_client.models import Model
9+
from mpt_api_client.resources.accounts.accounts_users import (
10+
AccountsUsersService,
11+
AsyncAccountsUsersService,
12+
)
913
from mpt_api_client.resources.accounts.mixins import (
1014
ActivatableMixin,
1115
AsyncActivatableMixin,
@@ -39,6 +43,12 @@ class AccountsService(
3943
):
4044
"""Accounts service."""
4145

46+
def users(self, account_id: str) -> AccountsUsersService:
47+
"""Return account users service."""
48+
return AccountsUsersService(
49+
http_client=self.http_client, endpoint_params={"account_id": account_id}
50+
)
51+
4252

4353
class AsyncAccountsService(
4454
AsyncCreateMixin[Account],
@@ -50,3 +60,9 @@ class AsyncAccountsService(
5060
AccountsServiceConfig,
5161
):
5262
"""Async Accounts service."""
63+
64+
def users(self, account_id: str) -> AsyncAccountsUsersService:
65+
"""Return account users service."""
66+
return AsyncAccountsUsersService(
67+
http_client=self.http_client, endpoint_params={"account_id": account_id}
68+
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
AsyncDeleteMixin,
5+
AsyncUpdateMixin,
6+
CreateMixin,
7+
DeleteMixin,
8+
UpdateMixin,
9+
)
10+
from mpt_api_client.models import Model
11+
from mpt_api_client.resources.accounts.mixins import (
12+
AsyncInvitableMixin,
13+
InvitableMixin,
14+
)
15+
16+
17+
class AccountsUser(Model):
18+
"""Account User Model."""
19+
20+
21+
class AccountsUsersServiceConfig:
22+
"""Account Users Service Configuration."""
23+
24+
_endpoint = "/public/v1/accounts/accounts/{account_id}/users"
25+
_model_class = AccountsUser
26+
_collection_key = "data"
27+
28+
29+
class AccountsUsersService(
30+
UpdateMixin[AccountsUser],
31+
DeleteMixin,
32+
CreateMixin[AccountsUser],
33+
InvitableMixin[AccountsUser],
34+
Service[AccountsUser],
35+
AccountsUsersServiceConfig,
36+
):
37+
"""Account Users Service."""
38+
39+
40+
class AsyncAccountsUsersService(
41+
AsyncUpdateMixin[AccountsUser],
42+
AsyncDeleteMixin,
43+
AsyncCreateMixin[AccountsUser],
44+
AsyncService[AccountsUser],
45+
AsyncInvitableMixin[AccountsUser],
46+
AccountsUsersServiceConfig,
47+
):
48+
"""Asynchronous Account Users Service."""

mpt_api_client/resources/accounts/mixins.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,43 @@ def validate(self, resource_id: str, resource_data: ResourceData | None = None)
7171
)
7272

7373

74+
class InvitableMixin[Model]:
75+
"""Invitable mixin for sending and managing invites for resources."""
76+
77+
def accept_invite(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
78+
"""Accept an invite for a resource.
79+
80+
Args:
81+
resource_id: Resource ID
82+
resource_data: Resource data will be updated
83+
"""
84+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
85+
resource_id, "POST", "accept-invite", json=resource_data
86+
)
87+
88+
def resend_invite(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
89+
"""Resend an invite to a resource.
90+
91+
Args:
92+
resource_id: Resource ID
93+
resource_data: Resource data will be updated
94+
"""
95+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
96+
resource_id, "POST", "resend-invite", json=resource_data
97+
)
98+
99+
def send_new_invite(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
100+
"""Send a new invite to a resource.
101+
102+
Args:
103+
resource_id: Resource ID
104+
resource_data: Resource data will be updated
105+
"""
106+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
107+
resource_id, "POST", "send-new-invite", json=resource_data
108+
)
109+
110+
74111
class AsyncActivatableMixin[Model]:
75112
"""Async activatable mixin for activating, enabling, disabling and deactivating resources."""
76113

@@ -138,3 +175,46 @@ async def validate(self, resource_id: str, resource_data: ResourceData | None =
138175
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
139176
resource_id, "POST", "validate", json=resource_data
140177
)
178+
179+
180+
class AsyncInvitableMixin[Model]:
181+
"""Asynchronous Invitable mixin for sending and managing invites for resources."""
182+
183+
async def accept_invite(
184+
self, resource_id: str, resource_data: ResourceData | None = None
185+
) -> Model:
186+
"""Accept an invite for a resource.
187+
188+
Args:
189+
resource_id: Resource ID
190+
resource_data: Resource data will be updated
191+
"""
192+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
193+
resource_id, "POST", "accept-invite", json=resource_data
194+
)
195+
196+
async def resend_invite(
197+
self, resource_id: str, resource_data: ResourceData | None = None
198+
) -> Model:
199+
"""Resend an invite to a resource.
200+
201+
Args:
202+
resource_id: Resource ID
203+
resource_data: Resource data will be updated
204+
"""
205+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
206+
resource_id, "POST", "resend-invite", json=resource_data
207+
)
208+
209+
async def send_new_invite(
210+
self, resource_id: str, resource_data: ResourceData | None = None
211+
) -> Model:
212+
"""Send a new invite to a resource.
213+
214+
Args:
215+
resource_id: Resource ID
216+
resource_data: Resource data will be updated
217+
"""
218+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
219+
resource_id, "POST", "send-new-invite", json=resource_data
220+
)

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ per-file-ignores =
3636
mpt_api_client/mpt_client.py: WPS214 WPS235
3737
mpt_api_client/http/mixins.py: WPS202
3838
mpt_api_client/resources/*: WPS215
39+
mpt_api_client/resources/accounts/*.py: WPS202 WPS215
3940
mpt_api_client/resources/billing/*.py: WPS202 WPS204 WPS214 WPS215
4041
mpt_api_client/resources/catalog/*.py: WPS110 WPS214 WPS215
4142
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215

tests/resources/accounts/test_account.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pytest
22

33
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
4+
from mpt_api_client.resources.accounts.accounts_users import (
5+
AccountsUsersService,
6+
AsyncAccountsUsersService,
7+
)
48

59

610
@pytest.fixture
@@ -13,6 +17,20 @@ def async_account_service(async_http_client):
1317
return AsyncAccountsService(http_client=async_http_client)
1418

1519

20+
@pytest.fixture
21+
def accounts_users_service(http_client):
22+
return AccountsUsersService(
23+
http_client=http_client, endpoint_params={"account_id": "ACC-0000-0001"}
24+
)
25+
26+
27+
@pytest.fixture
28+
def async_accounts_users_service(async_http_client):
29+
return AsyncAccountsUsersService(
30+
http_client=async_http_client, endpoint_params={"account_id": "ACC-0000-0001"}
31+
)
32+
33+
1634
@pytest.mark.parametrize(
1735
"method", ["get", "create", "update", "enable", "disable", "activate", "deactivate", "validate"]
1836
)
@@ -25,3 +43,29 @@ def test_mixins_present(account_service, method):
2543
)
2644
def test_async_mixins_present(async_account_service, method):
2745
assert hasattr(async_account_service, method)
46+
47+
48+
@pytest.mark.parametrize(
49+
("service_method", "expected_service_class"),
50+
[
51+
("users", AccountsUsersService),
52+
],
53+
)
54+
def test_property_services(account_service, service_method, expected_service_class):
55+
service = getattr(account_service, service_method)("ACC-0000-0001")
56+
57+
assert isinstance(service, expected_service_class)
58+
assert service.endpoint_params == {"account_id": "ACC-0000-0001"}
59+
60+
61+
@pytest.mark.parametrize(
62+
("service_method", "expected_service_class"),
63+
[
64+
("users", AsyncAccountsUsersService),
65+
],
66+
)
67+
def test_async_property_services(async_account_service, service_method, expected_service_class):
68+
service = getattr(async_account_service, service_method)("ACC-0000-0001")
69+
70+
assert isinstance(service, expected_service_class)
71+
assert service.endpoint_params == {"account_id": "ACC-0000-0001"}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.accounts.accounts_users import (
4+
AccountsUsersService,
5+
AsyncAccountsUsersService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def accounts_users_service(http_client):
11+
return AccountsUsersService(
12+
http_client=http_client, endpoint_params={"account_id": "ACC-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_accounts_users_service(async_http_client):
18+
return AsyncAccountsUsersService(
19+
http_client=async_http_client, endpoint_params={"account_id": "ACC-0000-0001"}
20+
)
21+
22+
23+
def test_endpoint(accounts_users_service):
24+
assert accounts_users_service.endpoint == "/public/v1/accounts/accounts/ACC-0000-0001/users"
25+
26+
27+
def test_async_endpoint(async_accounts_users_service):
28+
assert (
29+
async_accounts_users_service.endpoint == "/public/v1/accounts/accounts/ACC-0000-0001/users"
30+
)
31+
32+
33+
@pytest.mark.parametrize(
34+
"method",
35+
["get", "create", "update", "accept_invite", "resend_invite", "send_new_invite"],
36+
)
37+
def test_methods_present(accounts_users_service, method):
38+
assert hasattr(accounts_users_service, method)
39+
40+
41+
@pytest.mark.parametrize(
42+
"method",
43+
["get", "create", "update", "accept_invite", "resend_invite", "send_new_invite"],
44+
)
45+
def test_async_methods_present(async_accounts_users_service, method):
46+
assert hasattr(async_accounts_users_service, method)

0 commit comments

Comments
 (0)