|
| 1 | +import httpx |
1 | 2 | import pytest |
| 3 | +import respx |
2 | 4 |
|
3 | 5 | from mpt_api_client.resources.catalog.product_terms import ( |
4 | 6 | AsyncTermService, |
@@ -42,14 +44,16 @@ def async_products_service(async_http_client): |
42 | 44 |
|
43 | 45 |
|
44 | 46 | @pytest.mark.parametrize( |
45 | | - "method", ["get", "create", "update", "delete", "review", "publish", "unpublish"] |
| 47 | + "method", |
| 48 | + ["get", "create", "update", "delete", "review", "publish", "unpublish", "update_settings"], |
46 | 49 | ) |
47 | 50 | def test_mixins_present(products_service, method): |
48 | 51 | assert hasattr(products_service, method) |
49 | 52 |
|
50 | 53 |
|
51 | 54 | @pytest.mark.parametrize( |
52 | | - "method", ["get", "create", "update", "delete", "review", "publish", "unpublish"] |
| 55 | + "method", |
| 56 | + ["get", "create", "update", "delete", "review", "publish", "unpublish", "update_settings"], |
53 | 57 | ) |
54 | 58 | def test_async_mixins_present(async_products_service, method): |
55 | 59 | assert hasattr(async_products_service, method) |
@@ -91,3 +95,43 @@ def test_async_property_services(async_products_service, service_method, expecte |
91 | 95 |
|
92 | 96 | assert isinstance(property_service, expected_service_class) |
93 | 97 | 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