|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mpt_api_client import RQLQuery |
| 4 | +from mpt_api_client.exceptions import MPTAPIError |
| 5 | + |
| 6 | + |
| 7 | +@pytest.fixture |
| 8 | +async def async_created_product(logger, async_mpt_vendor, product_data, product_icon): |
| 9 | + product = await async_mpt_vendor.catalog.products.create(product_data, icon=product_icon) |
| 10 | + |
| 11 | + yield product |
| 12 | + |
| 13 | + try: |
| 14 | + await async_mpt_vendor.catalog.products.delete(product.id) |
| 15 | + except MPTAPIError as error: |
| 16 | + logger.exception("TEARDOWN - Unable to delete product %s: %s", product.id, error.title) |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.flaky |
| 20 | +def test_create_product(async_created_product, product_data): |
| 21 | + assert async_created_product.name == product_data["name"] |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.flaky |
| 25 | +async def test_update_product(async_mpt_vendor, async_created_product): |
| 26 | + update_data = {"name": "Updated Product"} |
| 27 | + |
| 28 | + product = await async_mpt_vendor.catalog.products.update(async_created_product.id, update_data) |
| 29 | + |
| 30 | + assert product.name == update_data["name"] |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.skip(reason="Leaves test products in the catalog") |
| 34 | +@pytest.mark.flaky |
| 35 | +async def test_product_review_and_publish(async_mpt_vendor, async_mpt_ops, async_created_product): |
| 36 | + await async_mpt_vendor.catalog.products.review(async_created_product.id) |
| 37 | + await async_mpt_ops.catalog.products.publish(async_created_product.id) |
| 38 | + |
| 39 | + |
| 40 | +@pytest.mark.flaky |
| 41 | +async def test_get_product(async_mpt_vendor, product_id, logger): |
| 42 | + await async_mpt_vendor.catalog.products.get(product_id) |
| 43 | + |
| 44 | + |
| 45 | +@pytest.mark.flaky |
| 46 | +async def test_product_save_settings(async_mpt_vendor, async_created_product): |
| 47 | + await async_mpt_vendor.catalog.products.update_settings( |
| 48 | + async_created_product.id, {"itemSelection": True} |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +@pytest.mark.flaky |
| 53 | +async def test_filter_and_select_products(async_mpt_vendor, product_id): |
| 54 | + select_fields = ["-icon", "-revision", "-settings", "-vendor", "-statistics", "-website"] |
| 55 | + filtered_products = ( |
| 56 | + async_mpt_vendor.catalog.products.filter(RQLQuery(id=product_id)) |
| 57 | + .filter(RQLQuery(name="E2E Seeded")) |
| 58 | + .select(*select_fields) |
| 59 | + ) |
| 60 | + products = [product async for product in filtered_products.iterate()] |
| 61 | + assert len(products) == 1 |
0 commit comments