diff --git a/tests/e2e/notifications/__init__.py b/tests/e2e/notifications/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/e2e/notifications/categories/__init__.py b/tests/e2e/notifications/categories/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/e2e/notifications/categories/conftest.py b/tests/e2e/notifications/categories/conftest.py new file mode 100644 index 0000000..02bc656 --- /dev/null +++ b/tests/e2e/notifications/categories/conftest.py @@ -0,0 +1,15 @@ +import pytest + + +@pytest.fixture +def category_data(short_uuid): + return { + "name": f"e2e-category-{short_uuid}", + "description": "E2E test category - please delete", + "externalId": f"e2e-cat-{short_uuid}", + } + + +@pytest.fixture +def invalid_category_id(): + return "NCT-000-000-000" diff --git a/tests/e2e/notifications/categories/test_async_categories.py b/tests/e2e/notifications/categories/test_async_categories.py new file mode 100644 index 0000000..fa46d72 --- /dev/null +++ b/tests/e2e/notifications/categories/test_async_categories.py @@ -0,0 +1,115 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.rql.query_builder import RQLQuery + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +async def async_created_category(async_mpt_ops, category_data): + service = async_mpt_ops.notifications.categories + category = await service.create(category_data) + yield category + try: + await service.delete(category.id) + except MPTAPIError as error: + print(f"TEARDOWN - Unable to delete category {category.id}: {error.title}") # noqa: WPS421 + + +@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") # noqa: AAA01 +def test_create_category(async_created_category, category_data): + assert async_created_category.name == category_data["name"] + assert async_created_category.description == category_data["description"] + + +@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") +async def test_get_category(async_mpt_vendor, async_created_category): + service = async_mpt_vendor.notifications.categories + + result = await service.get(async_created_category.id) + + assert result.id == async_created_category.id + assert result.name == async_created_category.name + + +@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") +async def test_update_category(async_mpt_ops, async_created_category): + service = async_mpt_ops.notifications.categories + update_data = { + "name": "e2e-async-updated-category", + "description": "Async updated description", + } + + result = await service.update(async_created_category.id, update_data) + + assert result.name == "e2e-async-updated-category" + assert result.description == "Async updated description" + + +@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") +async def test_list_categories(async_mpt_vendor, async_created_category): + service = async_mpt_vendor.notifications.categories + + result = [category async for category in service.iterate()] + + assert any(category.id == async_created_category.id for category in result) + + +@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") +async def test_filter_categories(async_mpt_vendor, async_created_category): + service = async_mpt_vendor.notifications.categories + + result = [ + category + async for category in service.filter(RQLQuery(id=async_created_category.id)).iterate() + ] + + assert len(result) == 1 + assert result[0].id == async_created_category.id + + +@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") +async def test_publish_category(async_mpt_ops, async_created_category): + service = async_mpt_ops.notifications.categories + unpublish_note_data = {"note": "Unpublishing category for async testing"} + await service.unpublish(async_created_category.id, unpublish_note_data) + note_data = {"note": "Publishing category for async testing"} + + result = await service.publish(async_created_category.id, note_data) + + assert result.id == async_created_category.id + + +@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") +async def test_unpublish_category(async_mpt_ops, async_created_category): + service = async_mpt_ops.notifications.categories + unpublish_note_data = {"note": "Unpublishing category for async testing"} + + result = await service.unpublish(async_created_category.id, unpublish_note_data) + + assert result.id == async_created_category.id + + +async def test_category_not_found(async_mpt_vendor, invalid_category_id): + service = async_mpt_vendor.notifications.categories + + with pytest.raises(MPTAPIError): + await service.get(invalid_category_id) + + +@pytest.mark.skip(reason="async_created_category kills performance due to MPT-13785") +async def test_delete_category(async_mpt_ops, async_created_category): + service = async_mpt_ops.notifications.categories + + await service.delete(async_created_category.id) + + with pytest.raises(MPTAPIError): + await service.get(async_created_category.id) + + +async def test_delete_category_not_found(async_mpt_ops, invalid_category_id): + service = async_mpt_ops.notifications.categories + + with pytest.raises(MPTAPIError): + await service.delete(invalid_category_id) diff --git a/tests/e2e/notifications/categories/test_sync_categories.py b/tests/e2e/notifications/categories/test_sync_categories.py new file mode 100644 index 0000000..37370c9 --- /dev/null +++ b/tests/e2e/notifications/categories/test_sync_categories.py @@ -0,0 +1,113 @@ +import pytest + +from mpt_api_client.exceptions import MPTAPIError +from mpt_api_client.rql.query_builder import RQLQuery + +pytestmark = [pytest.mark.flaky] + + +@pytest.fixture +def created_category(mpt_ops, category_data): + service = mpt_ops.notifications.categories + category = service.create(category_data) + yield category + try: + service.delete(category.id) + except MPTAPIError as error: + print(f"TEARDOWN - Unable to delete category {category.id}: {error.title}") # noqa: WPS421 + + +@pytest.mark.skip(reason="created_category kills performance due to MPT-13785") +def test_create_category(created_category, category_data): + assert created_category.name == category_data["name"] # act + + assert created_category.description == category_data["description"] + + +@pytest.mark.skip(reason="created_category kills performance due to MPT-13785") +def test_get_category(mpt_client, created_category): + service = mpt_client.notifications.categories + + result = service.get(created_category.id) + + assert result.id == created_category.id + assert result.name == created_category.name + + +@pytest.mark.skip(reason="created_category kills performance due to MPT-13785") +def test_update_category(mpt_ops, created_category): + service = mpt_ops.notifications.categories + update_data = { + "name": "e2e-updated-category", + "description": "Updated description", + } + + result = service.update(created_category.id, update_data) + + assert result.name == "e2e-updated-category" + assert result.description == "Updated description" + + +@pytest.mark.skip(reason="created_category kills performance due to MPT-13785") +def test_list_categories(mpt_client, created_category): + service = mpt_client.notifications.categories + + result = list(service.iterate()) + + assert any(category.id == created_category.id for category in result) + + +@pytest.mark.skip(reason="created_category kills performance due to MPT-13785") +def test_filter_categories(mpt_client, created_category): + service = mpt_client.notifications.categories + + result = list(service.filter(RQLQuery(id=created_category.id)).iterate()) + + assert len(result) == 1 + assert result[0].id == created_category.id + + +@pytest.mark.skip(reason="created_category kills performance due to MPT-13785") +def test_publish_category(mpt_ops, created_category): + service = mpt_ops.notifications.categories + unpublish_note_data = {"note": "Unpublishing category for testing"} + service.unpublish(created_category.id, unpublish_note_data) + note_data = {"note": "Publishing category for testing"} + + result = service.publish(created_category.id, note_data) + + assert result.id == created_category.id + + +@pytest.mark.skip(reason="created_category kills performance due to MPT-13785") +def test_unpublish_category(mpt_ops, created_category): + service = mpt_ops.notifications.categories + unpublish_note_data = {"note": "Unpublishing category for testing"} + + result = service.unpublish(created_category.id, unpublish_note_data) + + assert result.id == created_category.id + + +def test_category_not_found(mpt_client, invalid_category_id): + service = mpt_client.notifications.categories + + with pytest.raises(MPTAPIError): + service.get(invalid_category_id) + + +@pytest.mark.skip(reason="created_category kills performance due to MPT-13785") +def test_delete_category(mpt_ops, created_category): + service = mpt_ops.notifications.categories + + service.delete(created_category.id) # act + + with pytest.raises(MPTAPIError): + service.get(created_category.id) + + +def test_delete_category_not_found(mpt_ops, invalid_category_id): + service = mpt_ops.notifications.categories + + with pytest.raises(MPTAPIError): + service.delete(invalid_category_id)