diff --git a/mpt_api_client/resources/catalog/products.py b/mpt_api_client/resources/catalog/products.py index 3b451c66..70920188 100644 --- a/mpt_api_client/resources/catalog/products.py +++ b/mpt_api_client/resources/catalog/products.py @@ -11,6 +11,10 @@ AsyncPublishableMixin, PublishableMixin, ) +from mpt_api_client.resources.catalog.products_parameter_groups import ( + AsyncParameterGroupsService, + ParameterGroupsService, +) class Product(Model): @@ -35,6 +39,12 @@ class ProductsService( ): """Products service.""" + def parameter_groups(self, product_id: str) -> ParameterGroupsService: + """Return parameter_groups service.""" + return ParameterGroupsService( + http_client=self.http_client, endpoint_params={"product_id": product_id} + ) + class AsyncProductsService( AsyncCreateMixin[Product], @@ -45,3 +55,9 @@ class AsyncProductsService( ProductsServiceConfig, ): """Products service.""" + + def parameter_groups(self, product_id: str) -> AsyncParameterGroupsService: + """Return parameter_groups service.""" + return AsyncParameterGroupsService( + http_client=self.http_client, endpoint_params={"product_id": product_id} + ) diff --git a/mpt_api_client/resources/catalog/products_parameter_groups.py b/mpt_api_client/resources/catalog/products_parameter_groups.py new file mode 100644 index 00000000..fb4ed0fe --- /dev/null +++ b/mpt_api_client/resources/catalog/products_parameter_groups.py @@ -0,0 +1,40 @@ +from mpt_api_client.http import AsyncService, CreateMixin, DeleteMixin, Service +from mpt_api_client.http.mixins import ( + AsyncCreateMixin, + AsyncDeleteMixin, + AsyncUpdateMixin, + UpdateMixin, +) +from mpt_api_client.models import Model + + +class ParameterGroup(Model): + """Parameter Group resource.""" + + +class ParameterGroupsServiceConfig: + """Parameter Groups service configuration.""" + + _endpoint = "/public/v1/catalog/products/{product_id}/parameter-groups" + _model_class = ParameterGroup + _collection_key = "data" + + +class ParameterGroupsService( + CreateMixin[ParameterGroup], + DeleteMixin, + UpdateMixin[ParameterGroup], + Service[ParameterGroup], + ParameterGroupsServiceConfig, +): + """Parameter Groups service.""" + + +class AsyncParameterGroupsService( + AsyncCreateMixin[ParameterGroup], + AsyncDeleteMixin, + AsyncUpdateMixin[ParameterGroup], + AsyncService[ParameterGroup], + ParameterGroupsServiceConfig, +): + """Parameter Groups service.""" diff --git a/setup.cfg b/setup.cfg index 983097f2..a78bd925 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,6 +34,7 @@ extend-ignore = per-file-ignores = mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214 mpt_api_client/resources/catalog/products.py: WPS215 + mpt_api_client/resources/catalog/products_parameter_groups.py: WPS215 tests/http/test_async_service.py: WPS204 WPS202 tests/http/test_service.py: WPS204 WPS202 diff --git a/tests/resources/catalog/test_products.py b/tests/resources/catalog/test_products.py index 870b0fa4..882727b8 100644 --- a/tests/resources/catalog/test_products.py +++ b/tests/resources/catalog/test_products.py @@ -1,6 +1,10 @@ import pytest from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService +from mpt_api_client.resources.catalog.products_parameter_groups import ( + AsyncParameterGroupsService, + ParameterGroupsService, +) @pytest.fixture @@ -25,3 +29,17 @@ def test_mixins_present(products_service, method): ) def test_async_mixins_present(async_products_service, method): assert hasattr(async_products_service, method) + + +def test_parameters_groups_service(products_service): + parameters_groups_service = products_service.parameter_groups("PRD-001") + + assert isinstance(parameters_groups_service, ParameterGroupsService) + assert parameters_groups_service.endpoint_params == {"product_id": "PRD-001"} + + +def test_async_parameters_groups_service(async_products_service): + parameters_groups_service = async_products_service.parameter_groups("PRD-001") + + assert isinstance(parameters_groups_service, AsyncParameterGroupsService) + assert parameters_groups_service.endpoint_params == {"product_id": "PRD-001"} diff --git a/tests/resources/catalog/test_products_parameter_groups.py b/tests/resources/catalog/test_products_parameter_groups.py new file mode 100644 index 00000000..75e0af3a --- /dev/null +++ b/tests/resources/catalog/test_products_parameter_groups.py @@ -0,0 +1,45 @@ +from typing import Any + +import pytest + +from mpt_api_client.resources.catalog.products_parameter_groups import ( + AsyncParameterGroupsService, + ParameterGroupsService, +) + + +@pytest.fixture +def parameter_groups_service(http_client: Any) -> ParameterGroupsService: + return ParameterGroupsService( + http_client=http_client, endpoint_params={"product_id": "PRD-001"} + ) + + +@pytest.fixture +def async_parameter_groups_service(async_http_client: Any) -> AsyncParameterGroupsService: + return AsyncParameterGroupsService( + http_client=async_http_client, endpoint_params={"product_id": "PRD-001"} + ) + + +def test_endpoint(parameter_groups_service): + assert ( + parameter_groups_service.endpoint == "/public/v1/catalog/products/PRD-001/parameter-groups" + ) + + +def test_async_endpoint(async_parameter_groups_service): + assert ( + async_parameter_groups_service.endpoint + == "/public/v1/catalog/products/PRD-001/parameter-groups" + ) + + +@pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) +def test_methods_present(parameter_groups_service, method): + assert hasattr(parameter_groups_service, method) + + +@pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) +def test_async_methods_present(async_parameter_groups_service, method): + assert hasattr(async_parameter_groups_service, method) diff --git a/tests/resources/commerce/test_order_subcription.py b/tests/resources/commerce/test_order_subcription.py index 6721d325..535d1188 100644 --- a/tests/resources/commerce/test_order_subcription.py +++ b/tests/resources/commerce/test_order_subcription.py @@ -28,3 +28,11 @@ def test_mixins_present(subscription_service, method): @pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) def test_async_mixins_present(async_subscription_service, method): assert hasattr(async_subscription_service, method) + + +def test_endpoint(subscription_service): + assert subscription_service.endpoint == "/public/v1/commerce/orders/ORD-123/subscriptions" + + +def test_async_endpoint(async_subscription_service): + assert async_subscription_service.endpoint == "/public/v1/commerce/orders/ORD-123/subscriptions"