Skip to content

Commit 6c91d66

Browse files
authored
MPT-14893 E2E tests for product templates (#130)
2 parents 6c3538f + 1b07836 commit 6c91d66

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

e2e_config.test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"catalog.product.item_group.id": "IGR-7255-3950-0001",
1717
"catalog.product.parameter.id": "PAR-7255-3950-0016",
1818
"catalog.product.parameter_group.id": "PGR-7255-3950-0001",
19+
"catalog.product.template.id": "TPL-7255-3950-0001",
1920
"catalog.unit.id": "UNT-1229"
2021
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def template_payload():
6+
return {
7+
"name": "Test Template - delete",
8+
"description": "A template for testing",
9+
"content": "template content",
10+
"type": "OrderProcessing",
11+
}
12+
13+
14+
@pytest.fixture
15+
def template_id(e2e_config):
16+
return e2e_config["catalog.product.template.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 import RQLQuery
4+
from mpt_api_client.exceptions import MPTAPIError
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
def async_template_service(async_mpt_vendor, product_id):
11+
return async_mpt_vendor.catalog.products.templates(product_id)
12+
13+
14+
@pytest.fixture
15+
async def async_created_template(async_template_service, template_payload):
16+
template = await async_template_service.create(template_payload)
17+
yield template
18+
try:
19+
await async_template_service.delete(template.id)
20+
except MPTAPIError as error:
21+
print(f"TEARDOWN - Unable to delete template {template.id}: {error.title}")
22+
23+
24+
async def test_list_templates(async_template_service):
25+
templates = [template async for template in async_template_service.iterate()]
26+
assert isinstance(templates, list)
27+
28+
29+
def test_created_template(async_created_template, template_payload):
30+
assert async_created_template.name == template_payload["name"]
31+
32+
33+
async def test_get_template(async_template_service, template_id):
34+
template = await async_template_service.get(template_id)
35+
36+
assert template.id == template_id
37+
38+
39+
async def test_update_template(async_created_template, async_template_service):
40+
update_payload = {"name": "Updated name"}
41+
updated_template = await async_template_service.update(
42+
async_created_template.id, update_payload
43+
)
44+
assert updated_template.name == "Updated name"
45+
46+
47+
async def test_delete_template(async_template_service, async_created_template):
48+
await async_template_service.delete(async_created_template.id)
49+
50+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
51+
await async_template_service.get(async_created_template.id)
52+
53+
54+
async def test_filter_templates(async_template_service, template_id):
55+
template = await async_template_service.filter(RQLQuery(id=template_id)).fetch_one()
56+
assert template.id == template_id
57+
58+
59+
async def test_not_found(async_template_service):
60+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
61+
await async_template_service.get("TMP-000-000")
62+
63+
64+
async def test_create_wrong_data(async_template_service):
65+
with pytest.raises(MPTAPIError, match=r"400 One or more validation errors occurred"):
66+
await async_template_service.create({})
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
3+
from mpt_api_client import RQLQuery
4+
from mpt_api_client.exceptions import MPTAPIError
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
def template_service(mpt_vendor, product_id):
11+
return mpt_vendor.catalog.products.templates(product_id)
12+
13+
14+
@pytest.fixture
15+
def created_template(template_service, template_payload):
16+
template = template_service.create(template_payload)
17+
18+
yield template
19+
20+
try:
21+
template_service.delete(template.id)
22+
except MPTAPIError as error:
23+
print(f"TEARDOWN - Unable to delete template {template.id}: {error.title}")
24+
25+
26+
def test_list_templates(template_service, product_id):
27+
templates = list(template_service.iterate())
28+
assert isinstance(templates, list)
29+
30+
31+
def test_created_template(created_template, template_payload):
32+
assert created_template.name == template_payload["name"]
33+
34+
35+
def test_get_template(template_service, template_id):
36+
template = template_service.get(template_id)
37+
38+
assert template.id == template_id
39+
40+
41+
def test_update_template(created_template, template_service):
42+
update_payload = {"name": "Updated name"}
43+
44+
updated_template = template_service.update(created_template.id, update_payload)
45+
46+
assert updated_template.name == "Updated name"
47+
48+
49+
def test_delete_template(template_service, created_template, template_payload):
50+
template_service.delete(created_template.id)
51+
52+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
53+
template_service.get(created_template.id)
54+
55+
56+
def test_filter_templates(template_service, template_id):
57+
template = template_service.filter(RQLQuery(id=template_id)).fetch_one()
58+
59+
assert template.id == template_id
60+
61+
62+
def test_not_found(template_service):
63+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
64+
template_service.get("TMP-000-000")
65+
66+
67+
def test_create_wrong_data(template_service):
68+
with pytest.raises(MPTAPIError, match=r"400 One or more validation errors occurred"):
69+
template_service.create({})

0 commit comments

Comments
 (0)