Skip to content

Commit 5a5e2b4

Browse files
committed
MPT-14900 E2E tests for catalog pricing-policies
1 parent 8994da6 commit 5a5e2b4

23 files changed

Lines changed: 206 additions & 60 deletions

mpt_api_client/resources/catalog/pricing_policy_attachments.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from mpt_api_client.http import AsyncService, Service
22
from mpt_api_client.http.mixins import (
33
AsyncCollectionMixin,
4-
AsyncFilesOperationsMixin,
4+
AsyncDownloadFileMixin,
55
AsyncModifiableResourceMixin,
66
CollectionMixin,
7-
FilesOperationsMixin,
7+
DownloadFileMixin,
88
ModifiableResourceMixin,
99
)
1010
from mpt_api_client.models import Model
11-
from mpt_api_client.resources.catalog.mixins import ActivatableMixin, AsyncActivatableMixin
11+
from mpt_api_client.resources.catalog.mixins import (
12+
AsyncCreateFileMixin,
13+
CreateFileMixin,
14+
)
1215

1316

1417
class PricingPolicyAttachment(Model):
@@ -21,11 +24,13 @@ class PricingPolicyAttachmentsServiceConfig:
2124
_endpoint = "/public/v1/catalog/pricing-policies/{pricing_policy_id}/attachments"
2225
_model_class = PricingPolicyAttachment
2326
_collection_key = "data"
27+
_upload_file_key = "file"
28+
_upload_data_key = "attachment"
2429

2530

2631
class PricingPolicyAttachmentsService(
27-
FilesOperationsMixin[PricingPolicyAttachment],
28-
ActivatableMixin[PricingPolicyAttachment],
32+
CreateFileMixin[PricingPolicyAttachment],
33+
DownloadFileMixin[PricingPolicyAttachment],
2934
ModifiableResourceMixin[PricingPolicyAttachment],
3035
CollectionMixin[PricingPolicyAttachment],
3136
Service[PricingPolicyAttachment],
@@ -35,8 +40,8 @@ class PricingPolicyAttachmentsService(
3540

3641

3742
class AsyncPricingPolicyAttachmentsService(
38-
AsyncFilesOperationsMixin[PricingPolicyAttachment],
39-
AsyncActivatableMixin[PricingPolicyAttachment],
43+
AsyncCreateFileMixin[PricingPolicyAttachment],
44+
AsyncDownloadFileMixin[PricingPolicyAttachment],
4045
AsyncModifiableResourceMixin[PricingPolicyAttachment],
4146
AsyncCollectionMixin[PricingPolicyAttachment],
4247
AsyncService[PricingPolicyAttachment],

tests/e2e/catalog/items/test_async_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@pytest.fixture
10-
async def async_created_item(logger, async_mpt_vendor, item_data):
10+
async def async_created_item(async_mpt_vendor, item_data):
1111
service = async_mpt_vendor.catalog.items
1212
item = await service.create(item_data)
1313
yield item

tests/e2e/catalog/items/test_sync_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@pytest.fixture
10-
def created_item(logger, mpt_vendor, item_data):
10+
def created_item(mpt_vendor, item_data):
1111
service = mpt_vendor.catalog.items
1212
item = service.create(item_data)
1313
yield item

tests/e2e/catalog/pricing_policies/attachments/__init__.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
5+
6+
@pytest.fixture
7+
def attachment_id(created_attachment):
8+
return created_attachment.id
9+
10+
11+
@pytest.fixture
12+
def attachment_data():
13+
return {
14+
"name": "e2e test attachment - please delete",
15+
"description": "E2E test attachment for automated testing",
16+
}
17+
18+
19+
@pytest.fixture
20+
def attachment_service(mpt_ops, pricing_policy_id):
21+
return mpt_ops.catalog.pricing_policies.attachments(pricing_policy_id)
22+
23+
24+
@pytest.fixture
25+
def created_attachment(attachment_service, attachment_data, pdf_fd):
26+
attachment = attachment_service.create(attachment_data, file=pdf_fd)
27+
yield attachment
28+
try:
29+
attachment_service.delete(attachment.id)
30+
except MPTAPIError as error:
31+
print(f"TEARDOWN - Unable to delete attachment {attachment.id}: {error.title}")
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
def async_attachment_service(async_mpt_ops, pricing_policy_id):
11+
return async_mpt_ops.catalog.pricing_policies.attachments(pricing_policy_id)
12+
13+
14+
@pytest.fixture
15+
async def created_attachment_async(async_attachment_service, attachment_data, pdf_fd):
16+
attachment = await async_attachment_service.create(attachment_data, file=pdf_fd)
17+
yield attachment
18+
try:
19+
await async_attachment_service.delete(attachment.id)
20+
except MPTAPIError as error:
21+
print(f"TEARDOWN - Unable to delete attachment {attachment.id}: {error.title}")
22+
23+
24+
def test_create_attachment_async(created_attachment_async, attachment_data):
25+
assert created_attachment_async.name == attachment_data["name"]
26+
assert created_attachment_async.description == attachment_data["description"]
27+
28+
29+
async def test_update_attachment_async(async_attachment_service, created_attachment_async):
30+
update_data = {"name": "Updated e2e test attachment - please delete"}
31+
attachment = await async_attachment_service.update(created_attachment_async.id, update_data)
32+
assert attachment.name == update_data["name"]
33+
34+
35+
async def test_get_attachment_async(async_attachment_service, attachment_id):
36+
attachment = await async_attachment_service.get(attachment_id)
37+
assert attachment.id == attachment_id
38+
39+
40+
async def test_download_attachment_async(async_attachment_service, attachment_id):
41+
file_response = await async_attachment_service.download(attachment_id)
42+
assert file_response.file_contents is not None
43+
assert file_response.filename == "empty.pdf"
44+
45+
46+
async def test_iterate_attachments_async(async_attachment_service, created_attachment_async):
47+
attachments = [att async for att in async_attachment_service.iterate()]
48+
assert any(att.id == created_attachment_async.id for att in attachments)
49+
50+
51+
async def test_filter_attachments_async(async_attachment_service, created_attachment_async):
52+
filtered_service = async_attachment_service.filter(RQLQuery(id=created_attachment_async.id))
53+
attachments = [att async for att in filtered_service.iterate()]
54+
assert len(attachments) == 1
55+
assert attachments[0].id == created_attachment_async.id
56+
57+
58+
async def test_not_found_async(async_attachment_service):
59+
with pytest.raises(MPTAPIError):
60+
await async_attachment_service.get("ATT-000-000-000")
61+
62+
63+
async def test_delete_attachment_async(async_attachment_service, created_attachment_async):
64+
await async_attachment_service.delete(created_attachment_async.id)
65+
with pytest.raises(MPTAPIError):
66+
await async_attachment_service.get(created_attachment_async.id)
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.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
def test_create_attachment(created_attachment, attachment_data):
10+
assert created_attachment.name == attachment_data["name"]
11+
assert created_attachment.description == attachment_data["description"]
12+
13+
14+
def test_update_attachment(attachment_service, created_attachment):
15+
update_data = {"name": "Updated e2e test attachment - please delete"}
16+
attachment = attachment_service.update(created_attachment.id, update_data)
17+
assert attachment.name == update_data["name"]
18+
19+
20+
def test_get_attachment(attachment_service, attachment_id):
21+
attachment = attachment_service.get(attachment_id)
22+
assert attachment.id == attachment_id
23+
24+
25+
def test_download_attachment(attachment_service, attachment_id):
26+
file_response = attachment_service.download(attachment_id)
27+
assert file_response.file_contents is not None
28+
assert file_response.filename == "empty.pdf"
29+
30+
31+
def test_iterate_attachments(attachment_service, created_attachment):
32+
attachments = list(attachment_service.iterate())
33+
assert any(att.id == created_attachment.id for att in attachments)
34+
35+
36+
def test_filter_attachments(attachment_service, created_attachment):
37+
attachments = list(attachment_service.filter(RQLQuery(id=created_attachment.id)).iterate())
38+
assert len(attachments) == 1
39+
assert attachments[0].id == created_attachment.id
40+
41+
42+
def test_not_found(attachment_service):
43+
with pytest.raises(MPTAPIError):
44+
attachment_service.get("ATT-000-000-000")
45+
46+
47+
def test_delete_attachment(attachment_service, created_attachment):
48+
attachment_service.delete(created_attachment.id)
49+
with pytest.raises(MPTAPIError):
50+
attachment_service.get(created_attachment.id)

tests/e2e/catalog/pricing_policies/conftest.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from mpt_api_client.exceptions import MPTAPIError
4+
35

46
@pytest.fixture
57
def buyer_id(e2e_config):
@@ -19,5 +21,22 @@ def pricing_policy_data(buyer_id, product_id):
1921

2022

2123
@pytest.fixture
22-
def pricing_policy_id(e2e_config):
23-
return e2e_config.get("catalog.pricing_policy.id")
24+
def pricing_policies_service(mpt_ops):
25+
return mpt_ops.catalog.pricing_policies
26+
27+
28+
@pytest.fixture
29+
def created_pricing_policy(pricing_policies_service, pricing_policy_data):
30+
policy = pricing_policies_service.create(pricing_policy_data)
31+
32+
yield policy
33+
34+
try:
35+
pricing_policies_service.delete(policy.id)
36+
except MPTAPIError as error:
37+
print(f"TEARDOWN - Unable to delete pricing policy {policy.id}: {error.title}")
38+
39+
40+
@pytest.fixture
41+
def pricing_policy_id(created_pricing_policy):
42+
return created_pricing_policy.id

tests/e2e/catalog/pricing_policies/test_async_pricing_policies.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ async def test_get_pricing_policy(async_pricing_policies_service, async_created_
3232
assert fetched.id == async_created_pricing_policy.id
3333

3434

35-
async def test_get_pricing_policy_by_id(
36-
async_pricing_policies_service, async_created_pricing_policy
37-
):
38-
fetched = await async_pricing_policies_service.get(async_created_pricing_policy.id)
39-
assert fetched.id == async_created_pricing_policy.id
35+
async def test_get_pricing_policy_by_id(async_pricing_policies_service, pricing_policy_id):
36+
fetched = await async_pricing_policies_service.get(pricing_policy_id)
37+
assert fetched.id == pricing_policy_id
4038

4139

4240
async def test_iterate_pricing_policies(

tests/e2e/catalog/pricing_policies/test_sync_pricing_policies.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@
66
pytestmark = [pytest.mark.flaky]
77

88

9-
@pytest.fixture
10-
def pricing_policies_service(mpt_ops):
11-
return mpt_ops.catalog.pricing_policies
12-
13-
14-
@pytest.fixture
15-
def created_pricing_policy(pricing_policies_service, pricing_policy_data):
16-
policy = pricing_policies_service.create(pricing_policy_data)
17-
18-
yield policy
19-
20-
try:
21-
pricing_policies_service.delete(policy.id)
22-
except MPTAPIError as error:
23-
print(f"TEARDOWN - Unable to delete pricing policy {policy.id}: {error.title}")
24-
25-
269
def test_create_pricing_policy(created_pricing_policy, pricing_policy_data):
2710
assert created_pricing_policy.name == pricing_policy_data["name"]
2811

@@ -33,8 +16,6 @@ def test_get_pricing_policy(pricing_policies_service, created_pricing_policy):
3316

3417

3518
def test_get_pricing_policy_by_id(pricing_policies_service, pricing_policy_id):
36-
if not pricing_policy_id:
37-
pytest.skip("No pricing_policy_id configured")
3819
fetched = pricing_policies_service.get(pricing_policy_id)
3920
assert fetched.id == pricing_policy_id
4021

0 commit comments

Comments
 (0)