diff --git a/mpt_api_client/resources/catalog/products.py b/mpt_api_client/resources/catalog/products.py index 3c80002c..a27b5c66 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_item_groups import ( + AsyncItemGroupsService, + ItemGroupsService, +) from mpt_api_client.resources.catalog.products_parameter_groups import ( AsyncParameterGroupsService, ParameterGroupsService, @@ -43,6 +47,12 @@ class ProductsService( ): """Products service.""" + def item_groups(self, product_id: str) -> ItemGroupsService: + """Return item_groups service.""" + return ItemGroupsService( + http_client=self.http_client, endpoint_params={"product_id": product_id} + ) + def parameter_groups(self, product_id: str) -> ParameterGroupsService: """Return parameter_groups service.""" return ParameterGroupsService( @@ -66,6 +76,12 @@ class AsyncProductsService( ): """Products service.""" + def item_groups(self, product_id: str) -> AsyncItemGroupsService: + """Return item_groups service.""" + return AsyncItemGroupsService( + http_client=self.http_client, endpoint_params={"product_id": product_id} + ) + def parameter_groups(self, product_id: str) -> AsyncParameterGroupsService: """Return parameter_groups service.""" return AsyncParameterGroupsService( diff --git a/mpt_api_client/resources/catalog/products_item_groups.py b/mpt_api_client/resources/catalog/products_item_groups.py new file mode 100644 index 00000000..bace7c0f --- /dev/null +++ b/mpt_api_client/resources/catalog/products_item_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 ItemGroup(Model): + """Item Group resource.""" + + +class ItemGroupsServiceConfig: + """Item Groups service configuration.""" + + _endpoint = "/public/v1/catalog/products/{product_id}/item-groups" + _model_class = ItemGroup + _collection_key = "data" + + +class ItemGroupsService( + CreateMixin[ItemGroup], + DeleteMixin, + UpdateMixin[ItemGroup], + Service[ItemGroup], + ItemGroupsServiceConfig, +): + """Item Groups service.""" + + +class AsyncItemGroupsService( + AsyncCreateMixin[ItemGroup], + AsyncDeleteMixin, + AsyncUpdateMixin[ItemGroup], + AsyncService[ItemGroup], + ItemGroupsServiceConfig, +): + """Item Groups service.""" diff --git a/setup.cfg b/setup.cfg index 9e49df6c..a584cbbb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,6 +35,7 @@ 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/items.py: WPS215 + mpt_api_client/resources/catalog/products_item_groups.py: WPS215 mpt_api_client/resources/catalog/products_parameter_groups.py: WPS215 mpt_api_client/resources/catalog/products_parameters.py: WPS215 tests/http/test_async_service.py: WPS204 WPS202 diff --git a/tests/resources/catalog/test_products.py b/tests/resources/catalog/test_products.py index 7746fe96..b34c854d 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_item_groups import ( + AsyncItemGroupsService, + ItemGroupsService, +) from mpt_api_client.resources.catalog.products_parameter_groups import ( AsyncParameterGroupsService, ParameterGroupsService, @@ -38,6 +42,7 @@ def test_async_mixins_present(async_products_service, method): @pytest.mark.parametrize( ("service_method", "expected_service_class"), [ + ("item_groups", ItemGroupsService), ("parameter_groups", ParameterGroupsService), ("product_parameters", ParametersService), ], @@ -52,6 +57,7 @@ def test_property_services(products_service, service_method, expected_service_cl @pytest.mark.parametrize( ("service_method", "expected_service_class"), [ + ("item_groups", AsyncItemGroupsService), ("parameter_groups", AsyncParameterGroupsService), ("product_parameters", AsyncParametersService), ], diff --git a/tests/resources/catalog/test_products_item_groups.py b/tests/resources/catalog/test_products_item_groups.py new file mode 100644 index 00000000..2bfb9d8a --- /dev/null +++ b/tests/resources/catalog/test_products_item_groups.py @@ -0,0 +1,36 @@ +import pytest + +from mpt_api_client.resources.catalog.products_item_groups import ( + AsyncItemGroupsService, + ItemGroupsService, +) + + +@pytest.fixture +def item_groups_service(http_client): + return ItemGroupsService(http_client=http_client, endpoint_params={"product_id": "PRD-001"}) + + +@pytest.fixture +def async_item_groups_service(async_http_client): + return AsyncItemGroupsService( + http_client=async_http_client, endpoint_params={"product_id": "PRD-001"} + ) + + +def test_endpoint(item_groups_service): + assert item_groups_service.endpoint == "/public/v1/catalog/products/PRD-001/item-groups" + + +def test_async_endpoint(async_item_groups_service): + assert async_item_groups_service.endpoint == "/public/v1/catalog/products/PRD-001/item-groups" + + +@pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) +def test_methods_present(item_groups_service, method): + assert hasattr(item_groups_service, method) + + +@pytest.mark.parametrize("method", ["get", "create", "delete", "update"]) +def test_async_methods_present(async_item_groups_service, method): + assert hasattr(async_item_groups_service, method)