Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mpt_api_client/resources/accounts/accounts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
from mpt_api_client.resources.accounts.sellers import AsyncSellersService, SellersService
from mpt_api_client.resources.accounts.users import AsyncUsersService, UsersService


Expand All @@ -19,6 +20,11 @@ def users(self) -> UsersService:
"""Users service."""
return UsersService(http_client=self.http_client)

@property
def sellers(self) -> SellersService:
"""Sellers service."""
return SellersService(http_client=self.http_client)


class AsyncAccounts:
"""Async Accounts MPT API Module."""
Expand All @@ -35,3 +41,8 @@ def accounts(self) -> AsyncAccountsService:
def users(self) -> AsyncUsersService:
"""Users service."""
return AsyncUsersService(http_client=self.http_client)

@property
def sellers(self) -> AsyncSellersService:
"""Sellers service."""
return AsyncSellersService(http_client=self.http_client)
64 changes: 64 additions & 0 deletions mpt_api_client/resources/accounts/sellers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
UpdateMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.models.model import ResourceData
from mpt_api_client.resources.accounts.mixins import ActivatableMixin, AsyncActivatableMixin


class Seller(Model):
"""Seller Model."""


class SellersServiceConfig:
"""Sellers Service Configuration."""

_endpoint = "/public/v1/accounts/sellers"
_model_class = Seller
_collection_key = "data"


class SellersService(
CreateMixin[Seller],
DeleteMixin,
UpdateMixin[Seller],
ActivatableMixin[Seller],
Service[Seller],
SellersServiceConfig,
):
"""Sellers Service."""

def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Seller:
"""Disable a seller.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return self._resource_action(resource_id, "POST", "disable", json=resource_data)


class AsyncSellersService(
AsyncCreateMixin[Seller],
AsyncDeleteMixin,
AsyncUpdateMixin[Seller],
AsyncActivatableMixin[Seller],
AsyncService[Seller],
SellersServiceConfig,
):
"""Async Sellers Service."""

async def disable(self, resource_id: str, resource_data: ResourceData | None = None) -> Seller:
"""Disable a seller.

Args:
resource_id: Resource ID
resource_data: Resource data will be updated
"""
return await self._resource_action(resource_id, "POST", "disable", json=resource_data)
3 changes: 3 additions & 0 deletions tests/resources/accounts/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from mpt_api_client.resources.accounts.account import AccountsService, AsyncAccountsService
from mpt_api_client.resources.accounts.accounts import Accounts, AsyncAccounts
from mpt_api_client.resources.accounts.sellers import AsyncSellersService, SellersService
from mpt_api_client.resources.accounts.users import AsyncUsersService, UsersService


Expand All @@ -20,6 +21,7 @@ def async_accounts(async_http_client):
[
("accounts", AccountsService),
("users", UsersService),
("sellers", SellersService),
],
)
def test_accounts_properties(accounts, property_name, expected_service_class):
Expand All @@ -35,6 +37,7 @@ def test_accounts_properties(accounts, property_name, expected_service_class):
[
("accounts", AsyncAccountsService),
("users", AsyncUsersService),
("sellers", AsyncSellersService),
],
)
def test_async_accounts_properties(async_accounts, property_name, expected_service_class):
Expand Down
123 changes: 123 additions & 0 deletions tests/resources/accounts/test_sellers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import httpx
import pytest
import respx

from mpt_api_client.resources.accounts.sellers import AsyncSellersService, Seller, SellersService


@pytest.fixture
def sellers_service(http_client):
return SellersService(http_client=http_client)


@pytest.fixture
def async_sellers_service(async_http_client):
return AsyncSellersService(http_client=async_http_client)


@pytest.mark.parametrize(
"method",
["get", "create", "update", "delete", "activate", "deactivate", "disable"],
)
def test_mixins_present(sellers_service, method):
assert hasattr(sellers_service, method)


@pytest.mark.parametrize(
"method",
["get", "create", "update", "delete", "activate", "deactivate", "disable"],
)
def test_async_mixins_present(async_sellers_service, method):
assert hasattr(async_sellers_service, method)


@pytest.mark.parametrize(
("action", "input_status"), [("disable", {"id": "OBJ-0000-0001", "status": "update"})]
)
def test_sellers_resource_action(sellers_service, action, input_status):
request_expected_content = b'{"id":"OBJ-0000-0001","status":"update"}'
response_expected_data = {"id": "OBJ-0000-0001", "status": "new_status"}
with respx.mock:
mock_route = respx.post(
f"https://api.example.com/public/v1/accounts/sellers/OBJ-0000-0001/{action}"
).mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
json=response_expected_data,
)
)
sellers_obj = getattr(sellers_service, action)("OBJ-0000-0001", input_status)

request = mock_route.calls[0].request

assert request.content == request_expected_content
assert sellers_obj.to_dict() == response_expected_data
assert isinstance(sellers_obj, Seller)


@pytest.mark.parametrize(("action", "input_status"), [("disable", None)])
def test_sellers_resource_action_no_data(sellers_service, action, input_status):
request_expected_content = b""
response_expected_data = {"id": "OBJ-0000-0001", "status": "new_status"}
with respx.mock:
mock_route = respx.post(
f"https://api.example.com/public/v1/accounts/sellers/OBJ-0000-0001/{action}"
).mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
json=response_expected_data,
)
)
sellers_obj = getattr(sellers_service, action)("OBJ-0000-0001", input_status)

request = mock_route.calls[0].request

assert request.content == request_expected_content
assert sellers_obj.to_dict() == response_expected_data
assert isinstance(sellers_obj, Seller)


@pytest.mark.parametrize(
("action", "input_status"), [("disable", {"id": "OBJ-0000-0001", "status": "update"})]
)
async def test_async_sellers_resource_action(async_sellers_service, action, input_status):
request_expected_content = b'{"id":"OBJ-0000-0001","status":"update"}'
response_expected_data = {"id": "OBJ-0000-0001", "status": "new_status"}
with respx.mock:
mock_route = respx.post(
f"https://api.example.com/public/v1/accounts/sellers/OBJ-0000-0001/{action}"
).mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
json=response_expected_data,
)
)
sellers_obj = await getattr(async_sellers_service, action)("OBJ-0000-0001", input_status)

request = mock_route.calls[0].request

assert request.content == request_expected_content
assert sellers_obj.to_dict() == response_expected_data
assert isinstance(sellers_obj, Seller)


@pytest.mark.parametrize(("action", "input_status"), [("disable", None)])
async def test_async_sellers_resource_action_no_data(async_sellers_service, action, input_status):
request_expected_content = b""
response_expected_data = {"id": "OBJ-0000-0001", "status": "new_status"}
with respx.mock:
mock_route = respx.post(
f"https://api.example.com/public/v1/accounts/sellers/OBJ-0000-0001/{action}"
).mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
json=response_expected_data,
)
)
sellers_obj = await getattr(async_sellers_service, action)("OBJ-0000-0001", input_status)

request = mock_route.calls[0].request

assert request.content == request_expected_content
assert sellers_obj.to_dict() == response_expected_data
assert isinstance(sellers_obj, Seller)