Skip to content

Commit 4e9bb2c

Browse files
author
Robert Segal
committed
Added Accounts user groups endpoints
1 parent 53a2d67 commit 4e9bb2c

4 files changed

Lines changed: 102 additions & 2 deletions

File tree

mpt_api_client/resources/accounts/accounts.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
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.user_groups import (
4+
AsyncUserGroupsService,
5+
UserGroupsService,
6+
)
37

48

59
class Accounts:
@@ -13,6 +17,11 @@ def accounts(self) -> AccountsService:
1317
"""Accounts service."""
1418
return AccountsService(http_client=self.http_client)
1519

20+
@property
21+
def user_groups(self) -> UserGroupsService:
22+
"""User Groups service."""
23+
return UserGroupsService(http_client=self.http_client)
24+
1625

1726
class AsyncAccounts:
1827
"""Async Accounts MPT API Module."""
@@ -24,3 +33,8 @@ def __init__(self, *, http_client: AsyncHTTPClient):
2433
def accounts(self) -> AsyncAccountsService:
2534
"""Accounts service."""
2635
return AsyncAccountsService(http_client=self.http_client)
36+
37+
@property
38+
def user_groups(self) -> AsyncUserGroupsService:
39+
"""User Groups service."""
40+
return AsyncUserGroupsService(http_client=self.http_client)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
12+
13+
class UserGroup(Model):
14+
"""User Group resource."""
15+
16+
17+
class UserGroupsServiceConfig:
18+
"""User Groups service configuration."""
19+
20+
_endpoint = "/public/v1/accounts/user-groups"
21+
_model_class = UserGroup
22+
_collection_key = "data"
23+
24+
25+
class UserGroupsService(
26+
CreateMixin[UserGroup],
27+
UpdateMixin[UserGroup],
28+
DeleteMixin,
29+
Service[UserGroup],
30+
UserGroupsServiceConfig,
31+
):
32+
"""User Groups service."""
33+
34+
35+
class AsyncUserGroupsService(
36+
AsyncCreateMixin[UserGroup],
37+
AsyncUpdateMixin[UserGroup],
38+
AsyncDeleteMixin,
39+
AsyncService[UserGroup],
40+
UserGroupsServiceConfig,
41+
):
42+
"""Async User Groups service."""

tests/resources/accounts/test_accounts.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
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.user_groups import (
6+
AsyncUserGroupsService,
7+
UserGroupsService,
8+
)
59

610

711
@pytest.fixture
@@ -15,7 +19,11 @@ def async_accounts(async_http_client):
1519

1620

1721
@pytest.mark.parametrize(
18-
("property_name", "expected_service_class"), [("accounts", AccountsService)]
22+
("property_name", "expected_service_class"),
23+
[
24+
("accounts", AccountsService),
25+
("user_groups", UserGroupsService),
26+
],
1927
)
2028
def test_accounts_properties(accounts, property_name, expected_service_class):
2129
"""Test that Accounts properties return correct instances."""
@@ -26,7 +34,11 @@ def test_accounts_properties(accounts, property_name, expected_service_class):
2634

2735

2836
@pytest.mark.parametrize(
29-
("property_name", "expected_service_class"), [("accounts", AsyncAccountsService)]
37+
("property_name", "expected_service_class"),
38+
[
39+
("accounts", AsyncAccountsService),
40+
("user_groups", AsyncUserGroupsService),
41+
],
3042
)
3143
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
3244
"""Test that AsyncAccounts properties return correct instances."""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.accounts.user_groups import (
4+
AsyncUserGroupsService,
5+
UserGroupsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def user_groups_service(http_client):
11+
return UserGroupsService(http_client=http_client)
12+
13+
14+
@pytest.fixture
15+
def async_user_groups_service(http_client):
16+
return AsyncUserGroupsService(http_client=http_client)
17+
18+
19+
@pytest.mark.parametrize(
20+
"method",
21+
["get", "create", "update", "delete"],
22+
)
23+
def test_mixins_present(user_groups_service, method):
24+
assert hasattr(user_groups_service, method)
25+
26+
27+
@pytest.mark.parametrize(
28+
"method",
29+
["get", "create", "update", "delete"],
30+
)
31+
def test_async_mixins_present(async_user_groups_service, method):
32+
assert hasattr(async_user_groups_service, method)

0 commit comments

Comments
 (0)