Skip to content

Commit 4ffe267

Browse files
author
Robert Segal
committed
Add additional mixin tests for activatable resource
1 parent 3524b0b commit 4ffe267

File tree

2 files changed

+164
-4
lines changed

2 files changed

+164
-4
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ per-file-ignores =
4141
tests/http/test_service.py: WPS204 WPS202
4242
tests/http/test_mixins.py: WPS204 WPS202
4343
tests/resources/catalog/test_products.py: WPS202 WPS210
44+
tests/resources/catalog/test_mixins.py: WPS118 WPS202 WPS204
4445

4546
tests/*:
4647
# Allow magic strings.

tests/resources/catalog/test_mixins.py

Lines changed: 163 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import pytest
33
import respx
44

5+
from mpt_api_client.resources.catalog.pricing_policy_attachments import (
6+
AsyncPricingPolicyAttachmentsService,
7+
PricingPolicyAttachment,
8+
PricingPolicyAttachmentsService,
9+
)
510
from mpt_api_client.resources.catalog.products import AsyncProductsService, Product, ProductsService
611

712

@@ -15,6 +20,20 @@ def async_product_service(async_http_client):
1520
return AsyncProductsService(http_client=async_http_client)
1621

1722

23+
@pytest.fixture
24+
def pricing_policy_attachments_service(http_client):
25+
return PricingPolicyAttachmentsService(
26+
http_client=http_client, endpoint_params={"pricing_policy_id": "PRP-0000-0001"}
27+
)
28+
29+
30+
@pytest.fixture
31+
def async_pricing_policy_attachments_service(async_http_client):
32+
return AsyncPricingPolicyAttachmentsService(
33+
http_client=async_http_client, endpoint_params={"pricing_policy_id": "PRP-0000-0001"}
34+
)
35+
36+
1837
@pytest.mark.parametrize(
1938
("action", "input_status"),
2039
[
@@ -31,7 +50,7 @@ def test_custom_resource_actions(product_service, action, input_status):
3150
f"https://api.example.com/public/v1/catalog/products/PRD-123/{action}"
3251
).mock(
3352
return_value=httpx.Response(
34-
status_code=200,
53+
status_code=httpx.codes.OK,
3554
headers={"content-type": "application/json"},
3655
json=response_expected_data,
3756
)
@@ -62,7 +81,7 @@ def test_custom_resource_actions_no_data(product_service, action, input_status):
6281
f"https://api.example.com/public/v1/catalog/products/PRD-123/{action}"
6382
).mock(
6483
return_value=httpx.Response(
65-
status_code=200,
84+
status_code=httpx.codes.OK,
6685
headers={"content-type": "application/json"},
6786
json=response_expected_data,
6887
)
@@ -93,7 +112,7 @@ async def test_async_custom_resource_actions(async_product_service, action, inpu
93112
f"https://api.example.com/public/v1/catalog/products/PRD-123/{action}"
94113
).mock(
95114
return_value=httpx.Response(
96-
status_code=200,
115+
status_code=httpx.codes.OK,
97116
headers={"content-type": "application/json"},
98117
json=response_expected_data,
99118
)
@@ -124,7 +143,7 @@ async def test_async_custom_resource_actions_no_data(async_product_service, acti
124143
f"https://api.example.com/public/v1/catalog/products/PRD-123/{action}"
125144
).mock(
126145
return_value=httpx.Response(
127-
status_code=200,
146+
status_code=httpx.codes.OK,
128147
headers={"content-type": "application/json"},
129148
json=response_expected_data,
130149
)
@@ -137,3 +156,143 @@ async def test_async_custom_resource_actions_no_data(async_product_service, acti
137156
assert request.content == request_expected_content
138157
assert order.to_dict() == response_expected_data
139158
assert isinstance(order, Product)
159+
160+
161+
@pytest.mark.parametrize(
162+
("action", "input_status"),
163+
[
164+
("activate", {"id": "PRP-0000-0000-0001", "status": "update"}),
165+
("deactivate", {"id": "PRP-0000-0000-0001", "status": "update"}),
166+
],
167+
)
168+
def test_custom_resource_activatable_actions(
169+
pricing_policy_attachments_service, action, input_status
170+
):
171+
request_expected_content = b'{"id":"PRP-0000-0000-0001","status":"update"}'
172+
response_expected_data = {"id": "PRP-0000-0000-0001", "status": "new_status"}
173+
with respx.mock:
174+
mock_route = respx.post(
175+
f"https://api.example.com/public/v1/catalog/pricing-policies/PRP-0000-0001"
176+
f"/attachments/PRP-0000-0000-0001/{action}"
177+
).mock(
178+
return_value=httpx.Response(
179+
status_code=httpx.codes.OK,
180+
headers={"content-type": "application/json"},
181+
json=response_expected_data,
182+
)
183+
)
184+
attachment = getattr(pricing_policy_attachments_service, action)(
185+
"PRP-0000-0000-0001", input_status
186+
)
187+
188+
assert mock_route.call_count == 1
189+
request = mock_route.calls[0].request
190+
191+
assert request.content == request_expected_content
192+
assert attachment.to_dict() == response_expected_data
193+
assert isinstance(attachment, PricingPolicyAttachment)
194+
195+
196+
@pytest.mark.parametrize(
197+
("action", "input_status"),
198+
[
199+
("activate", None),
200+
("deactivate", None),
201+
],
202+
)
203+
def test_custom_resource_activatable_actions_no_data(
204+
pricing_policy_attachments_service, action, input_status
205+
):
206+
request_expected_content = b""
207+
response_expected_data = {"id": "PRP-0000-0000-0001", "status": "new_status"}
208+
with respx.mock:
209+
mock_route = respx.post(
210+
f"https://api.example.com/public/v1/catalog/pricing-policies/PRP-0000-0001"
211+
f"/attachments/PRP-0000-0000-0001/{action}"
212+
).mock(
213+
return_value=httpx.Response(
214+
status_code=httpx.codes.OK,
215+
headers={"content-type": "application/json"},
216+
json=response_expected_data,
217+
)
218+
)
219+
attachment = getattr(pricing_policy_attachments_service, action)(
220+
"PRP-0000-0000-0001", input_status
221+
)
222+
223+
assert mock_route.call_count == 1
224+
request = mock_route.calls[0].request
225+
226+
assert request.content == request_expected_content
227+
assert attachment.to_dict() == response_expected_data
228+
assert isinstance(attachment, PricingPolicyAttachment)
229+
230+
231+
@pytest.mark.parametrize(
232+
("action", "input_status"),
233+
[
234+
("activate", {"id": "PRP-0000-0000-0001", "status": "update"}),
235+
("deactivate", {"id": "PRP-0000-0000-0001", "status": "update"}),
236+
],
237+
)
238+
async def test_async_custom_resource_activatable_actions(
239+
async_pricing_policy_attachments_service, action, input_status
240+
):
241+
request_expected_content = b'{"id":"PRP-0000-0000-0001","status":"update"}'
242+
response_expected_data = {"id": "PRP-0000-0000-0001", "status": "new_status"}
243+
with respx.mock:
244+
mock_route = respx.post(
245+
f"https://api.example.com/public/v1/catalog/pricing-policies/PRP-0000-0001"
246+
f"/attachments/PRP-0000-0000-0001/{action}"
247+
).mock(
248+
return_value=httpx.Response(
249+
status_code=httpx.codes.OK,
250+
headers={"content-type": "application/json"},
251+
json=response_expected_data,
252+
)
253+
)
254+
attachment = await getattr(async_pricing_policy_attachments_service, action)(
255+
"PRP-0000-0000-0001", input_status
256+
)
257+
258+
assert mock_route.call_count == 1
259+
request = mock_route.calls[0].request
260+
261+
assert request.content == request_expected_content
262+
assert attachment.to_dict() == response_expected_data
263+
assert isinstance(attachment, PricingPolicyAttachment)
264+
265+
266+
@pytest.mark.parametrize(
267+
("action", "input_status"),
268+
[
269+
("activate", None),
270+
("deactivate", None),
271+
],
272+
)
273+
async def test_async_custom_resource_activatable_actions_no_data(
274+
async_pricing_policy_attachments_service, action, input_status
275+
):
276+
request_expected_content = b""
277+
response_expected_data = {"id": "PRP-0000-0000-0001", "status": "new_status"}
278+
with respx.mock:
279+
mock_route = respx.post(
280+
f"https://api.example.com/public/v1/catalog/pricing-policies/PRP-0000-0001"
281+
f"/attachments/PRP-0000-0000-0001/{action}"
282+
).mock(
283+
return_value=httpx.Response(
284+
status_code=httpx.codes.OK,
285+
headers={"content-type": "application/json"},
286+
json=response_expected_data,
287+
)
288+
)
289+
attachment = await getattr(async_pricing_policy_attachments_service, action)(
290+
"PRP-0000-0000-0001", input_status
291+
)
292+
293+
assert mock_route.call_count == 1
294+
request = mock_route.calls[0].request
295+
296+
assert request.content == request_expected_content
297+
assert attachment.to_dict() == response_expected_data
298+
assert isinstance(attachment, PricingPolicyAttachment)

0 commit comments

Comments
 (0)