diff --git a/e2e_config.test.json b/e2e_config.test.json index 9aee6959..3080ff22 100644 --- a/e2e_config.test.json +++ b/e2e_config.test.json @@ -16,5 +16,6 @@ "catalog.product.item_group.id": "IGR-7255-3950-0001", "catalog.product.parameter.id": "PAR-7255-3950-0016", "catalog.product.parameter_group.id": "PGR-7255-3950-0001", + "catalog.product.template.id": "TPL-7255-3950-0001", "catalog.unit.id": "UNT-1229" } diff --git a/tests/e2e/catalog/product/templates/conftest.py b/tests/e2e/catalog/product/templates/conftest.py new file mode 100644 index 00000000..97918d8c --- /dev/null +++ b/tests/e2e/catalog/product/templates/conftest.py @@ -0,0 +1,16 @@ +import pytest + + +@pytest.fixture +def template_payload(): + return { + "name": "Test Template - delete", + "description": "A template for testing", + "content": "template content", + "type": "OrderProcessing", + } + + +@pytest.fixture +def template_id(e2e_config): + return e2e_config["catalog.product.template.id"] diff --git a/tests/e2e/catalog/product/templates/test_async_templates.py b/tests/e2e/catalog/product/templates/test_async_templates.py new file mode 100644 index 00000000..329b88d4 --- /dev/null +++ b/tests/e2e/catalog/product/templates/test_async_templates.py @@ -0,0 +1,66 @@ +import pytest + +from mpt_api_client import RQLQuery +from mpt_api_client.exceptions import MPTAPIError + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +def async_template_service(async_mpt_vendor, product_id): + return async_mpt_vendor.catalog.products.templates(product_id) + + +@pytest.fixture +async def async_created_template(async_template_service, template_payload): + template = await async_template_service.create(template_payload) + yield template + try: + await async_template_service.delete(template.id) + except MPTAPIError as error: + print(f"TEARDOWN - Unable to delete template {template.id}: {error.title}") + + +async def test_list_templates(async_template_service): + templates = [template async for template in async_template_service.iterate()] + assert isinstance(templates, list) + + +def test_created_template(async_created_template, template_payload): + assert async_created_template.name == template_payload["name"] + + +async def test_get_template(async_template_service, template_id): + template = await async_template_service.get(template_id) + + assert template.id == template_id + + +async def test_update_template(async_created_template, async_template_service): + update_payload = {"name": "Updated name"} + updated_template = await async_template_service.update( + async_created_template.id, update_payload + ) + assert updated_template.name == "Updated name" + + +async def test_delete_template(async_template_service, async_created_template): + await async_template_service.delete(async_created_template.id) + + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + await async_template_service.get(async_created_template.id) + + +async def test_filter_templates(async_template_service, template_id): + template = await async_template_service.filter(RQLQuery(id=template_id)).fetch_one() + assert template.id == template_id + + +async def test_not_found(async_template_service): + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + await async_template_service.get("TMP-000-000") + + +async def test_create_wrong_data(async_template_service): + with pytest.raises(MPTAPIError, match=r"400 One or more validation errors occurred"): + await async_template_service.create({}) diff --git a/tests/e2e/catalog/product/templates/test_sync_templates.py b/tests/e2e/catalog/product/templates/test_sync_templates.py new file mode 100644 index 00000000..8f7a7694 --- /dev/null +++ b/tests/e2e/catalog/product/templates/test_sync_templates.py @@ -0,0 +1,69 @@ +import pytest + +from mpt_api_client import RQLQuery +from mpt_api_client.exceptions import MPTAPIError + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +def template_service(mpt_vendor, product_id): + return mpt_vendor.catalog.products.templates(product_id) + + +@pytest.fixture +def created_template(template_service, template_payload): + template = template_service.create(template_payload) + + yield template + + try: + template_service.delete(template.id) + except MPTAPIError as error: + print(f"TEARDOWN - Unable to delete template {template.id}: {error.title}") + + +def test_list_templates(template_service, product_id): + templates = list(template_service.iterate()) + assert isinstance(templates, list) + + +def test_created_template(created_template, template_payload): + assert created_template.name == template_payload["name"] + + +def test_get_template(template_service, template_id): + template = template_service.get(template_id) + + assert template.id == template_id + + +def test_update_template(created_template, template_service): + update_payload = {"name": "Updated name"} + + updated_template = template_service.update(created_template.id, update_payload) + + assert updated_template.name == "Updated name" + + +def test_delete_template(template_service, created_template, template_payload): + template_service.delete(created_template.id) + + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + template_service.get(created_template.id) + + +def test_filter_templates(template_service, template_id): + template = template_service.filter(RQLQuery(id=template_id)).fetch_one() + + assert template.id == template_id + + +def test_not_found(template_service): + with pytest.raises(MPTAPIError, match=r"404 Not Found"): + template_service.get("TMP-000-000") + + +def test_create_wrong_data(template_service): + with pytest.raises(MPTAPIError, match=r"400 One or more validation errors occurred"): + template_service.create({})