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
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/catalog/product/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
15 changes: 15 additions & 0 deletions tests/e2e/catalog/product/item_groups/conftest.py
Original file line number Diff line number Diff line change
@@ -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,
}
73 changes: 73 additions & 0 deletions tests/e2e/catalog/product/item_groups/test_async_item_groups.py
Original file line number Diff line number Diff line change
@@ -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)
71 changes: 71 additions & 0 deletions tests/e2e/catalog/product/item_groups/test_sync_item_groups.py
Original file line number Diff line number Diff line change
@@ -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)