Skip to content

Commit 1d9c023

Browse files
albertsolad3rky
authored andcommitted
MPT-13422 Add catalog product update settings
1 parent a8e143b commit 1d9c023

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

mpt_api_client/resources/catalog/products.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
DeleteMixin,
77
UpdateMixin,
88
)
9-
from mpt_api_client.models import Model
9+
from mpt_api_client.models import Model, ResourceData
1010
from mpt_api_client.resources.catalog.mixins import (
1111
AsyncPublishableMixin,
1212
PublishableMixin,
@@ -103,6 +103,10 @@ def terms(self, product_id: str) -> TermService:
103103
"""Return terms service."""
104104
return TermService(http_client=self.http_client, endpoint_params={"product_id": product_id})
105105

106+
def update_settings(self, product_id: str, settings: ResourceData) -> Product:
107+
"""Update product settings."""
108+
return self._resource_action(product_id, "PUT", "settings", settings)
109+
106110

107111
class AsyncProductsService(
108112
AsyncCreateMixin[Product],
@@ -155,3 +159,7 @@ def terms(self, product_id: str) -> AsyncTermService:
155159
return AsyncTermService(
156160
http_client=self.http_client, endpoint_params={"product_id": product_id}
157161
)
162+
163+
async def update_settings(self, product_id: str, settings: ResourceData) -> Product:
164+
"""Update product settings."""
165+
return await self._resource_action(product_id, "PUT", "settings", settings)

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extend-ignore =
3333

3434
per-file-ignores =
3535
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
36-
mpt_api_client/resources/catalog/products.py: WPS204 WPS215
36+
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
3737
mpt_api_client/resources/catalog/items.py: WPS215
3838
mpt_api_client/resources/catalog/products_item_groups.py: WPS215
3939
mpt_api_client/resources/catalog/products_parameter_groups.py: WPS215
@@ -48,6 +48,7 @@ per-file-ignores =
4848
tests/http/test_async_service.py: WPS204 WPS202
4949
tests/http/test_service.py: WPS204 WPS202
5050
tests/http/test_mixins.py: WPS204 WPS202
51+
tests/resources/catalog/test_products.py: WPS202 WPS210
5152

5253
tests/*:
5354
# Allow magic strings.

tests/resources/catalog/test_products.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import httpx
12
import pytest
3+
import respx
24

35
from mpt_api_client.resources.catalog.product_terms import (
46
AsyncTermService,
@@ -42,14 +44,16 @@ def async_products_service(async_http_client):
4244

4345

4446
@pytest.mark.parametrize(
45-
"method", ["get", "create", "update", "delete", "review", "publish", "unpublish"]
47+
"method",
48+
["get", "create", "update", "delete", "review", "publish", "unpublish", "update_settings"],
4649
)
4750
def test_mixins_present(products_service, method):
4851
assert hasattr(products_service, method)
4952

5053

5154
@pytest.mark.parametrize(
52-
"method", ["get", "create", "update", "delete", "review", "publish", "unpublish"]
55+
"method",
56+
["get", "create", "update", "delete", "review", "publish", "unpublish", "update_settings"],
5357
)
5458
def test_async_mixins_present(async_products_service, method):
5559
assert hasattr(async_products_service, method)
@@ -91,3 +95,43 @@ def test_async_property_services(async_products_service, service_method, expecte
9195

9296
assert isinstance(property_service, expected_service_class)
9397
assert property_service.endpoint_params == {"product_id": "PRD-001"}
98+
99+
100+
def test_update_settings(products_service):
101+
"""Test updating product settings."""
102+
product_id = "PRD-001"
103+
settings_data = {"visibility": "public", "searchable": True, "featured": False}
104+
expected_response = {"id": product_id, "name": "Test Product", "settings": settings_data}
105+
106+
with respx.mock:
107+
mock_route = respx.put(
108+
f"https://api.example.com/public/v1/catalog/products/{product_id}/settings"
109+
).mock(return_value=httpx.Response(httpx.codes.OK, json=expected_response))
110+
111+
product = products_service.update_settings(product_id, settings_data)
112+
113+
assert mock_route.call_count == 1
114+
request = mock_route.calls[0].request
115+
assert request.method == "PUT"
116+
assert request.url.path == f"/public/v1/catalog/products/{product_id}/settings"
117+
assert product.to_dict() == expected_response
118+
119+
120+
async def test_async_update_settings(async_products_service):
121+
"""Test updating product settings asynchronously."""
122+
product_id = "PRD-002"
123+
settings_data = {"visibility": "private", "searchable": False, "featured": True}
124+
expected_response = {"id": product_id, "name": "Test Product Async", "settings": settings_data}
125+
126+
with respx.mock:
127+
mock_route = respx.put(
128+
f"https://api.example.com/public/v1/catalog/products/{product_id}/settings"
129+
).mock(return_value=httpx.Response(httpx.codes.OK, json=expected_response))
130+
131+
product = await async_products_service.update_settings(product_id, settings_data)
132+
133+
assert mock_route.call_count == 1
134+
request = mock_route.calls[0].request
135+
assert request.method == "PUT"
136+
assert request.url.path == f"/public/v1/catalog/products/{product_id}/settings"
137+
assert product.to_dict() == expected_response

0 commit comments

Comments
 (0)