Skip to content

Commit e47e712

Browse files
authored
MPT-13319 Add catalog products item groups endpoints (#33)
2 parents e9db3ed + c790442 commit e47e712

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

mpt_api_client/resources/catalog/products.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
AsyncPublishableMixin,
1212
PublishableMixin,
1313
)
14+
from mpt_api_client.resources.catalog.products_item_groups import (
15+
AsyncItemGroupsService,
16+
ItemGroupsService,
17+
)
1418
from mpt_api_client.resources.catalog.products_parameter_groups import (
1519
AsyncParameterGroupsService,
1620
ParameterGroupsService,
@@ -43,6 +47,12 @@ class ProductsService(
4347
):
4448
"""Products service."""
4549

50+
def item_groups(self, product_id: str) -> ItemGroupsService:
51+
"""Return item_groups service."""
52+
return ItemGroupsService(
53+
http_client=self.http_client, endpoint_params={"product_id": product_id}
54+
)
55+
4656
def parameter_groups(self, product_id: str) -> ParameterGroupsService:
4757
"""Return parameter_groups service."""
4858
return ParameterGroupsService(
@@ -66,6 +76,12 @@ class AsyncProductsService(
6676
):
6777
"""Products service."""
6878

79+
def item_groups(self, product_id: str) -> AsyncItemGroupsService:
80+
"""Return item_groups service."""
81+
return AsyncItemGroupsService(
82+
http_client=self.http_client, endpoint_params={"product_id": product_id}
83+
)
84+
6985
def parameter_groups(self, product_id: str) -> AsyncParameterGroupsService:
7086
"""Return parameter_groups service."""
7187
return AsyncParameterGroupsService(
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from mpt_api_client.http import AsyncService, CreateMixin, DeleteMixin, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
AsyncDeleteMixin,
5+
AsyncUpdateMixin,
6+
UpdateMixin,
7+
)
8+
from mpt_api_client.models import Model
9+
10+
11+
class ItemGroup(Model):
12+
"""Item Group resource."""
13+
14+
15+
class ItemGroupsServiceConfig:
16+
"""Item Groups service configuration."""
17+
18+
_endpoint = "/public/v1/catalog/products/{product_id}/item-groups"
19+
_model_class = ItemGroup
20+
_collection_key = "data"
21+
22+
23+
class ItemGroupsService(
24+
CreateMixin[ItemGroup],
25+
DeleteMixin,
26+
UpdateMixin[ItemGroup],
27+
Service[ItemGroup],
28+
ItemGroupsServiceConfig,
29+
):
30+
"""Item Groups service."""
31+
32+
33+
class AsyncItemGroupsService(
34+
AsyncCreateMixin[ItemGroup],
35+
AsyncDeleteMixin,
36+
AsyncUpdateMixin[ItemGroup],
37+
AsyncService[ItemGroup],
38+
ItemGroupsServiceConfig,
39+
):
40+
"""Item Groups service."""

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ per-file-ignores =
3535
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
3636
mpt_api_client/resources/catalog/products.py: WPS215
3737
mpt_api_client/resources/catalog/items.py: WPS215
38+
mpt_api_client/resources/catalog/products_item_groups.py: WPS215
3839
mpt_api_client/resources/catalog/products_parameter_groups.py: WPS215
3940
mpt_api_client/resources/catalog/products_parameters.py: WPS215
4041
tests/http/test_async_service.py: WPS204 WPS202

tests/resources/catalog/test_products.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pytest
22

33
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService
4+
from mpt_api_client.resources.catalog.products_item_groups import (
5+
AsyncItemGroupsService,
6+
ItemGroupsService,
7+
)
48
from mpt_api_client.resources.catalog.products_parameter_groups import (
59
AsyncParameterGroupsService,
610
ParameterGroupsService,
@@ -38,6 +42,7 @@ def test_async_mixins_present(async_products_service, method):
3842
@pytest.mark.parametrize(
3943
("service_method", "expected_service_class"),
4044
[
45+
("item_groups", ItemGroupsService),
4146
("parameter_groups", ParameterGroupsService),
4247
("product_parameters", ParametersService),
4348
],
@@ -52,6 +57,7 @@ def test_property_services(products_service, service_method, expected_service_cl
5257
@pytest.mark.parametrize(
5358
("service_method", "expected_service_class"),
5459
[
60+
("item_groups", AsyncItemGroupsService),
5561
("parameter_groups", AsyncParameterGroupsService),
5662
("product_parameters", AsyncParametersService),
5763
],
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.catalog.products_item_groups import (
4+
AsyncItemGroupsService,
5+
ItemGroupsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def item_groups_service(http_client):
11+
return ItemGroupsService(http_client=http_client, endpoint_params={"product_id": "PRD-001"})
12+
13+
14+
@pytest.fixture
15+
def async_item_groups_service(async_http_client):
16+
return AsyncItemGroupsService(
17+
http_client=async_http_client, endpoint_params={"product_id": "PRD-001"}
18+
)
19+
20+
21+
def test_endpoint(item_groups_service):
22+
assert item_groups_service.endpoint == "/public/v1/catalog/products/PRD-001/item-groups"
23+
24+
25+
def test_async_endpoint(async_item_groups_service):
26+
assert async_item_groups_service.endpoint == "/public/v1/catalog/products/PRD-001/item-groups"
27+
28+
29+
@pytest.mark.parametrize("method", ["get", "create", "delete", "update"])
30+
def test_methods_present(item_groups_service, method):
31+
assert hasattr(item_groups_service, method)
32+
33+
34+
@pytest.mark.parametrize("method", ["get", "create", "delete", "update"])
35+
def test_async_methods_present(async_item_groups_service, method):
36+
assert hasattr(async_item_groups_service, method)

0 commit comments

Comments
 (0)