diff --git a/mpt_api_client/resources/accounts/accounts.py b/mpt_api_client/resources/accounts/accounts.py index 812e1ad..8471f10 100644 --- a/mpt_api_client/resources/accounts/accounts.py +++ b/mpt_api_client/resources/accounts/accounts.py @@ -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 @@ -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.""" @@ -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) diff --git a/mpt_api_client/resources/accounts/sellers.py b/mpt_api_client/resources/accounts/sellers.py new file mode 100644 index 0000000..7443612 --- /dev/null +++ b/mpt_api_client/resources/accounts/sellers.py @@ -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) diff --git a/tests/resources/accounts/test_accounts.py b/tests/resources/accounts/test_accounts.py index 824b961..24d90f6 100644 --- a/tests/resources/accounts/test_accounts.py +++ b/tests/resources/accounts/test_accounts.py @@ -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 @@ -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): @@ -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): diff --git a/tests/resources/accounts/test_sellers.py b/tests/resources/accounts/test_sellers.py new file mode 100644 index 0000000..42e3ab9 --- /dev/null +++ b/tests/resources/accounts/test_sellers.py @@ -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)