Skip to content

Commit 0e1014e

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

7 files changed

Lines changed: 164 additions & 14 deletions

File tree

e2e_config.test.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@
1919
"catalog.product.template.id": "TPL-7255-3950-0001",
2020
"catalog.product.terms.id": "TCS-7255-3950-0001",
2121
"catalog.product.terms.variant.id": "TCV-7255-3950-0001-0001",
22-
"catalog.unit.id": "UNT-1229"
22+
"catalog.unit.id": "UNT-1229",
23+
"catalog.pricing_policy.id": "PRP-1123-5132-3456",
24+
"catalog.pricing_policy.attachment.id": "PPA-1123-5132-3456-0001"
2325
}

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/pricing_policies/attachments/__init__.py

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

tests/unit/resources/catalog/test_pricing_policy_attachments.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@ def test_async_endpoint(async_pricing_policy_attachments_service) -> None:
3636
)
3737

3838

39-
@pytest.mark.parametrize(
40-
"method", ["get", "create", "delete", "update", "download", "activate", "deactivate"]
41-
)
39+
@pytest.mark.parametrize("method", ["get", "create", "delete", "update", "download"])
4240
def test_methods_present(pricing_policy_attachments_service, method: str) -> None:
4341
assert hasattr(pricing_policy_attachments_service, method)
4442

4543

46-
@pytest.mark.parametrize(
47-
"method", ["get", "create", "delete", "update", "download", "activate", "deactivate"]
48-
)
44+
@pytest.mark.parametrize("method", ["get", "create", "delete", "update", "download"])
4945
def test_async_methods_present(async_pricing_policy_attachments_service, method: str) -> None:
5046
assert hasattr(async_pricing_policy_attachments_service, method)

0 commit comments

Comments
 (0)