From e5285eb31791a03b3655c440210ad1b8429803cb Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Tue, 18 Nov 2025 10:46:16 +0000 Subject: [PATCH] MPT-14887 E2E tests for catalog/product/item_groups --- setup.cfg | 3 +- tests/e2e/catalog/product/conftest.py | 5 ++ .../catalog/product/item_groups/conftest.py | 15 ++++ .../item_groups/test_async_item_groups.py | 73 +++++++++++++++++++ .../item_groups/test_sync_item_groups.py | 71 ++++++++++++++++++ 5 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/catalog/product/item_groups/conftest.py create mode 100644 tests/e2e/catalog/product/item_groups/test_async_item_groups.py create mode 100644 tests/e2e/catalog/product/item_groups/test_sync_item_groups.py diff --git a/setup.cfg b/setup.cfg index 3d376c36..c278fa56 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,9 +50,8 @@ per-file-ignores = tests/unit/resources/*/test_mixins.py: WPS118 WPS202 WPS204 WPS235 tests/unit/test_mpt_client.py: WPS235 tests/e2e/accounts/*.py: WPS430 WPS202 - tests/e2e/catalog/*.py: WPS421 + tests/e2e/catalog/*.py: WPS202 WPS421 tests/e2e/catalog/items/*.py: WPS110 WPS202 - tests/e2e/catalog/product/documents/*.py: WPS202 WPS421 tests/*: # Allow magic strings. diff --git a/tests/e2e/catalog/product/conftest.py b/tests/e2e/catalog/product/conftest.py index 52383b34..3045eee4 100644 --- a/tests/e2e/catalog/product/conftest.py +++ b/tests/e2e/catalog/product/conftest.py @@ -14,3 +14,8 @@ def parameter_group_id(e2e_config): @pytest.fixture def parameter_id(e2e_config): return e2e_config["catalog.product.parameter.id"] + + +@pytest.fixture +def item_group_id(e2e_config): + return e2e_config["catalog.product.item_group.id"] diff --git a/tests/e2e/catalog/product/item_groups/conftest.py b/tests/e2e/catalog/product/item_groups/conftest.py new file mode 100644 index 00000000..e1a5f0d5 --- /dev/null +++ b/tests/e2e/catalog/product/item_groups/conftest.py @@ -0,0 +1,15 @@ +import pytest + + +@pytest.fixture +def item_group_data(product_id): + return { + "product": {"id": product_id}, + "name": "e2e - please delete", + "label": "e2e - please delete", + "description": "e2e - temporary item group", + "displayOrder": 100, + "default": False, + "multiple": True, + "required": True, + } diff --git a/tests/e2e/catalog/product/item_groups/test_async_item_groups.py b/tests/e2e/catalog/product/item_groups/test_async_item_groups.py new file mode 100644 index 00000000..e28a3f1d --- /dev/null +++ b/tests/e2e/catalog/product/item_groups/test_async_item_groups.py @@ -0,0 +1,73 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.rql.query_builder import RQLQuery # added import + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +async def async_created_item_group(logger, async_mpt_vendor, product_id, item_group_data): + service = async_mpt_vendor.catalog.products.item_groups(product_id) + group = await service.create(item_group_data) + yield group + try: + await service.delete(group.id) + except MPTAPIError as error: # noqa: WPS421 + print(f"TEARDOWN - Unable to delete item group {group.id}: {error.title}") + + +def test_create_item_group(async_created_item_group): + assert async_created_item_group.name == "e2e - please delete" + + +async def test_update_item_group(async_mpt_vendor, product_id, async_created_item_group): + service = async_mpt_vendor.catalog.products.item_groups(product_id) + update_data = {"name": "e2e - delete me (updated)"} + group = await service.update(async_created_item_group.id, update_data) + assert group.name == "e2e - delete me (updated)" + + +async def test_get_item_group(async_mpt_vendor, product_id, item_group_id): + service = async_mpt_vendor.catalog.products.item_groups(product_id) + group = await service.get(item_group_id) + assert group.id == item_group_id + + +async def test_get_item_group_by_id(async_mpt_vendor, product_id, item_group_id): + service = async_mpt_vendor.catalog.products.item_groups(product_id) + + group = await service.get(item_group_id) + + assert group.id == item_group_id + + +async def test_iterate_item_groups(async_mpt_vendor, product_id, async_created_item_group): + service = async_mpt_vendor.catalog.products.item_groups(product_id) + + groups = [group async for group in service.iterate()] + + assert any(group.id == async_created_item_group.id for group in groups) + + +async def test_filter_item_groups(async_mpt_vendor, product_id, item_group_id): + select_fields = ["-description"] + filtered_item_groups = ( + async_mpt_vendor.catalog.products.item_groups(product_id) + .filter(RQLQuery(id=item_group_id)) + .select(*select_fields) + ) + + groups = [group async for group in filtered_item_groups.iterate()] + + assert len(groups) == 1 + assert groups[0].id == item_group_id + + +async def test_delete_item_group(async_mpt_vendor, product_id, async_created_item_group): + service = async_mpt_vendor.catalog.products.item_groups(product_id) + + await service.delete(async_created_item_group.id) + + with pytest.raises(MPTAPIError): + await service.get(async_created_item_group.id) diff --git a/tests/e2e/catalog/product/item_groups/test_sync_item_groups.py b/tests/e2e/catalog/product/item_groups/test_sync_item_groups.py new file mode 100644 index 00000000..4e7dc0c5 --- /dev/null +++ b/tests/e2e/catalog/product/item_groups/test_sync_item_groups.py @@ -0,0 +1,71 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.rql.query_builder import RQLQuery # added import + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +def created_item_group(logger, mpt_vendor, product_id, item_group_data): + service = mpt_vendor.catalog.products.item_groups(product_id) + group = service.create(item_group_data) + yield group + try: + service.delete(group.id) + except MPTAPIError as error: # noqa: WPS421 + print(f"TEARDOWN - Unable to delete item group {group.id}: {error.title}") + + +def test_create_item_group(created_item_group): + assert created_item_group.name == "e2e - please delete" + + +def test_update_item_group(mpt_vendor, product_id, created_item_group): + service = mpt_vendor.catalog.products.item_groups(product_id) + update_data = {"name": "please delete me"} + + group = service.update(created_item_group.id, update_data) + + assert group.name == "please delete me" + + +def test_get_item_group(mpt_vendor, product_id, created_item_group): + service = mpt_vendor.catalog.products.item_groups(product_id) + + group = service.get(created_item_group.id) + + assert group.id == created_item_group.id + + +def test_get_item_group_by_id(mpt_vendor, product_id, item_group_id): + service = mpt_vendor.catalog.products.item_groups(product_id) + + group = service.get(item_group_id) + + assert group.id == item_group_id + + +def test_iterate_item_groups(mpt_vendor, product_id, created_item_group): + service = mpt_vendor.catalog.products.item_groups(product_id) + groups = list(service.iterate()) + assert any(group.id == created_item_group.id for group in groups) + + +def test_filter_item_groups(mpt_vendor, product_id, item_group_id): + select_fields = ["-description"] + filtered_item_groups = ( + mpt_vendor.catalog.products.item_groups(product_id) + .filter(RQLQuery(id=item_group_id)) + .select(*select_fields) + ) + groups = list(filtered_item_groups.iterate()) + assert len(groups) == 1 + assert groups[0].id == item_group_id + + +def test_delete_item_group(mpt_vendor, product_id, created_item_group): + service = mpt_vendor.catalog.products.item_groups(product_id) + service.delete(created_item_group.id) + with pytest.raises(MPTAPIError): + service.get(created_item_group.id)