|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mpt_api_client.exceptions import MPTAPIError |
| 4 | +from mpt_api_client.rql.query_builder import RQLQuery |
| 5 | + |
| 6 | +pytestmark = [pytest.mark.flaky] |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +async def async_created_category(async_mpt_ops, category_data): |
| 11 | + service = async_mpt_ops.notifications.categories |
| 12 | + category = await service.create(category_data) |
| 13 | + yield category |
| 14 | + try: |
| 15 | + await service.delete(category.id) |
| 16 | + except MPTAPIError as error: |
| 17 | + print(f"TEARDOWN - Unable to delete category {category.id}: {error.title}") # noqa: WPS421 |
| 18 | + |
| 19 | + |
| 20 | +async def test_create_category(async_created_category, category_data): |
| 21 | + assert async_created_category.name == category_data["name"] |
| 22 | + assert async_created_category.description == category_data["description"] |
| 23 | + |
| 24 | + |
| 25 | +async def test_get_category(async_mpt_vendor, async_created_category): |
| 26 | + service = async_mpt_vendor.notifications.categories |
| 27 | + |
| 28 | + result = await service.get(async_created_category.id) |
| 29 | + |
| 30 | + assert result.id == async_created_category.id |
| 31 | + assert result.name == async_created_category.name |
| 32 | + |
| 33 | + |
| 34 | +async def test_update_category(async_mpt_ops, async_created_category): |
| 35 | + service = async_mpt_ops.notifications.categories |
| 36 | + update_data = { |
| 37 | + "name": "e2e-async-updated-category", |
| 38 | + "description": "Async updated description", |
| 39 | + } |
| 40 | + |
| 41 | + result = await service.update(async_created_category.id, update_data) |
| 42 | + |
| 43 | + assert result.name == "e2e-async-updated-category" |
| 44 | + assert result.description == "Async updated description" |
| 45 | + |
| 46 | + |
| 47 | +async def test_list_categories(async_mpt_vendor, async_created_category): |
| 48 | + service = async_mpt_vendor.notifications.categories |
| 49 | + |
| 50 | + result = [category async for category in service.iterate()] |
| 51 | + |
| 52 | + assert any(category.id == async_created_category.id for category in result) |
| 53 | + |
| 54 | + |
| 55 | +async def test_filter_categories(async_mpt_vendor, async_created_category): |
| 56 | + service = async_mpt_vendor.notifications.categories |
| 57 | + |
| 58 | + result = [ |
| 59 | + category |
| 60 | + async for category in service.filter(RQLQuery(id=async_created_category.id)).iterate() |
| 61 | + ] |
| 62 | + |
| 63 | + assert len(result) == 1 |
| 64 | + assert result[0].id == async_created_category.id |
| 65 | + |
| 66 | + |
| 67 | +async def test_publish_category(async_mpt_ops, async_created_category): |
| 68 | + service = async_mpt_ops.notifications.categories |
| 69 | + |
| 70 | + unpublish_note_data = {"note": "Unpublishing category for async testing"} |
| 71 | + await service.unpublish(async_created_category.id, unpublish_note_data) |
| 72 | + |
| 73 | + note_data = {"note": "Publishing category for async testing"} |
| 74 | + result = await service.publish(async_created_category.id, note_data) |
| 75 | + |
| 76 | + assert result.id == async_created_category.id |
| 77 | + |
| 78 | + |
| 79 | +async def test_unpublish_category(async_mpt_ops, async_created_category): |
| 80 | + service = async_mpt_ops.notifications.categories |
| 81 | + |
| 82 | + unpublish_note_data = {"note": "Unpublishing category for async testing"} |
| 83 | + result = await service.unpublish(async_created_category.id, unpublish_note_data) |
| 84 | + |
| 85 | + assert result.id == async_created_category.id |
| 86 | + |
| 87 | + |
| 88 | +async def test_category_not_found(async_mpt_vendor): |
| 89 | + service = async_mpt_vendor.notifications.categories |
| 90 | + |
| 91 | + with pytest.raises(MPTAPIError): |
| 92 | + await service.get("NCT-000-000-000") |
| 93 | + |
| 94 | + |
| 95 | +async def test_delete_category(async_mpt_ops, async_created_category): |
| 96 | + service = async_mpt_ops.notifications.categories |
| 97 | + |
| 98 | + await service.delete(async_created_category.id) |
| 99 | + |
| 100 | + await service.get(async_created_category.id) |
| 101 | + |
| 102 | + |
| 103 | +async def test_delete_category_not_found(async_mpt_ops, invalid_category_id): |
| 104 | + service = async_mpt_ops.notifications.categories |
| 105 | + |
| 106 | + with pytest.raises(MPTAPIError): |
| 107 | + await service.delete(invalid_category_id) |
0 commit comments