Skip to content

Commit e5285eb

Browse files
albertsolad3rky
authored andcommitted
MPT-14887 E2E tests for catalog/product/item_groups
1 parent edd37a2 commit e5285eb

5 files changed

Lines changed: 165 additions & 2 deletions

File tree

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ per-file-ignores =
5050
tests/unit/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235
5151
tests/unit/test_mpt_client.py: WPS235
5252
tests/e2e/accounts/*.py: WPS430 WPS202
53-
tests/e2e/catalog/*.py: WPS421
53+
tests/e2e/catalog/*.py: WPS202 WPS421
5454
tests/e2e/catalog/items/*.py: WPS110 WPS202
55-
tests/e2e/catalog/product/documents/*.py: WPS202 WPS421
5655

5756
tests/*:
5857
# Allow magic strings.

tests/e2e/catalog/product/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ def parameter_group_id(e2e_config):
1414
@pytest.fixture
1515
def parameter_id(e2e_config):
1616
return e2e_config["catalog.product.parameter.id"]
17+
18+
19+
@pytest.fixture
20+
def item_group_id(e2e_config):
21+
return e2e_config["catalog.product.item_group.id"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def item_group_data(product_id):
6+
return {
7+
"product": {"id": product_id},
8+
"name": "e2e - please delete",
9+
"label": "e2e - please delete",
10+
"description": "e2e - temporary item group",
11+
"displayOrder": 100,
12+
"default": False,
13+
"multiple": True,
14+
"required": True,
15+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery # added import
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
async def async_created_item_group(logger, async_mpt_vendor, product_id, item_group_data):
11+
service = async_mpt_vendor.catalog.products.item_groups(product_id)
12+
group = await service.create(item_group_data)
13+
yield group
14+
try:
15+
await service.delete(group.id)
16+
except MPTAPIError as error: # noqa: WPS421
17+
print(f"TEARDOWN - Unable to delete item group {group.id}: {error.title}")
18+
19+
20+
def test_create_item_group(async_created_item_group):
21+
assert async_created_item_group.name == "e2e - please delete"
22+
23+
24+
async def test_update_item_group(async_mpt_vendor, product_id, async_created_item_group):
25+
service = async_mpt_vendor.catalog.products.item_groups(product_id)
26+
update_data = {"name": "e2e - delete me (updated)"}
27+
group = await service.update(async_created_item_group.id, update_data)
28+
assert group.name == "e2e - delete me (updated)"
29+
30+
31+
async def test_get_item_group(async_mpt_vendor, product_id, item_group_id):
32+
service = async_mpt_vendor.catalog.products.item_groups(product_id)
33+
group = await service.get(item_group_id)
34+
assert group.id == item_group_id
35+
36+
37+
async def test_get_item_group_by_id(async_mpt_vendor, product_id, item_group_id):
38+
service = async_mpt_vendor.catalog.products.item_groups(product_id)
39+
40+
group = await service.get(item_group_id)
41+
42+
assert group.id == item_group_id
43+
44+
45+
async def test_iterate_item_groups(async_mpt_vendor, product_id, async_created_item_group):
46+
service = async_mpt_vendor.catalog.products.item_groups(product_id)
47+
48+
groups = [group async for group in service.iterate()]
49+
50+
assert any(group.id == async_created_item_group.id for group in groups)
51+
52+
53+
async def test_filter_item_groups(async_mpt_vendor, product_id, item_group_id):
54+
select_fields = ["-description"]
55+
filtered_item_groups = (
56+
async_mpt_vendor.catalog.products.item_groups(product_id)
57+
.filter(RQLQuery(id=item_group_id))
58+
.select(*select_fields)
59+
)
60+
61+
groups = [group async for group in filtered_item_groups.iterate()]
62+
63+
assert len(groups) == 1
64+
assert groups[0].id == item_group_id
65+
66+
67+
async def test_delete_item_group(async_mpt_vendor, product_id, async_created_item_group):
68+
service = async_mpt_vendor.catalog.products.item_groups(product_id)
69+
70+
await service.delete(async_created_item_group.id)
71+
72+
with pytest.raises(MPTAPIError):
73+
await service.get(async_created_item_group.id)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery # added import
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
def created_item_group(logger, mpt_vendor, product_id, item_group_data):
11+
service = mpt_vendor.catalog.products.item_groups(product_id)
12+
group = service.create(item_group_data)
13+
yield group
14+
try:
15+
service.delete(group.id)
16+
except MPTAPIError as error: # noqa: WPS421
17+
print(f"TEARDOWN - Unable to delete item group {group.id}: {error.title}")
18+
19+
20+
def test_create_item_group(created_item_group):
21+
assert created_item_group.name == "e2e - please delete"
22+
23+
24+
def test_update_item_group(mpt_vendor, product_id, created_item_group):
25+
service = mpt_vendor.catalog.products.item_groups(product_id)
26+
update_data = {"name": "please delete me"}
27+
28+
group = service.update(created_item_group.id, update_data)
29+
30+
assert group.name == "please delete me"
31+
32+
33+
def test_get_item_group(mpt_vendor, product_id, created_item_group):
34+
service = mpt_vendor.catalog.products.item_groups(product_id)
35+
36+
group = service.get(created_item_group.id)
37+
38+
assert group.id == created_item_group.id
39+
40+
41+
def test_get_item_group_by_id(mpt_vendor, product_id, item_group_id):
42+
service = mpt_vendor.catalog.products.item_groups(product_id)
43+
44+
group = service.get(item_group_id)
45+
46+
assert group.id == item_group_id
47+
48+
49+
def test_iterate_item_groups(mpt_vendor, product_id, created_item_group):
50+
service = mpt_vendor.catalog.products.item_groups(product_id)
51+
groups = list(service.iterate())
52+
assert any(group.id == created_item_group.id for group in groups)
53+
54+
55+
def test_filter_item_groups(mpt_vendor, product_id, item_group_id):
56+
select_fields = ["-description"]
57+
filtered_item_groups = (
58+
mpt_vendor.catalog.products.item_groups(product_id)
59+
.filter(RQLQuery(id=item_group_id))
60+
.select(*select_fields)
61+
)
62+
groups = list(filtered_item_groups.iterate())
63+
assert len(groups) == 1
64+
assert groups[0].id == item_group_id
65+
66+
67+
def test_delete_item_group(mpt_vendor, product_id, created_item_group):
68+
service = mpt_vendor.catalog.products.item_groups(product_id)
69+
service.delete(created_item_group.id)
70+
with pytest.raises(MPTAPIError):
71+
service.get(created_item_group.id)

0 commit comments

Comments
 (0)