Skip to content

Commit 02d3f13

Browse files
author
Robert Segal
committed
Add price list and price list items endpoints
1 parent 24d6131 commit 02d3f13

File tree

7 files changed

+234
-0
lines changed

7 files changed

+234
-0
lines changed

mpt_api_client/resources/catalog/catalog.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
AuthorizationsService,
55
)
66
from mpt_api_client.resources.catalog.items import AsyncItemsService, ItemsService
7+
from mpt_api_client.resources.catalog.price_list_items import (
8+
AsyncPriceListItemsService,
9+
PriceListItemsService,
10+
)
11+
from mpt_api_client.resources.catalog.price_lists import (
12+
AsyncPriceListsService,
13+
PriceListsService,
14+
)
715
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService
816

917

@@ -18,6 +26,17 @@ def authorizations(self) -> AuthorizationsService:
1826
"""Authorizations service."""
1927
return AuthorizationsService(http_client=self.http_client)
2028

29+
def price_list_items(self, price_list_id: str) -> PriceListItemsService:
30+
"""Price List Items service."""
31+
return PriceListItemsService(
32+
http_client=self.http_client, endpoint_params={"price_list_id": price_list_id}
33+
)
34+
35+
@property
36+
def price_lists(self) -> PriceListsService:
37+
"""Price Lists service."""
38+
return PriceListsService(http_client=self.http_client)
39+
2140
@property
2241
def products(self) -> ProductsService:
2342
"""Products service."""
@@ -40,6 +59,17 @@ def authorizations(self) -> AsyncAuthorizationsService:
4059
"""Authorizations service."""
4160
return AsyncAuthorizationsService(http_client=self.http_client)
4261

62+
def price_list_items(self, price_list_id: str) -> AsyncPriceListItemsService:
63+
"""Price List Items service."""
64+
return AsyncPriceListItemsService(
65+
http_client=self.http_client, endpoint_params={"price_list_id": price_list_id}
66+
)
67+
68+
@property
69+
def price_lists(self) -> AsyncPriceListsService:
70+
"""Price Lists service."""
71+
return AsyncPriceListsService(http_client=self.http_client)
72+
4373
@property
4474
def products(self) -> AsyncProductsService:
4575
"""Products service."""
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 PriceListItem(Model):
12+
"""Price List Item resource."""
13+
14+
15+
class PriceListItemsServiceConfig:
16+
"""Price List Items service configuration."""
17+
18+
_endpoint = "/public/v1/catalog/price-lists/{price_list_id}/items"
19+
_model_class = PriceListItem
20+
_collection_key = "data"
21+
22+
23+
class PriceListItemsService(
24+
CreateMixin[PriceListItem],
25+
DeleteMixin,
26+
UpdateMixin[PriceListItem],
27+
Service[PriceListItem],
28+
PriceListItemsServiceConfig,
29+
):
30+
"""Price List Items service."""
31+
32+
33+
class AsyncPriceListItemsService(
34+
AsyncCreateMixin[PriceListItem],
35+
AsyncDeleteMixin,
36+
AsyncUpdateMixin[PriceListItem],
37+
AsyncService[PriceListItem],
38+
PriceListItemsServiceConfig,
39+
):
40+
"""Price List Items service."""
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
AsyncDeleteMixin,
5+
AsyncUpdateMixin,
6+
CreateMixin,
7+
DeleteMixin,
8+
UpdateMixin,
9+
)
10+
from mpt_api_client.models import Model
11+
from mpt_api_client.resources.catalog.price_list_items import (
12+
AsyncPriceListItemsService,
13+
PriceListItemsService,
14+
)
15+
16+
17+
class PriceList(Model):
18+
"""Price List resource."""
19+
20+
21+
class PriceListsServiceConfig:
22+
"""Price Lists service configuration."""
23+
24+
_endpoint = "/public/v1/catalog/price-lists"
25+
_model_class = PriceList
26+
_collection_key = "data"
27+
28+
29+
class PriceListsService(
30+
CreateMixin[PriceList],
31+
DeleteMixin,
32+
UpdateMixin[PriceList],
33+
Service[PriceList],
34+
PriceListsServiceConfig,
35+
):
36+
"""Price Lists service."""
37+
38+
def items(self, price_list_id: str) -> PriceListItemsService:
39+
"""Price List Items service."""
40+
return PriceListItemsService(
41+
http_client=self.http_client, endpoint_params={"price_list_id": price_list_id}
42+
)
43+
44+
45+
class AsyncPriceListsService(
46+
AsyncCreateMixin[PriceList],
47+
AsyncDeleteMixin,
48+
AsyncUpdateMixin[PriceList],
49+
AsyncService[PriceList],
50+
PriceListsServiceConfig,
51+
):
52+
"""Price Lists service."""
53+
54+
def items(self, price_list_id: str) -> AsyncPriceListItemsService:
55+
"""Price List Items service."""
56+
return AsyncPriceListItemsService(
57+
http_client=self.http_client, endpoint_params={"price_list_id": price_list_id}
58+
)

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ per-file-ignores =
3636
mpt_api_client/resources/catalog/authorizations.py: WPS215
3737
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
3838
mpt_api_client/resources/catalog/items.py: WPS215
39+
mpt_api_client/resources/catalog/price_lists.py: WPS215 WPS110
40+
mpt_api_client/resources/catalog/price_list_items.py: WPS215
3941
mpt_api_client/resources/catalog/products_item_groups.py: WPS215
4042
mpt_api_client/resources/catalog/products_parameter_groups.py: WPS215
4143
mpt_api_client/resources/catalog/products_parameters.py: WPS215

tests/resources/catalog/test_catalog.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
)
77
from mpt_api_client.resources.catalog.catalog import AsyncCatalog, Catalog
88
from mpt_api_client.resources.catalog.items import AsyncItemsService, ItemsService
9+
from mpt_api_client.resources.catalog.price_lists import (
10+
AsyncPriceListsService,
11+
PriceListsService,
12+
)
913
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService
1014

1115

@@ -23,6 +27,7 @@ def async_catalog(async_http_client):
2327
("property_name", "expected_service_class"),
2428
[
2529
("authorizations", AuthorizationsService),
30+
("price_lists", PriceListsService),
2631
("products", ProductsService),
2732
("items", ItemsService),
2833
],
@@ -39,6 +44,7 @@ def test_catalog_properties(catalog, property_name, expected_service_class):
3944
("property_name", "expected_service_class"),
4045
[
4146
("authorizations", AsyncAuthorizationsService),
47+
("price_lists", AsyncPriceListsService),
4248
("products", AsyncProductsService),
4349
("items", AsyncItemsService),
4450
],
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.catalog.price_list_items import (
4+
AsyncPriceListItemsService,
5+
PriceListItemsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def price_list_items_service(http_client):
11+
return PriceListItemsService(
12+
http_client=http_client, endpoint_params={"price_list_id": "ITM-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_price_list_items_service(async_http_client):
18+
return AsyncPriceListItemsService(
19+
http_client=async_http_client, endpoint_params={"price_list_id": "ITM-0000-0001"}
20+
)
21+
22+
23+
@pytest.fixture
24+
def test_endpoint(price_list_items_service):
25+
assert price_list_items_service.endpoint == "/public/v1/catalog/price-lists/ITM-0000-0001/items"
26+
27+
28+
@pytest.fixture
29+
def async_test_endpoint(async_price_list_items_service):
30+
assert async_price_list_items_service.endpoint == (
31+
"/public/v1/catalog/price-lists/ITM-0000-0001/items"
32+
)
33+
34+
35+
@pytest.mark.parametrize("method", ["get", "create", "delete", "update"])
36+
def test_methods_present(price_list_items_service, method):
37+
assert hasattr(price_list_items_service, method)
38+
39+
40+
@pytest.mark.parametrize("method", ["get", "create", "delete", "update"])
41+
def test_async_methods_present(async_price_list_items_service, method):
42+
assert hasattr(async_price_list_items_service, method)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.catalog.price_list_items import (
4+
AsyncPriceListItemsService,
5+
PriceListItemsService,
6+
)
7+
from mpt_api_client.resources.catalog.price_lists import (
8+
AsyncPriceListsService,
9+
PriceListsService,
10+
)
11+
12+
13+
@pytest.fixture
14+
def price_lists_service(http_client):
15+
return PriceListsService(http_client=http_client)
16+
17+
18+
@pytest.fixture
19+
def async_price_lists_service(http_client):
20+
return AsyncPriceListsService(http_client=http_client)
21+
22+
23+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
24+
def test_mixins_present(price_lists_service, method):
25+
assert hasattr(price_lists_service, method)
26+
27+
28+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
29+
def test_async_mixins_present(async_price_lists_service, method):
30+
assert hasattr(async_price_lists_service, method)
31+
32+
33+
@pytest.mark.parametrize(
34+
("service_method", "expected_model_class"),
35+
[
36+
("items", PriceListItemsService),
37+
],
38+
)
39+
def test_property_services(price_lists_service, service_method, expected_model_class):
40+
property_service = getattr(price_lists_service, service_method)("ITM-0000-0001")
41+
42+
assert isinstance(property_service, expected_model_class)
43+
assert property_service.endpoint_params == {"price_list_id": "ITM-0000-0001"}
44+
45+
46+
@pytest.mark.parametrize(
47+
("service_method", "expected_model_class"),
48+
[
49+
("items", AsyncPriceListItemsService),
50+
],
51+
)
52+
def test_async_property_services(async_price_lists_service, service_method, expected_model_class):
53+
property_service = getattr(async_price_lists_service, service_method)("ITM-0000-0001")
54+
55+
assert isinstance(property_service, expected_model_class)
56+
assert property_service.endpoint_params == {"price_list_id": "ITM-0000-0001"}

0 commit comments

Comments
 (0)