Skip to content

Commit cb52d93

Browse files
authored
2 parents c09f4ce + 9c29b05 commit cb52d93

File tree

7 files changed

+399
-1
lines changed

7 files changed

+399
-1
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
@@ -97,6 +97,43 @@ def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -
9797
)
9898

9999

100+
class InvitableMixin[Model]:
101+
"""Invitable mixin for sending and managing invites for resources."""
102+
103+
def accept_invite(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
104+
"""Accept an invite for a resource.
105+
106+
Args:
107+
resource_id: Resource ID
108+
resource_data: Resource data will be updated
109+
"""
110+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
111+
resource_id, "POST", "accept-invite", json=resource_data
112+
)
113+
114+
def resend_invite(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
115+
"""Resend an invite to a resource.
116+
117+
Args:
118+
resource_id: Resource ID
119+
resource_data: Resource data will be updated
120+
"""
121+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
122+
resource_id, "POST", "resend-invite", json=resource_data
123+
)
124+
125+
def send_new_invite(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
126+
"""Send a new invite to a resource.
127+
128+
Args:
129+
resource_id: Resource ID
130+
resource_data: Resource data will be updated
131+
"""
132+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
133+
resource_id, "POST", "send-new-invite", json=resource_data
134+
)
135+
136+
100137
class AsyncActivatableMixin[Model]:
101138
"""Async activatable mixin for activating, enabling, disabling and deactivating resources."""
102139

@@ -190,3 +227,46 @@ async def unblock(self, resource_id: str, resource_data: ResourceData | None = N
190227
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
191228
resource_id, "POST", "unblock", json=resource_data
192229
)
230+
231+
232+
class AsyncInvitableMixin[Model]:
233+
"""Asynchronous Invitable mixin for sending and managing invites for resources."""
234+
235+
async def accept_invite(
236+
self, resource_id: str, resource_data: ResourceData | None = None
237+
) -> Model:
238+
"""Accept an invite for a resource.
239+
240+
Args:
241+
resource_id: Resource ID
242+
resource_data: Resource data will be updated
243+
"""
244+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
245+
resource_id, "POST", "accept-invite", json=resource_data
246+
)
247+
248+
async def resend_invite(
249+
self, resource_id: str, resource_data: ResourceData | None = None
250+
) -> Model:
251+
"""Resend an invite to a resource.
252+
253+
Args:
254+
resource_id: Resource ID
255+
resource_data: Resource data will be updated
256+
"""
257+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
258+
resource_id, "POST", "resend-invite", json=resource_data
259+
)
260+
261+
async def send_new_invite(
262+
self, resource_id: str, resource_data: ResourceData | None = None
263+
) -> Model:
264+
"""Send a new invite to a resource.
265+
266+
Args:
267+
resource_id: Resource ID
268+
resource_data: Resource data will be updated
269+
"""
270+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
271+
resource_id, "POST", "send-new-invite", json=resource_data
272+
)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ per-file-ignores =
4444
tests/http/test_service.py: WPS204 WPS202
4545
tests/http/test_mixins.py: WPS204 WPS202
4646
tests/resources/catalog/test_products.py: WPS202 WPS210
47-
tests/resources/*/test_mixins.py: WPS118 WPS202 WPS204
47+
tests/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235
4848
tests/test_mpt_client.py: WPS235
4949

5050
tests/*:

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)