Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions mpt_api_client/resources/catalog/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
AsyncPriceListsService,
PriceListsService,
)
from mpt_api_client.resources.catalog.pricing_policies import (
AsyncPricingPoliciesService,
PricingPoliciesService,
)
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService
from mpt_api_client.resources.catalog.units_of_measure import (
AsyncUnitsOfMeasureService,
Expand Down Expand Up @@ -37,6 +41,11 @@ def price_lists(self) -> PriceListsService:
"""Price Lists service."""
return PriceListsService(http_client=self.http_client)

@property
def pricing_policies(self) -> PricingPoliciesService:
"""Pricing policies service."""
return PricingPoliciesService(http_client=self.http_client)

@property
def products(self) -> ProductsService:
"""Products service."""
Expand Down Expand Up @@ -74,6 +83,11 @@ def price_lists(self) -> AsyncPriceListsService:
"""Price Lists service."""
return AsyncPriceListsService(http_client=self.http_client)

@property
def pricing_policies(self) -> AsyncPricingPoliciesService:
"""Pricing policies service."""
return AsyncPricingPoliciesService(http_client=self.http_client)

@property
def products(self) -> AsyncProductsService:
"""Products service."""
Expand Down
87 changes: 87 additions & 0 deletions mpt_api_client/resources/catalog/pricing_policies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from mpt_api_client.http import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncService,
CreateMixin,
DeleteMixin,
Service,
)
from mpt_api_client.models import Model, ResourceData


class PricingPolicy(Model):
"""Pricing policy resource."""


class PricingPoliciesServiceConfig:
"""Pricing policy service config."""

_endpoint = "/public/v1/catalog/pricing-policies"
_model_class = PricingPolicy
_collection_key = "data"


class PricingPoliciesService( # noqa: WPS215
CreateMixin[PricingPolicy],
DeleteMixin,
Service[PricingPolicy],
PricingPoliciesServiceConfig,
):
"""Pricing policies service."""

def activate(self, resource_id: str, resource_data: ResourceData) -> PricingPolicy:
"""Activate pricing policy.

Args:
resource_id: Pricing policy resource ID
resource_data: Pricing policy resource data

Returns:
Activated pricing policy.
"""
return self._resource_action(resource_id, "POST", "activate", json=resource_data)

def disable(self, resource_id: str, resource_data: ResourceData) -> PricingPolicy:
"""Disable pricing policy.

Args:
resource_id: Pricing policy resource ID
resource_data: Pricing policy resource data

Returns:
Disabled pricing policy.
"""
return self._resource_action(resource_id, "POST", "disable", json=resource_data)


class AsyncPricingPoliciesService(
AsyncCreateMixin[PricingPolicy],
AsyncDeleteMixin,
AsyncService[PricingPolicy],
PricingPoliciesServiceConfig,
):
"""Async pricing policies service."""

async def activate(self, resource_id: str, resource_data: ResourceData) -> PricingPolicy:
"""Activate pricing policy.

Args:
resource_id: Pricing policy resource ID
resource_data: Pricing policy resource data

Returns:
Activated pricing policy.
"""
return await self._resource_action(resource_id, "POST", "activate", json=resource_data)

async def disable(self, resource_id: str, resource_data: ResourceData) -> PricingPolicy:
"""Disable pricing policy.

Args:
resource_id: Pricing policy resource ID
resource_data: Pricing policy resource data

Returns:
Disabled pricing policy.
"""
return await self._resource_action(resource_id, "POST", "disable", json=resource_data)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extend-ignore =


per-file-ignores =
mpt_api_client/resources/catalog/*.py: WPS110 WPS215
mpt_api_client/resources/catalog/*.py: WPS110 WPS215 WPS214
mpt_api_client/resources/commerce/*.py: WPS215
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
Expand Down
6 changes: 6 additions & 0 deletions tests/resources/catalog/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
AsyncPriceListsService,
PriceListsService,
)
from mpt_api_client.resources.catalog.pricing_policies import (
AsyncPricingPoliciesService,
PricingPoliciesService,
)
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService
from mpt_api_client.resources.catalog.units_of_measure import (
AsyncUnitsOfMeasureService,
Expand All @@ -34,6 +38,7 @@ def async_catalog(async_http_client):
("authorizations", AuthorizationsService),
("listings", ListingsService),
("price_lists", PriceListsService),
("pricing_policies", PricingPoliciesService),
("products", ProductsService),
("units_of_measure", UnitsOfMeasureService),
("items", ItemsService),
Expand All @@ -53,6 +58,7 @@ def test_catalog_properties(catalog, property_name, expected_service_class):
("authorizations", AsyncAuthorizationsService),
("listings", AsyncListingsService),
("price_lists", AsyncPriceListsService),
("pricing_policies", AsyncPricingPoliciesService),
("products", AsyncProductsService),
("units_of_measure", AsyncUnitsOfMeasureService),
("items", AsyncItemsService),
Expand Down
110 changes: 110 additions & 0 deletions tests/resources/catalog/test_pricing_policies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import httpx
import pytest
import respx

from mpt_api_client.resources.catalog.pricing_policies import (
AsyncPricingPoliciesService,
PricingPoliciesService,
)


@pytest.fixture
def pricing_policies_service(http_client):
return PricingPoliciesService(http_client=http_client)


@pytest.fixture
def async_pricing_policies_service(async_http_client):
return AsyncPricingPoliciesService(http_client=async_http_client)


def test_activate(pricing_policies_service):
pricing_policy_expected = {
"id": "PRP-0000-0001",
"status": "Active",
"name": "Active Pricing Policy",
}
with respx.mock:
respx.post(
"https://api.example.com/public/v1/catalog/pricing-policies/PRP-0000-0001/activate"
).mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
json=pricing_policy_expected,
)
)

pricing_policy_activated = pricing_policies_service.activate(
"PRP-0000-0001", {"name": "Active Pricing Policy"}
)

assert pricing_policy_activated.to_dict() == pricing_policy_expected


async def test_async_activate(async_pricing_policies_service):
pricing_policy_expected = {
"id": "PRP-0000-0001",
"status": "Active",
"name": "Active Pricing Policy",
}
with respx.mock:
respx.post(
"https://api.example.com/public/v1/catalog/pricing-policies/PRP-0000-0001/activate"
).mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
json=pricing_policy_expected,
)
)

pricing_policy_activated = await async_pricing_policies_service.activate(
"PRP-0000-0001", {"name": "Active Pricing Policy"}
)

assert pricing_policy_activated.to_dict() == pricing_policy_expected


def test_disable(pricing_policies_service):
pricing_policy_expected = {
"id": "PRP-0000-0001",
"status": "Inactive",
"name": "Inactive Pricing Policy",
}
with respx.mock:
respx.post(
"https://api.example.com/public/v1/catalog/pricing-policies/PRP-0000-0001/disable"
).mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
json=pricing_policy_expected,
)
)

pricing_policy_disabled = pricing_policies_service.disable(
"PRP-0000-0001", {"name": "Inactive Pricing Policy"}
)

assert pricing_policy_disabled.to_dict() == pricing_policy_expected


async def test_async_disable(async_pricing_policies_service):
pricing_policy_expected = {
"id": "PRP-0000-0001",
"status": "Inactive",
"name": "Inactive Pricing Policy",
}
with respx.mock:
respx.post(
"https://api.example.com/public/v1/catalog/pricing-policies/PRP-0000-0001/disable"
).mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
json=pricing_policy_expected,
)
)

pricing_policy_disabled = await async_pricing_policies_service.disable(
"PRP-0000-0001", {"name": "Inactive Pricing Policy"}
)

assert pricing_policy_disabled.to_dict() == pricing_policy_expected