Skip to content

Commit c7cad98

Browse files
author
Robert Segal
committed
Added Accounts sellers endpoints
1 parent 7fb95f5 commit c7cad98

File tree

4 files changed

+201
-0
lines changed

4 files changed

+201
-0
lines changed

mpt_api_client/resources/accounts/accounts.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
22
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
33
from mpt_api_client.resources.accounts.users import AsyncUsersService, UsersService
4+
from mpt_api_client.resources.accounts.sellers import AsyncSellersService, SellersService
45

56

67
class Accounts:
@@ -19,6 +20,11 @@ def users(self) -> UsersService:
1920
"""Users service."""
2021
return UsersService(http_client=self.http_client)
2122

23+
@property
24+
def sellers(self) -> SellersService:
25+
"""Sellers service."""
26+
return SellersService(http_client=self.http_client)
27+
2228

2329
class AsyncAccounts:
2430
"""Async Accounts MPT API Module."""
@@ -35,3 +41,8 @@ def accounts(self) -> AsyncAccountsService:
3541
def users(self) -> AsyncUsersService:
3642
"""Users service."""
3743
return AsyncUsersService(http_client=self.http_client)
44+
45+
@property
46+
def sellers(self) -> AsyncSellersService:
47+
"""Sellers service."""
48+
return AsyncSellersService(http_client=self.http_client)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 ActivatableMixin, AsyncActivatableMixin
13+
14+
15+
class Seller(Model):
16+
"""Seller Model."""
17+
18+
19+
class SellersServiceConfig:
20+
"""Sellers Service Configuration."""
21+
22+
_endpoint = "/public/v1/accounts/sellers"
23+
_model_class = Seller
24+
_collection_key = "data"
25+
26+
27+
class SellersService(
28+
CreateMixin[Seller],
29+
DeleteMixin,
30+
UpdateMixin[Seller],
31+
ActivatableMixin[Seller],
32+
Service[Seller],
33+
SellersServiceConfig,
34+
):
35+
"""Sellers Service."""
36+
37+
def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Seller:
38+
"""Disable a seller.
39+
40+
Args:
41+
resource_id: Resource ID
42+
resource_data: Resource data will be updated
43+
"""
44+
return self._resource_action(resource_id, "POST", "disable", json=resource_data)
45+
46+
47+
class AsyncSellersService(
48+
AsyncCreateMixin[Seller],
49+
AsyncDeleteMixin,
50+
AsyncUpdateMixin[Seller],
51+
AsyncActivatableMixin[Seller],
52+
AsyncService[Seller],
53+
SellersServiceConfig,
54+
):
55+
"""Async Sellers Service."""
56+
57+
async def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Seller:
58+
"""Disable a seller.
59+
60+
Args:
61+
resource_id: Resource ID
62+
resource_data: Resource data will be updated
63+
"""
64+
return await self._resource_action(resource_id, "POST", "disable", json=resource_data)

tests/resources/accounts/test_accounts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
44
from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts
55
from mpt_api_client.resources.accounts.users import AsyncUsersService, UsersService
6+
from mpt_api_client.resources.accounts.sellers import AsyncSellersService, SellersService
67

78

89
@pytest.fixture
@@ -20,6 +21,7 @@ def async_accounts(async_http_client):
2021
[
2122
("accounts", AccountsService),
2223
("users", UsersService),
24+
("sellers", SellersService),
2325
],
2426
)
2527
def test_accounts_properties(accounts, property_name, expected_service_class):
@@ -35,6 +37,7 @@ def test_accounts_properties(accounts, property_name, expected_service_class):
3537
[
3638
("accounts", AsyncAccountsService),
3739
("users", AsyncUsersService),
40+
("sellers", AsyncSellersService),
3841
],
3942
)
4043
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import httpx
2+
import pytest
3+
import respx
4+
5+
from mpt_api_client.resources.accounts.sellers import AsyncSellersService, Seller, SellersService
6+
7+
8+
@pytest.fixture
9+
def sellers_service(http_client):
10+
return SellersService(http_client=http_client)
11+
12+
13+
@pytest.fixture
14+
def async_sellers_service(async_http_client):
15+
return AsyncSellersService(http_client=async_http_client)
16+
17+
18+
@pytest.mark.parametrize(
19+
"method",
20+
["get", "create", "update", "delete", "activate", "deactivate", "disable"],
21+
)
22+
def test_mixins_present(sellers_service, method):
23+
assert hasattr(sellers_service, method)
24+
25+
26+
@pytest.mark.parametrize(
27+
"method",
28+
["get", "create", "update", "delete", "activate", "deactivate", "disable"],
29+
)
30+
def test_async_mixins_present(async_sellers_service, method):
31+
assert hasattr(async_sellers_service, method)
32+
33+
34+
@pytest.mark.parametrize(
35+
("action", "input_status"), [("disable", {"id": "OBJ-0000-0001", "status": "update"})]
36+
)
37+
def test_sellers_resource_action(sellers_service, action, input_status):
38+
request_expected_content = b'{"id":"OBJ-0000-0001","status":"update"}'
39+
response_expected_data = {"id": "OBJ-0000-0001", "status": "new_status"}
40+
with respx.mock:
41+
mock_route = respx.post(
42+
f"https://api.example.com/public/v1/accounts/sellers/OBJ-0000-0001/{action}"
43+
).mock(
44+
return_value=httpx.Response(
45+
status_code=httpx.codes.OK,
46+
json=response_expected_data,
47+
)
48+
)
49+
sellers_obj = getattr(sellers_service, action)("OBJ-0000-0001", input_status)
50+
51+
request = mock_route.calls[0].request
52+
53+
assert request.content == request_expected_content
54+
assert sellers_obj.to_dict() == response_expected_data
55+
assert isinstance(sellers_obj, Seller)
56+
57+
58+
@pytest.mark.parametrize(("action", "input_status"), [("disable", None)])
59+
def test_sellers_resource_action_no_data(sellers_service, action, input_status):
60+
request_expected_content = b""
61+
response_expected_data = {"id": "OBJ-0000-0001", "status": "new_status"}
62+
with respx.mock:
63+
mock_route = respx.post(
64+
f"https://api.example.com/public/v1/accounts/sellers/OBJ-0000-0001/{action}"
65+
).mock(
66+
return_value=httpx.Response(
67+
status_code=httpx.codes.OK,
68+
json=response_expected_data,
69+
)
70+
)
71+
sellers_obj = getattr(sellers_service, action)("OBJ-0000-0001", input_status)
72+
73+
request = mock_route.calls[0].request
74+
75+
assert request.content == request_expected_content
76+
assert sellers_obj.to_dict() == response_expected_data
77+
assert isinstance(sellers_obj, Seller)
78+
79+
80+
@pytest.mark.parametrize(
81+
("action", "input_status"), [("disable", {"id": "OBJ-0000-0001", "status": "update"})]
82+
)
83+
async def test_async_sellers_resource_action(async_sellers_service, action, input_status):
84+
request_expected_content = b'{"id":"OBJ-0000-0001","status":"update"}'
85+
response_expected_data = {"id": "OBJ-0000-0001", "status": "new_status"}
86+
with respx.mock:
87+
mock_route = respx.post(
88+
f"https://api.example.com/public/v1/accounts/sellers/OBJ-0000-0001/{action}"
89+
).mock(
90+
return_value=httpx.Response(
91+
status_code=httpx.codes.OK,
92+
json=response_expected_data,
93+
)
94+
)
95+
sellers_obj = await getattr(async_sellers_service, action)("OBJ-0000-0001", input_status)
96+
97+
request = mock_route.calls[0].request
98+
99+
assert request.content == request_expected_content
100+
assert sellers_obj.to_dict() == response_expected_data
101+
assert isinstance(sellers_obj, Seller)
102+
103+
104+
@pytest.mark.parametrize(("action", "input_status"), [("disable", None)])
105+
async def test_async_sellers_resource_action_no_data(async_sellers_service, action, input_status):
106+
request_expected_content = b""
107+
response_expected_data = {"id": "OBJ-0000-0001", "status": "new_status"}
108+
with respx.mock:
109+
mock_route = respx.post(
110+
f"https://api.example.com/public/v1/accounts/sellers/OBJ-0000-0001/{action}"
111+
).mock(
112+
return_value=httpx.Response(
113+
status_code=httpx.codes.OK,
114+
json=response_expected_data,
115+
)
116+
)
117+
sellers_obj = await getattr(async_sellers_service, action)("OBJ-0000-0001", input_status)
118+
119+
request = mock_route.calls[0].request
120+
121+
assert request.content == request_expected_content
122+
assert sellers_obj.to_dict() == response_expected_data
123+
assert isinstance(sellers_obj, Seller)

0 commit comments

Comments
 (0)