Skip to content

Commit b4ec06f

Browse files
author
Robert Segal
committed
Added Accounts Users endpoints
1 parent 53a2d67 commit b4ec06f

File tree

7 files changed

+513
-4
lines changed

7 files changed

+513
-4
lines changed

mpt_api_client/resources/accounts/accounts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
22
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
3+
from mpt_api_client.resources.accounts.users import AsyncUsersService, UsersService
34

45

56
class Accounts:
@@ -13,6 +14,11 @@ def accounts(self) -> AccountsService:
1314
"""Accounts service."""
1415
return AccountsService(http_client=self.http_client)
1516

17+
@property
18+
def users(self) -> UsersService:
19+
"""Users service."""
20+
return UsersService(http_client=self.http_client)
21+
1622

1723
class AsyncAccounts:
1824
"""Async Accounts MPT API Module."""
@@ -24,3 +30,8 @@ def __init__(self, *, http_client: AsyncHTTPClient):
2430
def accounts(self) -> AsyncAccountsService:
2531
"""Accounts service."""
2632
return AsyncAccountsService(http_client=self.http_client)
33+
34+
@property
35+
def users(self) -> AsyncUsersService:
36+
"""Users service."""
37+
return AsyncUsersService(http_client=self.http_client)

mpt_api_client/resources/accounts/mixins.py

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

7373

74+
class BlockableMixin[Model]:
75+
"""Blockable mixin for blocking and unblocking resources."""
76+
77+
def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
78+
"""Block 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", "block", json=resource_data
86+
)
87+
88+
def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
89+
"""Unblock 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", "unblock", json=resource_data
97+
)
98+
99+
100+
class SSOMixin[Model]:
101+
"""SSO mixin for generating SSO URLs for resources."""
102+
103+
def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
104+
"""SSO 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", "sso", json=resource_data
112+
)
113+
114+
def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
115+
"""Check SSO for 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", "sso-check", json=resource_data
123+
)
124+
125+
74126
class AsyncActivatableMixin[Model]:
75127
"""Async activatable mixin for activating, enabling, disabling and deactivating resources."""
76128

@@ -138,3 +190,55 @@ async def validate(self, resource_id: str, resource_data: ResourceData | None =
138190
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
139191
resource_id, "POST", "validate", json=resource_data
140192
)
193+
194+
195+
class AsyncBlockableMixin[Model]:
196+
"""Asynchronous Blockable mixin for blocking and unblocking resources."""
197+
198+
async def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
199+
"""Block 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", "block", json=resource_data
207+
)
208+
209+
async def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
210+
"""Unblock a resource.
211+
212+
Args:
213+
resource_id: Resource ID
214+
resource_data: Resource data will be updated
215+
"""
216+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
217+
resource_id, "POST", "unblock", json=resource_data
218+
)
219+
220+
221+
class AsyncSSOMixin[Model]:
222+
"""SSO mixin for generating SSO URLs for resources."""
223+
224+
async def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
225+
"""SSO a resource.
226+
227+
Args:
228+
resource_id: Resource ID
229+
resource_data: Resource data will be updated
230+
"""
231+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
232+
resource_id, "POST", "sso", json=resource_data
233+
)
234+
235+
async def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
236+
"""Check SSO for a resource.
237+
238+
Args:
239+
resource_id: Resource ID
240+
resource_data: Resource data will be updated
241+
"""
242+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
243+
resource_id, "POST", "sso-check", json=resource_data
244+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
AsyncBlockableMixin,
13+
AsyncSSOMixin,
14+
BlockableMixin,
15+
SSOMixin,
16+
)
17+
18+
19+
class User(Model):
20+
"""User resource."""
21+
22+
23+
class UsersServiceConfig:
24+
"""Users service configuration."""
25+
26+
_endpoint = "/public/v1/accounts/users"
27+
_model_class = User
28+
_collection_key = "data"
29+
30+
31+
class UsersService(
32+
CreateMixin[User],
33+
UpdateMixin[User],
34+
DeleteMixin,
35+
BlockableMixin[User],
36+
SSOMixin[User],
37+
Service[User],
38+
UsersServiceConfig,
39+
):
40+
"""Users service."""
41+
42+
43+
class AsyncUsersService(
44+
AsyncCreateMixin[User],
45+
AsyncUpdateMixin[User],
46+
AsyncDeleteMixin,
47+
AsyncBlockableMixin[User],
48+
AsyncSSOMixin[User],
49+
AsyncService[User],
50+
UsersServiceConfig,
51+
):
52+
"""Async Users service."""

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extend-ignore =
3232

3333

3434
per-file-ignores =
35-
mpt_api_client/resources/accounts/*.py: WPS215
35+
mpt_api_client/resources/accounts/*.py: WPS215 WPS202
3636
mpt_api_client/mpt_client.py: WPS214 WPS235
3737
mpt_api_client/resources/audit/*.py: WPS215
3838
mpt_api_client/resources/billing/*.py: WPS215 WPS202 WPS214 WPS204
@@ -47,7 +47,7 @@ per-file-ignores =
4747
tests/http/test_service.py: WPS204 WPS202
4848
tests/http/test_mixins.py: WPS204 WPS202
4949
tests/resources/catalog/test_products.py: WPS202 WPS210
50-
tests/resources/*/test_mixins.py: WPS118 WPS202 WPS204
50+
tests/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235
5151
tests/test_mpt_client.py: WPS235
5252

5353
tests/*:

tests/resources/accounts/test_accounts.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
44
from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts
5+
from mpt_api_client.resources.accounts.users import AsyncUsersService, UsersService
56

67

78
@pytest.fixture
@@ -15,7 +16,11 @@ def async_accounts(async_http_client):
1516

1617

1718
@pytest.mark.parametrize(
18-
("property_name", "expected_service_class"), [("accounts", AccountsService)]
19+
("property_name", "expected_service_class"),
20+
[
21+
("accounts", AccountsService),
22+
("users", UsersService),
23+
],
1924
)
2025
def test_accounts_properties(accounts, property_name, expected_service_class):
2126
"""Test that Accounts properties return correct instances."""
@@ -26,7 +31,11 @@ def test_accounts_properties(accounts, property_name, expected_service_class):
2631

2732

2833
@pytest.mark.parametrize(
29-
("property_name", "expected_service_class"), [("accounts", AsyncAccountsService)]
34+
("property_name", "expected_service_class"),
35+
[
36+
("accounts", AsyncAccountsService),
37+
("users", AsyncUsersService),
38+
],
3039
)
3140
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
3241
"""Test that AsyncAccounts properties return correct instances."""

0 commit comments

Comments
 (0)