|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mpt_api_client.exceptions import MPTAPIError |
| 4 | +from tests.e2e.helper import ( |
| 5 | + assert_async_service_filter_with_iterate, |
| 6 | + assert_async_update_resource, |
| 7 | + async_create_fixture_resource_and_delete, |
| 8 | +) |
| 9 | + |
| 10 | +pytestmark = [pytest.mark.flaky] |
| 11 | + |
| 12 | + |
| 13 | +@pytest.fixture |
| 14 | +def async_price_lists_service(async_mpt_ops): |
| 15 | + return async_mpt_ops.catalog.price_lists |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture |
| 19 | +async def async_created_price_list(async_price_lists_service, price_list_data): |
| 20 | + async with async_create_fixture_resource_and_delete( |
| 21 | + async_price_lists_service, price_list_data |
| 22 | + ) as price_list: |
| 23 | + yield price_list |
| 24 | + |
| 25 | + |
| 26 | +def test_create_price_list(async_created_price_list, product_id): |
| 27 | + result = async_created_price_list |
| 28 | + |
| 29 | + assert result.product.id == product_id |
| 30 | + |
| 31 | + |
| 32 | +async def test_get_price_list(async_price_lists_service, async_created_price_list): |
| 33 | + result = await async_price_lists_service.get(async_created_price_list.id) |
| 34 | + |
| 35 | + assert result.id == async_created_price_list.id |
| 36 | + |
| 37 | + |
| 38 | +async def test_get_price_list_by_id(async_price_lists_service, price_list_id): |
| 39 | + result = await async_price_lists_service.get(price_list_id) |
| 40 | + |
| 41 | + assert result.id == price_list_id |
| 42 | + |
| 43 | + |
| 44 | +async def test_filter_price_lists(async_price_lists_service, async_created_price_list): |
| 45 | + await assert_async_service_filter_with_iterate( |
| 46 | + async_price_lists_service, async_created_price_list.id, ["-product"] |
| 47 | + ) # act |
| 48 | + |
| 49 | + |
| 50 | +async def test_update_price_list(async_price_lists_service, async_created_price_list, short_uuid): |
| 51 | + await assert_async_update_resource( |
| 52 | + async_price_lists_service, |
| 53 | + async_created_price_list.id, |
| 54 | + "notes", |
| 55 | + f"Updated notes {short_uuid}", |
| 56 | + ) # act |
| 57 | + |
| 58 | + |
| 59 | +async def test_delete_price_list(async_price_lists_service, async_created_price_list): |
| 60 | + await async_price_lists_service.delete(async_created_price_list.id) # act |
| 61 | + |
| 62 | + |
| 63 | +async def test_get_price_list_not_found(async_price_lists_service): |
| 64 | + bogus_id = "PRL-0000-NOTFOUND" |
| 65 | + |
| 66 | + with pytest.raises(MPTAPIError, match=r"404 Not Found"): |
| 67 | + await async_price_lists_service.get(bogus_id) |
| 68 | + |
| 69 | + |
| 70 | +async def test_create_price_list_invalid_data(async_price_lists_service): |
| 71 | + invalid_data = {"name": "e2e - delete me"} |
| 72 | + |
| 73 | + with pytest.raises(MPTAPIError, match=r"400 One or more validation errors occurred"): |
| 74 | + await async_price_lists_service.create(invalid_data) |
0 commit comments