Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/e2e/notifications/contacts/conftest.py
Original file line number Diff line number Diff line change
@@ -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"
63 changes: 63 additions & 0 deletions tests/e2e/notifications/contacts/test_async_contacts.py
Original file line number Diff line number Diff line change
@@ -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)
64 changes: 64 additions & 0 deletions tests/e2e/notifications/contacts/test_sync_contacts.py
Original file line number Diff line number Diff line change
@@ -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