Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e_config.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
16 changes: 16 additions & 0 deletions tests/e2e/catalog/product/templates/conftest.py
Original file line number Diff line number Diff line change
@@ -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"]
66 changes: 66 additions & 0 deletions tests/e2e/catalog/product/templates/test_async_templates.py
Original file line number Diff line number Diff line change
@@ -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({})
69 changes: 69 additions & 0 deletions tests/e2e/catalog/product/templates/test_sync_templates.py
Original file line number Diff line number Diff line change
@@ -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({})