Skip to content

Commit b625283

Browse files
author
Robert Segal
committed
Added catalog listings endpoints
1 parent 4341e51 commit b625283

File tree

5 files changed

+82
-27
lines changed

5 files changed

+82
-27
lines changed

mpt_api_client/resources/catalog/catalog.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
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-
)
7+
from mpt_api_client.resources.catalog.listings import AsyncListingsService, ListingsService
118
from mpt_api_client.resources.catalog.price_lists import (
129
AsyncPriceListsService,
1310
PriceListsService,
@@ -26,11 +23,10 @@ def authorizations(self) -> AuthorizationsService:
2623
"""Authorizations service."""
2724
return AuthorizationsService(http_client=self.http_client)
2825

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-
)
26+
@property
27+
def listings(self) -> ListingsService:
28+
"""Listings service."""
29+
return ListingsService(http_client=self.http_client)
3430

3531
@property
3632
def price_lists(self) -> PriceListsService:
@@ -59,11 +55,10 @@ def authorizations(self) -> AsyncAuthorizationsService:
5955
"""Authorizations service."""
6056
return AsyncAuthorizationsService(http_client=self.http_client)
6157

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-
)
58+
@property
59+
def listings(self) -> AsyncListingsService:
60+
"""Listings service."""
61+
return AsyncListingsService(http_client=self.http_client)
6762

6863
@property
6964
def price_lists(self) -> AsyncPriceListsService:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
12+
13+
class Listing(Model):
14+
"""Listing resource."""
15+
16+
17+
class ListingsServiceConfig:
18+
"""Listings service configuration."""
19+
20+
_endpoint = "/public/v1/catalog/listings"
21+
_model_class = Listing
22+
_collection_key = "data"
23+
24+
25+
class ListingsService(
26+
CreateMixin[Listing],
27+
DeleteMixin,
28+
UpdateMixin[Listing],
29+
Service[Listing],
30+
ListingsServiceConfig,
31+
):
32+
"""Listings service."""
33+
34+
35+
class AsyncListingsService(
36+
AsyncCreateMixin[Listing],
37+
AsyncDeleteMixin,
38+
AsyncUpdateMixin[Listing],
39+
AsyncService[Listing],
40+
ListingsServiceConfig,
41+
):
42+
"""Listings service."""

setup.cfg

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,10 @@ extend-ignore =
3232

3333

3434
per-file-ignores =
35+
mpt_api_client/resources/catalog/*.py: WPS110 WPS215
36+
mpt_api_client/resources/commerce/*.py: WPS215
3537
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
36-
mpt_api_client/resources/catalog/authorizations.py: WPS215
3738
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
38-
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
41-
mpt_api_client/resources/catalog/products_item_groups.py: WPS215
42-
mpt_api_client/resources/catalog/products_parameter_groups.py: WPS215
43-
mpt_api_client/resources/catalog/products_parameters.py: WPS215
44-
mpt_api_client/resources/catalog/products_media.py: WPS215
45-
mpt_api_client/resources/catalog/products_documents.py: WPS215
46-
mpt_api_client/resources/catalog/products_templates.py: WPS215
47-
mpt_api_client/resources/catalog/product_terms.py: WPS215
48-
mpt_api_client/resources/catalog/product_term_variants.py: WPS215
49-
mpt_api_client/resources/commerce/agreements_attachments.py: WPS215
5039
mpt_api_client/http/mixins.py: WPS202
5140
tests/http/test_async_service.py: WPS204 WPS202
5241
tests/http/test_service.py: WPS204 WPS202

tests/resources/catalog/test_catalog.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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.listings import AsyncListingsService, ListingsService
910
from mpt_api_client.resources.catalog.price_lists import (
1011
AsyncPriceListsService,
1112
PriceListsService,
@@ -27,6 +28,7 @@ def async_catalog(async_http_client):
2728
("property_name", "expected_service_class"),
2829
[
2930
("authorizations", AuthorizationsService),
31+
("listings", ListingsService),
3032
("price_lists", PriceListsService),
3133
("products", ProductsService),
3234
("items", ItemsService),
@@ -44,6 +46,7 @@ def test_catalog_properties(catalog, property_name, expected_service_class):
4446
("property_name", "expected_service_class"),
4547
[
4648
("authorizations", AsyncAuthorizationsService),
49+
("listings", AsyncListingsService),
4750
("price_lists", AsyncPriceListsService),
4851
("products", AsyncProductsService),
4952
("items", AsyncItemsService),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.catalog.listings import (
4+
AsyncListingsService,
5+
ListingsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def listings_service(http_client):
11+
return ListingsService(http_client=http_client)
12+
13+
14+
@pytest.fixture
15+
def async_listings_service(async_http_client):
16+
return AsyncListingsService(http_client=async_http_client)
17+
18+
19+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
20+
def test_mixins_present(listings_service, method):
21+
assert hasattr(listings_service, method)
22+
23+
24+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
25+
def test_async_mixins_present(async_listings_service, method):
26+
assert hasattr(async_listings_service, method)

0 commit comments

Comments
 (0)