Skip to content

Commit 3524b0b

Browse files
authored
[MPT-13332] Add catalog pricing policy attachments endpoints (#47)
Add catalog pricing policy attachments endpoints https://softwareone.atlassian.net/browse/MPT-13332x
2 parents 2fab99c + e10df10 commit 3524b0b

File tree

5 files changed

+198
-0
lines changed

5 files changed

+198
-0
lines changed

mpt_api_client/resources/catalog/mixins.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,57 @@ async def unpublish(self, resource_id: str, resource_data: ResourceData | None =
7373
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
7474
resource_id, "POST", "unpublish", json=resource_data
7575
)
76+
77+
78+
class ActivatableMixin[Model]:
79+
"""Activatable mixin adds the ability to activate and deactivate."""
80+
81+
def activate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
82+
"""Update state to Active.
83+
84+
Args:
85+
resource_id: Resource ID
86+
resource_data: Resource data will be updated
87+
"""
88+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
89+
resource_id, "POST", "activate", json=resource_data
90+
)
91+
92+
def deactivate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
93+
"""Update state to Inactive.
94+
95+
Args:
96+
resource_id: Resource ID
97+
resource_data: Resource data will be updated
98+
"""
99+
return self._resource_action( # type: ignore[attr-defined, no-any-return]
100+
resource_id, "POST", "deactivate", json=resource_data
101+
)
102+
103+
104+
class AsyncActivatableMixin[Model]:
105+
"""Activatable mixin adds the ability to activate and deactivate."""
106+
107+
async def activate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model:
108+
"""Update state to Active.
109+
110+
Args:
111+
resource_id: Resource ID
112+
resource_data: Resource data will be updated
113+
"""
114+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
115+
resource_id, "POST", "activate", json=resource_data
116+
)
117+
118+
async def deactivate(
119+
self, resource_id: str, resource_data: ResourceData | None = None
120+
) -> Model:
121+
"""Update state to Inactive.
122+
123+
Args:
124+
resource_id: Resource ID
125+
resource_data: Resource data will be updated
126+
"""
127+
return await self._resource_action( # type: ignore[attr-defined, no-any-return]
128+
resource_id, "POST", "deactivate", json=resource_data
129+
)

mpt_api_client/resources/catalog/pricing_policies.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
Service,
88
)
99
from mpt_api_client.models import Model, ResourceData
10+
from mpt_api_client.resources.catalog.pricing_policy_attachments import (
11+
AsyncPricingPolicyAttachmentsService,
12+
PricingPolicyAttachmentsService,
13+
)
1014

1115

1216
class PricingPolicy(Model):
@@ -29,6 +33,13 @@ class PricingPoliciesService( # noqa: WPS215
2933
):
3034
"""Pricing policies service."""
3135

36+
def attachments(self, pricing_policy_id: str) -> PricingPolicyAttachmentsService:
37+
"""Return pricing policy attachments service."""
38+
return PricingPolicyAttachmentsService(
39+
http_client=self.http_client,
40+
endpoint_params={"pricing_policy_id": pricing_policy_id},
41+
)
42+
3243
def activate(self, resource_id: str, resource_data: ResourceData) -> PricingPolicy:
3344
"""Activate pricing policy.
3445
@@ -62,6 +73,13 @@ class AsyncPricingPoliciesService(
6273
):
6374
"""Async pricing policies service."""
6475

76+
def attachments(self, pricing_policy_id: str) -> AsyncPricingPolicyAttachmentsService:
77+
"""Return pricing policy attachments service."""
78+
return AsyncPricingPolicyAttachmentsService(
79+
http_client=self.http_client,
80+
endpoint_params={"pricing_policy_id": pricing_policy_id},
81+
)
82+
6583
async def activate(self, resource_id: str, resource_data: ResourceData) -> PricingPolicy:
6684
"""Activate pricing policy.
6785
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from mpt_api_client.http import AsyncService, DeleteMixin, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncDeleteMixin,
4+
AsyncFileOperationsMixin,
5+
AsyncUpdateMixin,
6+
FileOperationsMixin,
7+
UpdateMixin,
8+
)
9+
from mpt_api_client.models import Model
10+
from mpt_api_client.resources.catalog.mixins import ActivatableMixin, AsyncActivatableMixin
11+
12+
13+
class PricingPolicyAttachment(Model):
14+
"""Pricing Policy Attachment resource."""
15+
16+
17+
class PricingPolicyAttachmentsServiceConfig:
18+
"""Pricing Policy Attachments service configuration."""
19+
20+
_endpoint = "/public/v1/catalog/pricing-policies/{pricing_policy_id}/attachments"
21+
_model_class = PricingPolicyAttachment
22+
_collection_key = "data"
23+
24+
25+
class PricingPolicyAttachmentsService(
26+
FileOperationsMixin[PricingPolicyAttachment],
27+
DeleteMixin,
28+
UpdateMixin[PricingPolicyAttachment],
29+
ActivatableMixin[PricingPolicyAttachment],
30+
Service[PricingPolicyAttachment],
31+
PricingPolicyAttachmentsServiceConfig,
32+
):
33+
"""Pricing Policy Attachments service."""
34+
35+
36+
class AsyncPricingPolicyAttachmentsService(
37+
AsyncFileOperationsMixin[PricingPolicyAttachment],
38+
AsyncDeleteMixin,
39+
AsyncUpdateMixin[PricingPolicyAttachment],
40+
AsyncActivatableMixin[PricingPolicyAttachment],
41+
AsyncService[PricingPolicyAttachment],
42+
PricingPolicyAttachmentsServiceConfig,
43+
):
44+
"""Pricing Policy Attachments service."""

tests/resources/catalog/test_pricing_policies.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
AsyncPricingPoliciesService,
77
PricingPoliciesService,
88
)
9+
from mpt_api_client.resources.catalog.pricing_policy_attachments import (
10+
AsyncPricingPolicyAttachmentsService,
11+
PricingPolicyAttachmentsService,
12+
)
913

1014

1115
@pytest.fixture
@@ -108,3 +112,31 @@ async def test_async_disable(async_pricing_policies_service):
108112
)
109113

110114
assert pricing_policy_disabled.to_dict() == pricing_policy_expected
115+
116+
117+
@pytest.mark.parametrize(
118+
("service_method", "expected_service_class"),
119+
[
120+
("attachments", PricingPolicyAttachmentsService),
121+
],
122+
)
123+
def test_property_services(pricing_policies_service, service_method, expected_service_class):
124+
property_service = getattr(pricing_policies_service, service_method)("PRP-0000-0001")
125+
126+
assert isinstance(property_service, expected_service_class)
127+
assert property_service.endpoint_params == {"pricing_policy_id": "PRP-0000-0001"}
128+
129+
130+
@pytest.mark.parametrize(
131+
("service_method", "expected_service_class"),
132+
[
133+
("attachments", AsyncPricingPolicyAttachmentsService),
134+
],
135+
)
136+
def test_async_property_services(
137+
async_pricing_policies_service, service_method, expected_service_class
138+
):
139+
property_service = getattr(async_pricing_policies_service, service_method)("PRP-0000-0001")
140+
141+
assert isinstance(property_service, expected_service_class)
142+
assert property_service.endpoint_params == {"pricing_policy_id": "PRP-0000-0001"}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.catalog.pricing_policy_attachments import (
4+
AsyncPricingPolicyAttachmentsService,
5+
PricingPolicyAttachmentsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def pricing_policy_attachments_service(http_client) -> PricingPolicyAttachmentsService:
11+
return PricingPolicyAttachmentsService(
12+
http_client=http_client, endpoint_params={"pricing_policy_id": "PRP-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_pricing_policy_attachments_service(
18+
async_http_client,
19+
) -> AsyncPricingPolicyAttachmentsService:
20+
return AsyncPricingPolicyAttachmentsService(
21+
http_client=async_http_client, endpoint_params={"pricing_policy_id": "PRP-0000-0001"}
22+
)
23+
24+
25+
def test_endpoint(pricing_policy_attachments_service) -> None:
26+
assert (
27+
pricing_policy_attachments_service.endpoint
28+
== "/public/v1/catalog/pricing-policies/PRP-0000-0001/attachments"
29+
)
30+
31+
32+
def test_async_endpoint(async_pricing_policy_attachments_service) -> None:
33+
assert (
34+
async_pricing_policy_attachments_service.endpoint
35+
== "/public/v1/catalog/pricing-policies/PRP-0000-0001/attachments"
36+
)
37+
38+
39+
@pytest.mark.parametrize(
40+
"method", ["get", "create", "delete", "update", "download", "activate", "deactivate"]
41+
)
42+
def test_methods_present(pricing_policy_attachments_service, method: str) -> None:
43+
assert hasattr(pricing_policy_attachments_service, method)
44+
45+
46+
@pytest.mark.parametrize(
47+
"method", ["get", "create", "delete", "update", "download", "activate", "deactivate"]
48+
)
49+
def test_async_methods_present(async_pricing_policy_attachments_service, method: str) -> None:
50+
assert hasattr(async_pricing_policy_attachments_service, method)

0 commit comments

Comments
 (0)