Skip to content

Commit 422c00d

Browse files
author
Robert Segal
committed
Added Accounts endpoints for state actions
1 parent c69aaff commit 422c00d

File tree

4 files changed

+612
-2
lines changed

4 files changed

+612
-2
lines changed

mpt_api_client/resources/accounts/account.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
UpdateMixin,
77
)
88
from mpt_api_client.models import Model
9+
from mpt_api_client.resources.accounts.mixins import (
10+
ActivatableMixin,
11+
AsyncActivatableMixin,
12+
AsyncEnablableMixin,
13+
AsyncValidateMixin,
14+
EnablableMixin,
15+
ValidateMixin,
16+
)
917

1018

1119
class Account(Model):
@@ -23,6 +31,9 @@ class AccountsServiceConfig:
2331
class AccountsService(
2432
CreateMixin[Account],
2533
UpdateMixin[Account],
34+
ActivatableMixin[Account],
35+
EnablableMixin[Account],
36+
ValidateMixin[Account],
2637
Service[Account],
2738
AccountsServiceConfig,
2839
):
@@ -32,6 +43,9 @@ class AccountsService(
3243
class AsyncAccountsService(
3344
AsyncCreateMixin[Account],
3445
AsyncUpdateMixin[Account],
46+
AsyncActivatableMixin[Account],
47+
AsyncEnablableMixin[Account],
48+
AsyncValidateMixin[Account],
3549
AsyncService[Account],
3650
AccountsServiceConfig,
3751
):
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
from mpt_api_client.models import ResourceData
2+
3+
# TODO: Consider reorganizing functions in mixins to reduce duplication and differences amongst
4+
# different domains
5+
6+
7+
class ActivatableMixin[Model]:
8+
"""Activatable mixin for activating, enabling, disabling and deactivating resources."""
9+
10+
def activate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
11+
"""Activate a resource.
12+
13+
Args:
14+
resource_id: Resource ID
15+
resource_data: Resource data will be updated
16+
"""
17+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
18+
resource_id, "POST", "activate", json=resource_data
19+
)
20+
21+
def deactivate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
22+
"""Deactivate a resource.
23+
24+
Args:
25+
resource_id: Resource ID
26+
resource_data: Resource data will be updated
27+
"""
28+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
29+
resource_id, "POST", "deactivate", json=resource_data
30+
)
31+
32+
33+
class EnablableMixin[Model]:
34+
"""Enablable mixin for enabling and disabling resources."""
35+
36+
def enable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
37+
"""Enable a resource.
38+
39+
Args:
40+
resource_id: Resource ID
41+
resource_data: Resource data will be updated
42+
"""
43+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
44+
resource_id, "POST", "enable", json=resource_data
45+
)
46+
47+
def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
48+
"""Disable a resource.
49+
50+
Args:
51+
resource_id: Resource ID
52+
resource_data: Resource data will be updated
53+
"""
54+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
55+
resource_id, "POST", "disable", json=resource_data
56+
)
57+
58+
59+
class ValidateMixin[Model]:
60+
"""Validate mixin adds the ability to validate a resource."""
61+
62+
def validate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
63+
"""Validate a resource.
64+
65+
Args:
66+
resource_id: Resource ID
67+
resource_data: Resource data will be validated
68+
"""
69+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
70+
resource_id, "POST", "validate", json=resource_data
71+
)
72+
73+
74+
class AsyncActivatableMixin[Model]:
75+
"""Async activatable mixin for activating, enabling, disabling and deactivating resources."""
76+
77+
async def activate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
78+
"""Activate a resource.
79+
80+
Args:
81+
resource_id: Resource ID
82+
resource_data: Resource data will be updated
83+
"""
84+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
85+
resource_id, "POST", "activate", json=resource_data
86+
)
87+
88+
async def deactivate(
89+
self, resource_id: str, resource_data: ResourceData | None = None
90+
) -> Model:
91+
"""Deactivate a resource.
92+
93+
Args:
94+
resource_id: Resource ID
95+
resource_data: Resource data will be updated
96+
"""
97+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
98+
resource_id, "POST", "deactivate", json=resource_data
99+
)
100+
101+
102+
class AsyncEnablableMixin[Model]:
103+
"""Asynchronous Enablable mixin for enabling and disabling resources."""
104+
105+
async def enable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
106+
"""Enable a resource.
107+
108+
Args:
109+
resource_id: Resource ID
110+
resource_data: Resource data will be updated
111+
"""
112+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
113+
resource_id, "POST", "enable", json=resource_data
114+
)
115+
116+
async def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
117+
"""Disable a resource.
118+
119+
Args:
120+
resource_id: Resource ID
121+
resource_data: Resource data will be updated
122+
"""
123+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
124+
resource_id, "POST", "disable", json=resource_data
125+
)
126+
127+
128+
class AsyncValidateMixin[Model]:
129+
"""Asynchronous Validate mixin adds the ability to validate a resource."""
130+
131+
async def validate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
132+
"""Validate a resource.
133+
134+
Args:
135+
resource_id: Resource ID
136+
resource_data: Resource data will be validated
137+
"""
138+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
139+
resource_id, "POST", "validate", json=resource_data
140+
)

tests/resources/accounts/test_account.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ def async_account_service(async_http_client):
1313
return AsyncAccountsService(http_client=async_http_client)
1414

1515

16-
@pytest.mark.parametrize("method", ["get", "create", "update"])
16+
@pytest.mark.parametrize(
17+
"method", ["get", "create", "update", "enable", "disable", "activate", "deactivate", "validate"]
18+
)
1719
def test_mixins_present(account_service, method):
1820
assert hasattr(account_service, method)
1921

2022

21-
@pytest.mark.parametrize("method", ["get", "create", "update"])
23+
@pytest.mark.parametrize(
24+
"method", ["get", "create", "update", "enable", "disable", "activate", "deactivate", "validate"]
25+
)
2226
def test_async_mixins_present(async_account_service, method):
2327
assert hasattr(async_account_service, method)

0 commit comments

Comments
 (0)