From b625283cd1d570d327292269178f8d707c8453a5 Mon Sep 17 00:00:00 2001 From: Robert Segal Date: Tue, 23 Sep 2025 07:10:22 -0600 Subject: [PATCH] Added catalog listings endpoints --- mpt_api_client/resources/catalog/catalog.py | 23 +++++------ mpt_api_client/resources/catalog/listings.py | 42 ++++++++++++++++++++ setup.cfg | 15 +------ tests/resources/catalog/test_catalog.py | 3 ++ tests/resources/catalog/test_listings.py | 26 ++++++++++++ 5 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 mpt_api_client/resources/catalog/listings.py create mode 100644 tests/resources/catalog/test_listings.py diff --git a/mpt_api_client/resources/catalog/catalog.py b/mpt_api_client/resources/catalog/catalog.py index f7d597d7..4bfe366c 100644 --- a/mpt_api_client/resources/catalog/catalog.py +++ b/mpt_api_client/resources/catalog/catalog.py @@ -4,10 +4,7 @@ AuthorizationsService, ) from mpt_api_client.resources.catalog.items import AsyncItemsService, ItemsService -from mpt_api_client.resources.catalog.price_list_items import ( - AsyncPriceListItemsService, - PriceListItemsService, -) +from mpt_api_client.resources.catalog.listings import AsyncListingsService, ListingsService from mpt_api_client.resources.catalog.price_lists import ( AsyncPriceListsService, PriceListsService, @@ -26,11 +23,10 @@ def authorizations(self) -> AuthorizationsService: """Authorizations service.""" return AuthorizationsService(http_client=self.http_client) - def price_list_items(self, price_list_id: str) -> PriceListItemsService: - """Price List Items service.""" - return PriceListItemsService( - http_client=self.http_client, endpoint_params={"price_list_id": price_list_id} - ) + @property + def listings(self) -> ListingsService: + """Listings service.""" + return ListingsService(http_client=self.http_client) @property def price_lists(self) -> PriceListsService: @@ -59,11 +55,10 @@ def authorizations(self) -> AsyncAuthorizationsService: """Authorizations service.""" return AsyncAuthorizationsService(http_client=self.http_client) - def price_list_items(self, price_list_id: str) -> AsyncPriceListItemsService: - """Price List Items service.""" - return AsyncPriceListItemsService( - http_client=self.http_client, endpoint_params={"price_list_id": price_list_id} - ) + @property + def listings(self) -> AsyncListingsService: + """Listings service.""" + return AsyncListingsService(http_client=self.http_client) @property def price_lists(self) -> AsyncPriceListsService: diff --git a/mpt_api_client/resources/catalog/listings.py b/mpt_api_client/resources/catalog/listings.py new file mode 100644 index 00000000..dafbcfa5 --- /dev/null +++ b/mpt_api_client/resources/catalog/listings.py @@ -0,0 +1,42 @@ +from mpt_api_client.http import AsyncService, Service +from mpt_api_client.http.mixins import ( + AsyncCreateMixin, + AsyncDeleteMixin, + AsyncUpdateMixin, + CreateMixin, + DeleteMixin, + UpdateMixin, +) +from mpt_api_client.models import Model + + +class Listing(Model): + """Listing resource.""" + + +class ListingsServiceConfig: + """Listings service configuration.""" + + _endpoint = "/public/v1/catalog/listings" + _model_class = Listing + _collection_key = "data" + + +class ListingsService( + CreateMixin[Listing], + DeleteMixin, + UpdateMixin[Listing], + Service[Listing], + ListingsServiceConfig, +): + """Listings service.""" + + +class AsyncListingsService( + AsyncCreateMixin[Listing], + AsyncDeleteMixin, + AsyncUpdateMixin[Listing], + AsyncService[Listing], + ListingsServiceConfig, +): + """Listings service.""" diff --git a/setup.cfg b/setup.cfg index b4d1ad07..a3f34980 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,21 +32,10 @@ extend-ignore = per-file-ignores = + mpt_api_client/resources/catalog/*.py: WPS110 WPS215 + mpt_api_client/resources/commerce/*.py: WPS215 mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214 - mpt_api_client/resources/catalog/authorizations.py: WPS215 mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215 - mpt_api_client/resources/catalog/items.py: WPS215 - mpt_api_client/resources/catalog/price_lists.py: WPS215 WPS110 - mpt_api_client/resources/catalog/price_list_items.py: WPS215 - mpt_api_client/resources/catalog/products_item_groups.py: WPS215 - mpt_api_client/resources/catalog/products_parameter_groups.py: WPS215 - mpt_api_client/resources/catalog/products_parameters.py: WPS215 - mpt_api_client/resources/catalog/products_media.py: WPS215 - mpt_api_client/resources/catalog/products_documents.py: WPS215 - mpt_api_client/resources/catalog/products_templates.py: WPS215 - mpt_api_client/resources/catalog/product_terms.py: WPS215 - mpt_api_client/resources/catalog/product_term_variants.py: WPS215 - mpt_api_client/resources/commerce/agreements_attachments.py: WPS215 mpt_api_client/http/mixins.py: WPS202 tests/http/test_async_service.py: WPS204 WPS202 tests/http/test_service.py: WPS204 WPS202 diff --git a/tests/resources/catalog/test_catalog.py b/tests/resources/catalog/test_catalog.py index cc7526b4..ba197d3c 100644 --- a/tests/resources/catalog/test_catalog.py +++ b/tests/resources/catalog/test_catalog.py @@ -6,6 +6,7 @@ ) from mpt_api_client.resources.catalog.catalog import AsyncCatalog, Catalog from mpt_api_client.resources.catalog.items import AsyncItemsService, ItemsService +from mpt_api_client.resources.catalog.listings import AsyncListingsService, ListingsService from mpt_api_client.resources.catalog.price_lists import ( AsyncPriceListsService, PriceListsService, @@ -27,6 +28,7 @@ def async_catalog(async_http_client): ("property_name", "expected_service_class"), [ ("authorizations", AuthorizationsService), + ("listings", ListingsService), ("price_lists", PriceListsService), ("products", ProductsService), ("items", ItemsService), @@ -44,6 +46,7 @@ def test_catalog_properties(catalog, property_name, expected_service_class): ("property_name", "expected_service_class"), [ ("authorizations", AsyncAuthorizationsService), + ("listings", AsyncListingsService), ("price_lists", AsyncPriceListsService), ("products", AsyncProductsService), ("items", AsyncItemsService), diff --git a/tests/resources/catalog/test_listings.py b/tests/resources/catalog/test_listings.py new file mode 100644 index 00000000..7c0d524c --- /dev/null +++ b/tests/resources/catalog/test_listings.py @@ -0,0 +1,26 @@ +import pytest + +from mpt_api_client.resources.catalog.listings import ( + AsyncListingsService, + ListingsService, +) + + +@pytest.fixture +def listings_service(http_client): + return ListingsService(http_client=http_client) + + +@pytest.fixture +def async_listings_service(async_http_client): + return AsyncListingsService(http_client=async_http_client) + + +@pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) +def test_mixins_present(listings_service, method): + assert hasattr(listings_service, method) + + +@pytest.mark.parametrize("method", ["get", "create", "update", "delete"]) +def test_async_mixins_present(async_listings_service, method): + assert hasattr(async_listings_service, method)