Skip to content

Commit 359d60e

Browse files
authored
MPT-14933 E2E for notifications/contacts (#168)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added comprehensive end-to-end tests for contact operations: create, retrieve, list, update, delete, block/unblock, and not-found handling. * Extended coverage for both synchronous and asynchronous workflows; test modules marked as flaky where applicable. * Added fixtures for contact data, created contact (sync/async), created contact ID, and an invalid contact ID for error scenarios. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 7748860 + 972f019 commit 359d60e

File tree

3 files changed

+168
-0
lines changed

3 files changed

+168
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
3+
from tests.e2e.helper import (
4+
async_create_fixture_resource_and_delete,
5+
create_fixture_resource_and_delete,
6+
)
7+
8+
9+
@pytest.fixture
10+
def contact_data(short_uuid):
11+
return {
12+
"name": "E2E delete me",
13+
"firstName": "Will",
14+
"lastName": "Smith",
15+
"email": f"{short_uuid}@example.com",
16+
"optOuts": [],
17+
}
18+
19+
20+
@pytest.fixture
21+
def created_contact(mpt_ops, contact_data):
22+
service = mpt_ops.notifications.contacts
23+
with create_fixture_resource_and_delete(service, contact_data) as contact:
24+
yield contact
25+
26+
27+
@pytest.fixture
28+
async def async_created_contact(async_mpt_ops, contact_data):
29+
service = async_mpt_ops.notifications.contacts
30+
async with async_create_fixture_resource_and_delete(service, contact_data) as contact:
31+
yield contact
32+
33+
34+
@pytest.fixture
35+
def created_contact_id(created_contact):
36+
return created_contact.id
37+
38+
39+
@pytest.fixture
40+
def invalid_contact_id():
41+
return "CON-0000-0000-0000"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import pytest
2+
3+
from mpt_api_client import RQLQuery
4+
from mpt_api_client.exceptions import MPTAPIError
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
def test_create_contact(created_contact): # noqa: AAA01
10+
assert created_contact is not None
11+
12+
13+
async def test_get_contact(async_mpt_ops, created_contact_id):
14+
result = await async_mpt_ops.notifications.contacts.get(created_contact_id)
15+
16+
assert result.id == created_contact_id
17+
18+
19+
async def test_list_contacts(async_mpt_ops, created_contact_id):
20+
iterator = async_mpt_ops.notifications.contacts.filter(
21+
RQLQuery(id=created_contact_id)
22+
).iterate()
23+
24+
result = [contact async for contact in iterator]
25+
26+
assert len(result) == 1
27+
assert result[0].id == created_contact_id
28+
29+
30+
async def test_get_contact_not_found(async_mpt_ops):
31+
service = async_mpt_ops.notifications.contacts
32+
33+
with pytest.raises(MPTAPIError):
34+
await service.get("CON-0000-0000-0000")
35+
36+
37+
async def test_block_unblock_contact(async_mpt_ops, created_contact):
38+
service = async_mpt_ops.notifications.contacts
39+
40+
result_block = await service.block(created_contact.id)
41+
result_unblock = await service.unblock(created_contact.id)
42+
43+
assert result_block.status == "Blocked"
44+
assert result_unblock.status == "Active"
45+
46+
47+
async def test_update_contact(async_mpt_ops, created_contact, short_uuid):
48+
service = async_mpt_ops.notifications.contacts
49+
new_name = f"delete {short_uuid}"
50+
result = await service.update(
51+
created_contact.id,
52+
{
53+
"name": new_name,
54+
},
55+
)
56+
57+
assert result.name == new_name
58+
59+
60+
async def test_delete_contact(async_mpt_ops, created_contact):
61+
service = async_mpt_ops.notifications.contacts
62+
63+
await service.delete(created_contact.id)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import pytest
2+
3+
from mpt_api_client import RQLQuery
4+
from mpt_api_client.exceptions import MPTAPIError
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
def test_created_contact(created_contact): # noqa: AAA01
10+
assert created_contact is not None
11+
12+
13+
def test_get_contact(mpt_ops, created_contact_id):
14+
service = mpt_ops.notifications.contacts
15+
16+
result = service.get(created_contact_id)
17+
18+
assert result.id == created_contact_id
19+
20+
21+
def test_list_contacts(mpt_ops, created_contact_id):
22+
iterator = mpt_ops.notifications.contacts.filter(RQLQuery(id=created_contact_id)).iterate()
23+
24+
result = list(iterator)
25+
26+
assert len(result) == 1
27+
assert result[0].id == created_contact_id
28+
29+
30+
def test_get_contact_not_found(mpt_ops, invalid_contact_id):
31+
service = mpt_ops.notifications.contacts
32+
33+
with pytest.raises(MPTAPIError):
34+
service.get(invalid_contact_id)
35+
36+
37+
def test_block_unblock_contact(mpt_ops, created_contact): # noqa: AAA01
38+
service = mpt_ops.notifications.contacts
39+
40+
result_block = service.block(created_contact.id)
41+
result_unblock = service.unblock(created_contact.id)
42+
43+
assert result_block.status == "Blocked"
44+
assert result_unblock.status == "Active"
45+
46+
47+
def test_update_contact(mpt_ops, created_contact, short_uuid):
48+
service = mpt_ops.notifications.contacts
49+
new_name = f"delete {short_uuid}"
50+
51+
result = service.update(
52+
created_contact.id,
53+
{
54+
"name": new_name,
55+
},
56+
)
57+
58+
assert result.name == new_name
59+
60+
61+
def test_delete_contact(mpt_ops, created_contact_id):
62+
service = mpt_ops.notifications.contacts
63+
64+
service.delete(created_contact_id) # act

0 commit comments

Comments
 (0)