From 972f019cd393998dceec6582a68dd9e434d615a4 Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Tue, 16 Dec 2025 13:52:34 +0000 Subject: [PATCH] MPT-14933 E2E for notifications/contacts --- tests/e2e/notifications/contacts/conftest.py | 41 ++++++++++++ .../contacts/test_async_contacts.py | 63 ++++++++++++++++++ .../contacts/test_sync_contacts.py | 64 +++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 tests/e2e/notifications/contacts/conftest.py create mode 100644 tests/e2e/notifications/contacts/test_async_contacts.py create mode 100644 tests/e2e/notifications/contacts/test_sync_contacts.py diff --git a/tests/e2e/notifications/contacts/conftest.py b/tests/e2e/notifications/contacts/conftest.py new file mode 100644 index 0000000..a43891e --- /dev/null +++ b/tests/e2e/notifications/contacts/conftest.py @@ -0,0 +1,41 @@ +import pytest + +from tests.e2e.helper import ( + async_create_fixture_resource_and_delete, + create_fixture_resource_and_delete, +) + + +@pytest.fixture +def contact_data(short_uuid): + return { + "name": "E2E delete me", + "firstName": "Will", + "lastName": "Smith", + "email": f"{short_uuid}@example.com", + "optOuts": [], + } + + +@pytest.fixture +def created_contact(mpt_ops, contact_data): + service = mpt_ops.notifications.contacts + with create_fixture_resource_and_delete(service, contact_data) as contact: + yield contact + + +@pytest.fixture +async def async_created_contact(async_mpt_ops, contact_data): + service = async_mpt_ops.notifications.contacts + async with async_create_fixture_resource_and_delete(service, contact_data) as contact: + yield contact + + +@pytest.fixture +def created_contact_id(created_contact): + return created_contact.id + + +@pytest.fixture +def invalid_contact_id(): + return "CON-0000-0000-0000" diff --git a/tests/e2e/notifications/contacts/test_async_contacts.py b/tests/e2e/notifications/contacts/test_async_contacts.py new file mode 100644 index 0000000..c43f537 --- /dev/null +++ b/tests/e2e/notifications/contacts/test_async_contacts.py @@ -0,0 +1,63 @@ +import pytest + +from mpt_api_client import RQLQuery +from mpt_api_client.exceptions import MPTAPIError + +pytestmark = [pytest.mark.flaky] + + +def test_create_contact(created_contact): # noqa: AAA01 + assert created_contact is not None + + +async def test_get_contact(async_mpt_ops, created_contact_id): + result = await async_mpt_ops.notifications.contacts.get(created_contact_id) + + assert result.id == created_contact_id + + +async def test_list_contacts(async_mpt_ops, created_contact_id): + iterator = async_mpt_ops.notifications.contacts.filter( + RQLQuery(id=created_contact_id) + ).iterate() + + result = [contact async for contact in iterator] + + assert len(result) == 1 + assert result[0].id == created_contact_id + + +async def test_get_contact_not_found(async_mpt_ops): + service = async_mpt_ops.notifications.contacts + + with pytest.raises(MPTAPIError): + await service.get("CON-0000-0000-0000") + + +async def test_block_unblock_contact(async_mpt_ops, created_contact): + service = async_mpt_ops.notifications.contacts + + result_block = await service.block(created_contact.id) + result_unblock = await service.unblock(created_contact.id) + + assert result_block.status == "Blocked" + assert result_unblock.status == "Active" + + +async def test_update_contact(async_mpt_ops, created_contact, short_uuid): + service = async_mpt_ops.notifications.contacts + new_name = f"delete {short_uuid}" + result = await service.update( + created_contact.id, + { + "name": new_name, + }, + ) + + assert result.name == new_name + + +async def test_delete_contact(async_mpt_ops, created_contact): + service = async_mpt_ops.notifications.contacts + + await service.delete(created_contact.id) diff --git a/tests/e2e/notifications/contacts/test_sync_contacts.py b/tests/e2e/notifications/contacts/test_sync_contacts.py new file mode 100644 index 0000000..723ce5e --- /dev/null +++ b/tests/e2e/notifications/contacts/test_sync_contacts.py @@ -0,0 +1,64 @@ +import pytest + +from mpt_api_client import RQLQuery +from mpt_api_client.exceptions import MPTAPIError + +pytestmark = [pytest.mark.flaky] + + +def test_created_contact(created_contact): # noqa: AAA01 + assert created_contact is not None + + +def test_get_contact(mpt_ops, created_contact_id): + service = mpt_ops.notifications.contacts + + result = service.get(created_contact_id) + + assert result.id == created_contact_id + + +def test_list_contacts(mpt_ops, created_contact_id): + iterator = mpt_ops.notifications.contacts.filter(RQLQuery(id=created_contact_id)).iterate() + + result = list(iterator) + + assert len(result) == 1 + assert result[0].id == created_contact_id + + +def test_get_contact_not_found(mpt_ops, invalid_contact_id): + service = mpt_ops.notifications.contacts + + with pytest.raises(MPTAPIError): + service.get(invalid_contact_id) + + +def test_block_unblock_contact(mpt_ops, created_contact): # noqa: AAA01 + service = mpt_ops.notifications.contacts + + result_block = service.block(created_contact.id) + result_unblock = service.unblock(created_contact.id) + + assert result_block.status == "Blocked" + assert result_unblock.status == "Active" + + +def test_update_contact(mpt_ops, created_contact, short_uuid): + service = mpt_ops.notifications.contacts + new_name = f"delete {short_uuid}" + + result = service.update( + created_contact.id, + { + "name": new_name, + }, + ) + + assert result.name == new_name + + +def test_delete_contact(mpt_ops, created_contact_id): + service = mpt_ops.notifications.contacts + + service.delete(created_contact_id) # act