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
16 changes: 16 additions & 0 deletions mpt_api_client/resources/catalog/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
40 changes: 40 additions & 0 deletions mpt_api_client/resources/catalog/products_item_groups.py
Original file line number Diff line number Diff line change
@@ -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."""
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/resources/catalog/test_products.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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),
],
Expand All @@ -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),
],
Expand Down
36 changes: 36 additions & 0 deletions tests/resources/catalog/test_products_item_groups.py
Original file line number Diff line number Diff line change
@@ -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)