Skip to content

Commit 9619a7a

Browse files
authored
MPT-14900 E2E tests for catalog pricing-policies attachments (#133)
2 parents 3399c94 + 90761ff commit 9619a7a

23 files changed

Lines changed: 224 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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
result = created_attachment_async
26+
27+
assert result.name == attachment_data["name"]
28+
assert result.description == attachment_data["description"]
29+
30+
31+
async def test_update_attachment_async(async_attachment_service, created_attachment_async):
32+
update_data = {"name": "Updated e2e test attachment - please delete"}
33+
34+
result = await async_attachment_service.update(created_attachment_async.id, update_data)
35+
36+
assert result.name == update_data["name"]
37+
38+
39+
async def test_get_attachment_async(async_attachment_service, attachment_id):
40+
result = await async_attachment_service.get(attachment_id)
41+
42+
assert result.id == attachment_id
43+
44+
45+
async def test_download_attachment_async(async_attachment_service, attachment_id):
46+
result = await async_attachment_service.download(attachment_id)
47+
48+
assert result.file_contents is not None
49+
assert result.filename == "empty.pdf"
50+
51+
52+
async def test_iterate_attachments_async(async_attachment_service, created_attachment_async):
53+
result = [att async for att in async_attachment_service.iterate()]
54+
55+
assert any(att.id == created_attachment_async.id for att in result)
56+
57+
58+
async def test_filter_attachments_async(async_attachment_service, created_attachment_async):
59+
filtered_service = async_attachment_service.filter(RQLQuery(id=created_attachment_async.id))
60+
61+
result = [att async for att in filtered_service.iterate()]
62+
63+
assert len(result) == 1
64+
assert result[0].id == created_attachment_async.id
65+
66+
67+
async def test_not_found_async(async_attachment_service):
68+
with pytest.raises(MPTAPIError):
69+
await async_attachment_service.get("ATT-000-000-000")
70+
71+
72+
async def test_delete_attachment_async(async_attachment_service, created_attachment_async):
73+
await async_attachment_service.delete(created_attachment_async.id)
74+
75+
with pytest.raises(MPTAPIError):
76+
await async_attachment_service.get(created_attachment_async.id)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
result = created_attachment
11+
12+
assert result.name == attachment_data["name"]
13+
assert result.description == attachment_data["description"]
14+
15+
16+
def test_update_attachment(attachment_service, created_attachment):
17+
update_data = {"name": "Updated e2e test attachment - please delete"}
18+
19+
result = attachment_service.update(created_attachment.id, update_data)
20+
21+
assert result.name == update_data["name"]
22+
23+
24+
def test_get_attachment(attachment_service, attachment_id):
25+
result = attachment_service.get(attachment_id)
26+
27+
assert result.id == attachment_id
28+
29+
30+
def test_download_attachment(attachment_service, attachment_id):
31+
result = attachment_service.download(attachment_id)
32+
33+
assert result.file_contents is not None
34+
assert result.filename == "empty.pdf"
35+
36+
37+
def test_iterate_attachments(attachment_service, created_attachment):
38+
result = list(attachment_service.iterate())
39+
40+
assert any(att.id == created_attachment.id for att in result)
41+
42+
43+
def test_filter_attachments(attachment_service, created_attachment):
44+
result = list(attachment_service.filter(RQLQuery(id=created_attachment.id)).iterate())
45+
46+
assert len(result) == 1
47+
assert result[0].id == created_attachment.id
48+
49+
50+
def test_not_found(attachment_service):
51+
with pytest.raises(MPTAPIError):
52+
attachment_service.get("ATT-000-000-000")
53+
54+
55+
def test_delete_attachment(attachment_service, created_attachment):
56+
attachment_service.delete(created_attachment.id)
57+
58+
with pytest.raises(MPTAPIError):
59+
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
@@ -35,12 +35,10 @@ async def test_get_pricing_policy(async_pricing_policies_service, async_created_
3535
assert result.id == async_created_pricing_policy.id
3636

3737

38-
async def test_get_pricing_policy_by_id(
39-
async_pricing_policies_service, async_created_pricing_policy
40-
):
41-
result = await async_pricing_policies_service.get(async_created_pricing_policy.id)
38+
async def test_get_pricing_policy_by_id(async_pricing_policies_service, pricing_policy_id):
39+
result = await async_pricing_policies_service.get(pricing_policy_id)
4240

43-
assert result.id == async_created_pricing_policy.id
41+
assert result.id == pricing_policy_id
4442

4543

4644
async def test_iterate_pricing_policies(

tests/e2e/catalog/pricing_policies/test_sync_pricing_policies.py

Lines changed: 0 additions & 20 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
result = created_pricing_policy
2811

@@ -36,9 +19,6 @@ def test_get_pricing_policy(pricing_policies_service, created_pricing_policy):
3619

3720

3821
def test_get_pricing_policy_by_id(pricing_policies_service, pricing_policy_id):
39-
if not pricing_policy_id:
40-
pytest.skip("No pricing_policy_id configured")
41-
4222
result = pricing_policies_service.get(pricing_policy_id)
4323

4424
assert result.id == pricing_policy_id

0 commit comments

Comments
 (0)