Skip to content

Commit 5a8d14e

Browse files
d3rkyRobert Segal
authored andcommitted
MPT-14075 Add notifications contacts (#71)
2 parents 53a2d67 + 0cb907f commit 5a8d14e

File tree

12 files changed

+558
-13
lines changed

12 files changed

+558
-13
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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ 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+
74100
class AsyncActivatableMixin[Model]:
75101
"""Async activatable mixin for activating, enabling, disabling and deactivating resources."""
76102

@@ -138,3 +164,29 @@ async def validate(self, resource_id: str, resource_data: ResourceData | None =
138164
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
139165
resource_id, "POST", "validate", json=resource_data
140166
)
167+
168+
169+
class AsyncBlockableMixin[Model]:
170+
"""Asynchronous Blockable mixin for blocking and unblocking resources."""
171+
172+
async def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
173+
"""Block a resource.
174+
175+
Args:
176+
resource_id: Resource ID
177+
resource_data: Resource data will be updated
178+
"""
179+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
180+
resource_id, "POST", "block", json=resource_data
181+
)
182+
183+
async def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
184+
"""Unblock a resource.
185+
186+
Args:
187+
resource_id: Resource ID
188+
resource_data: Resource data will be updated
189+
"""
190+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
191+
resource_id, "POST", "unblock", json=resource_data
192+
)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.models.model import ResourceData
12+
from mpt_api_client.resources.accounts.mixins import (
13+
AsyncBlockableMixin,
14+
BlockableMixin,
15+
)
16+
17+
18+
class User(Model):
19+
"""User resource."""
20+
21+
22+
class UsersServiceConfig:
23+
"""Users service configuration."""
24+
25+
_endpoint = "/public/v1/accounts/users"
26+
_model_class = User
27+
_collection_key = "data"
28+
29+
30+
class UsersService(
31+
CreateMixin[User],
32+
UpdateMixin[User],
33+
DeleteMixin,
34+
BlockableMixin[User],
35+
Service[User],
36+
UsersServiceConfig,
37+
):
38+
"""Users service."""
39+
40+
def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
41+
"""SSO a resource.
42+
43+
Args:
44+
resource_id: Resource ID
45+
resource_data: Resource data will be updated
46+
"""
47+
return self._resource_action(resource_id, "POST", "sso", json=resource_data)
48+
49+
def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
50+
"""Check SSO for a resource.
51+
52+
Args:
53+
resource_id: Resource ID
54+
resource_data: Resource data will be updated
55+
"""
56+
return self._resource_action(resource_id, "POST", "sso-check", json=resource_data)
57+
58+
59+
class AsyncUsersService(
60+
AsyncCreateMixin[User],
61+
AsyncUpdateMixin[User],
62+
AsyncDeleteMixin,
63+
AsyncBlockableMixin[User],
64+
AsyncService[User],
65+
UsersServiceConfig,
66+
):
67+
"""Async Users service."""
68+
69+
async def sso(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
70+
"""SSO a resource.
71+
72+
Args:
73+
resource_id: Resource ID
74+
resource_data: Resource data will be updated
75+
"""
76+
return await self._resource_action(resource_id, "POST", "sso", json=resource_data)
77+
78+
async def sso_check(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
79+
"""Check SSO for a resource.
80+
81+
Args:
82+
resource_id: Resource ID
83+
resource_data: Resource data will be updated
84+
"""
85+
return await self._resource_action(resource_id, "POST", "sso-check", json=resource_data)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from mpt_api_client.http import AsyncService, CreateMixin, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
AsyncDeleteMixin,
5+
AsyncUpdateMixin,
6+
DeleteMixin,
7+
UpdateMixin,
8+
)
9+
from mpt_api_client.models import Model, ResourceData
10+
11+
12+
class Contact(Model):
13+
"""Notifications Contact resource."""
14+
15+
16+
class ContactsServiceConfig:
17+
"""Notifications Contacts service configuration."""
18+
19+
_endpoint = "/public/v1/notifications/contacts"
20+
_model_class = Contact
21+
_collection_key = "data"
22+
23+
24+
class ContactsService(
25+
CreateMixin[Contact],
26+
UpdateMixin[Contact],
27+
DeleteMixin,
28+
Service[Contact],
29+
ContactsServiceConfig,
30+
):
31+
"""Notifications Contacts service."""
32+
33+
def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
34+
"""Block a contact."""
35+
return self._resource_action(resource_id, "POST", "block", json=resource_data)
36+
37+
def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
38+
"""Unblock a contact."""
39+
return self._resource_action(resource_id, "POST", "unblock", json=resource_data)
40+
41+
42+
class AsyncContactsService(
43+
AsyncCreateMixin[Contact],
44+
AsyncUpdateMixin[Contact],
45+
AsyncDeleteMixin,
46+
AsyncService[Contact],
47+
ContactsServiceConfig,
48+
):
49+
"""Async Notifications Contacts service."""
50+
51+
async def block(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
52+
"""Block a contact."""
53+
return await self._resource_action(resource_id, "POST", "block", json=resource_data)
54+
55+
async def unblock(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
56+
"""Unblock a contact."""
57+
return await self._resource_action(resource_id, "POST", "unblock", json=resource_data)

mpt_api_client/resources/notifications/notifications.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
AsyncCategoriesService,
44
CategoriesService,
55
)
6+
from mpt_api_client.resources.notifications.contacts import AsyncContactsService, ContactsService
67

78

89
class Notifications:
@@ -16,6 +17,11 @@ def categories(self) -> CategoriesService:
1617
"""Categories service."""
1718
return CategoriesService(http_client=self.http_client)
1819

20+
@property
21+
def contacts(self) -> ContactsService:
22+
"""Contacts service."""
23+
return ContactsService(http_client=self.http_client)
24+
1925

2026
class AsyncNotifications:
2127
"""Notifications MPT API Module."""
@@ -27,3 +33,8 @@ def __init__(self, http_client: AsyncHTTPClient):
2733
def categories(self) -> AsyncCategoriesService:
2834
"""Categories service."""
2935
return AsyncCategoriesService(http_client=self.http_client)
36+
37+
@property
38+
def contacts(self) -> AsyncContactsService:
39+
"""Async Contacts service."""
40+
return AsyncContactsService(http_client=self.http_client)

setup.cfg

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,19 @@ 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
37-
mpt_api_client/resources/audit/*.py: WPS215
38-
mpt_api_client/resources/billing/*.py: WPS215 WPS202 WPS214 WPS204
39-
mpt_api_client/resources/catalog/*.py: WPS110 WPS215 WPS214
40-
mpt_api_client/resources/commerce/*.py: WPS215
41-
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
42-
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
43-
mpt_api_client/resources/notifications/categories.py: WPS215
4437
mpt_api_client/http/mixins.py: WPS202
45-
mpt_api_client/mpt_client.py: WPS235
38+
mpt_api_client/resources/*: WPS215
39+
mpt_api_client/resources/billing/*.py: WPS202 WPS204 WPS214 WPS215
40+
mpt_api_client/resources/catalog/*.py: WPS110 WPS214 WPS215
41+
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
42+
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
4643
tests/http/test_async_service.py: WPS204 WPS202
4744
tests/http/test_service.py: WPS204 WPS202
4845
tests/http/test_mixins.py: WPS204 WPS202
4946
tests/resources/catalog/test_products.py: WPS202 WPS210
50-
tests/resources/*/test_mixins.py: WPS118 WPS202 WPS204
47+
tests/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235
5148
tests/test_mpt_client.py: WPS235
5249

5350
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)