Skip to content

Commit 6897e08

Browse files
committed
MPT-13325 Add catalog products templates
1 parent b177d20 commit 6897e08

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
@@ -31,6 +31,10 @@
3131
AsyncParametersService,
3232
ParametersService,
3333
)
34+
from mpt_api_client.resources.catalog.products_templates import (
35+
AsyncTemplatesService,
36+
TemplatesService,
37+
)
3438

3539

3640
class Product(Model):
@@ -85,6 +89,12 @@ def product_parameters(self, product_id: str) -> ParametersService:
8589
http_client=self.http_client, endpoint_params={"product_id": product_id}
8690
)
8791

92+
def templates(self, product_id: str) -> TemplatesService:
93+
"""Return templates service."""
94+
return TemplatesService(
95+
http_client=self.http_client, endpoint_params={"product_id": product_id}
96+
)
97+
8898

8999
class AsyncProductsService(
90100
AsyncCreateMixin[Product],
@@ -125,3 +135,9 @@ def product_parameters(self, product_id: str) -> AsyncParametersService:
125135
return AsyncParametersService(
126136
http_client=self.http_client, endpoint_params={"product_id": product_id}
127137
)
138+
139+
def templates(self, product_id: str) -> AsyncTemplatesService:
140+
"""Return templates service."""
141+
return AsyncTemplatesService(
142+
http_client=self.http_client, endpoint_params={"product_id": product_id}
143+
)
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 Template(Model):
12+
"""Template resource."""
13+
14+
15+
class TemplatesServiceConfig:
16+
"""Templates service configuration."""
17+
18+
_endpoint = "/public/v1/catalog/products/{product_id}/templates"
19+
_model_class = Template
20+
_collection_key = "data"
21+
22+
23+
class TemplatesService(
24+
CreateMixin[Template],
25+
DeleteMixin,
26+
UpdateMixin[Template],
27+
Service[Template],
28+
TemplatesServiceConfig,
29+
):
30+
"""Templates service."""
31+
32+
33+
class AsyncTemplatesService(
34+
AsyncCreateMixin[Template],
35+
AsyncDeleteMixin,
36+
AsyncUpdateMixin[Template],
37+
AsyncService[Template],
38+
TemplatesServiceConfig,
39+
):
40+
"""Templates service."""

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ per-file-ignores =
4040
mpt_api_client/resources/catalog/products_parameters.py: WPS215
4141
mpt_api_client/resources/catalog/products_media.py: WPS215
4242
mpt_api_client/resources/catalog/products_documents.py: WPS215
43+
mpt_api_client/resources/catalog/products_templates.py: WPS215
4344
tests/http/test_async_service.py: WPS204 WPS202
4445
tests/http/test_service.py: WPS204 WPS202
4546

tests/resources/catalog/test_products.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
AsyncParametersService,
2222
ParametersService,
2323
)
24+
from mpt_api_client.resources.catalog.products_templates import (
25+
AsyncTemplatesService,
26+
TemplatesService,
27+
)
2428

2529

2630
@pytest.fixture
@@ -55,6 +59,7 @@ def test_async_mixins_present(async_products_service, method):
5559
("media", MediaService),
5660
("documents", DocumentService),
5761
("product_parameters", ParametersService),
62+
("templates", TemplatesService),
5863
],
5964
)
6065
def test_property_services(products_service, service_method, expected_service_class):
@@ -72,6 +77,7 @@ def test_property_services(products_service, service_method, expected_service_cl
7277
("media", AsyncMediaService),
7378
("documents", AsyncDocumentService),
7479
("product_parameters", AsyncParametersService),
80+
("templates", AsyncTemplatesService),
7581
],
7682
)
7783
def test_async_property_services(async_products_service, service_method, expected_service_class):
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_templates import (
4+
AsyncTemplatesService,
5+
TemplatesService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def templates_service(http_client):
11+
return TemplatesService(http_client=http_client, endpoint_params={"product_id": "PRD-001"})
12+
13+
14+
@pytest.fixture
15+
def async_templates_service(async_http_client):
16+
return AsyncTemplatesService(
17+
http_client=async_http_client, endpoint_params={"product_id": "PRD-001"}
18+
)
19+
20+
21+
def test_endpoint(templates_service):
22+
assert templates_service.endpoint == "/public/v1/catalog/products/PRD-001/templates"
23+
24+
25+
def test_async_endpoint(async_templates_service):
26+
assert async_templates_service.endpoint == "/public/v1/catalog/products/PRD-001/templates"
27+
28+
29+
@pytest.mark.parametrize("method", ["get", "create", "delete", "update", "fetch_page", "iterate"])
30+
def test_methods_present(templates_service, method):
31+
assert hasattr(templates_service, method)
32+
33+
34+
@pytest.mark.parametrize("method", ["get", "create", "delete", "update", "fetch_page", "iterate"])
35+
def test_async_methods_present(async_templates_service, method):
36+
assert hasattr(async_templates_service, method)

0 commit comments

Comments
 (0)