Skip to content

Commit 2bf0eb1

Browse files
authored
Merge pull request #303
MPT-20245 update fixtures and tests for chat participants, unskip tests
2 parents 78e264a + d8503a3 commit 2bf0eb1

File tree

5 files changed

+53
-45
lines changed

5 files changed

+53
-45
lines changed

e2e_config.test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@
6969
"notifications.subscriber.id": "NTS-0829-7123-7123",
7070
"integration.extension.id": "EXT-6587-4477",
7171
"integration.term.id": "ETC-6587-4477-0062",
72-
"program.program.id": "PRG-9643-3741"
72+
"program.program.id": "PRG-9643-3741",
73+
"notifications.contact.id": "CTT-0001-9158"
7374
}

mpt_api_client/models/model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from mpt_api_client.models.meta import Meta
99
from mpt_api_client.models.model_collection import ModelCollection
1010

11-
ResourceData = dict[str, Any]
11+
Resource = dict[str, Any]
12+
ResourceData = Resource | list[Resource]
1213

1314

1415
_SNAKE_CASE_BOUNDARY = re.compile(r"([a-z0-9])([A-Z])")
@@ -158,7 +159,7 @@ def __setattr__(self, name: str, value: Any) -> None:
158159
processed_value = self._process_value(value, target_class=target_class)
159160
object.__setattr__(self, snake_name, processed_value)
160161

161-
def to_dict(self) -> dict[str, Any]:
162+
def to_dict(self) -> Resource:
162163
"""Returns the resource as a dictionary with original API keys."""
163164
out_dict = {}
164165

@@ -219,7 +220,7 @@ class Model(BaseModel):
219220
id: str
220221

221222
def __init__(
222-
self, resource_data: ResourceData | None = None, meta: Meta | None = None, **kwargs: Any
223+
self, resource_data: Resource | None = None, meta: Meta | None = None, **kwargs: Any
223224
) -> None:
224225
object.__setattr__(self, "meta", meta)
225226
data = dict(resource_data or {})

tests/e2e/helpdesk/chats/participants/conftest.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import pytest
22

3-
from tests.e2e.helper import (
4-
async_create_fixture_resource_and_delete,
5-
create_fixture_resource_and_delete,
6-
)
7-
83

94
@pytest.fixture
105
def chat_participants_service(mpt_ops, created_chat):
@@ -17,27 +12,23 @@ def async_chat_participants_service(async_mpt_ops, created_chat):
1712

1813

1914
@pytest.fixture
20-
def chat_participant_data(account_id, user_id):
21-
return {
22-
"identity": {"id": user_id},
23-
"account": {"id": account_id},
24-
}
15+
def contact_id(e2e_config):
16+
return e2e_config["notifications.contact.id"]
17+
18+
19+
@pytest.fixture
20+
def chat_participant_data(contact_id):
21+
return {"contact": {"id": contact_id}}
2522

2623

2724
@pytest.fixture
2825
def created_chat_participant(chat_participants_service, chat_participant_data):
29-
with create_fixture_resource_and_delete(
30-
chat_participants_service, chat_participant_data
31-
) as chat_participant:
32-
yield chat_participant
26+
return chat_participants_service.create([chat_participant_data])
3327

3428

3529
@pytest.fixture
3630
async def async_created_chat_participant(async_chat_participants_service, chat_participant_data):
37-
async with async_create_fixture_resource_and_delete(
38-
async_chat_participants_service, chat_participant_data
39-
) as chat_participant:
40-
yield chat_participant
31+
return await async_chat_participants_service.create([chat_participant_data])
4132

4233

4334
@pytest.fixture(scope="session")

tests/e2e/helpdesk/chats/participants/test_async_participants.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.models import ModelCollection
67
from mpt_api_client.resources.helpdesk.chat_participants import ChatParticipant
78

89
pytestmark = [pytest.mark.flaky]
@@ -15,30 +16,35 @@ async def test_list_chat_participants(async_chat_participants_service):
1516
assert all(isinstance(participant, ChatParticipant) for participant in result)
1617

1718

18-
@pytest.mark.skip(reason="Unskip after MPT-20015 completed") # noqa: AAA01
19-
def test_create_chat_participant(async_created_chat_participant):
20-
assert isinstance(async_created_chat_participant, ChatParticipant)
19+
def test_create_chat_participant(async_created_chat_participant, contact_id): # noqa: AAA01
20+
assert isinstance(async_created_chat_participant, ModelCollection)
21+
assert all(isinstance(cp, ChatParticipant) for cp in async_created_chat_participant)
22+
chat_participants_list = async_created_chat_participant.to_list()
23+
assert any(cp["contact"]["id"] == contact_id for cp in chat_participants_list)
2124

2225

23-
@pytest.mark.skip(reason="Unskip after MPT-20015 completed")
2426
async def test_update_chat_participant(
2527
async_chat_participants_service, async_created_chat_participant
2628
):
27-
result = await async_chat_participants_service.update(
28-
async_created_chat_participant.id,
29-
{"status": "Active"},
30-
)
29+
chat_participant = async_created_chat_participant[0].to_dict()
30+
new_muted_status = not chat_participant["muted"]
31+
chat_participant["muted"] = new_muted_status
32+
33+
result = await async_chat_participants_service.update(chat_participant["id"], chat_participant)
3134

32-
assert isinstance(result, ChatParticipant)
35+
assert result.to_dict().get("muted") == new_muted_status
3336

3437

35-
@pytest.mark.skip(reason="Unskip after MPT-20015 completed")
3638
async def test_delete_chat_participant(
37-
async_chat_participants_service, async_created_chat_participant
39+
async_chat_participants_service, async_created_chat_participant, contact_id
3840
):
39-
result = async_created_chat_participant
41+
result = next(
42+
chat_participant
43+
for chat_participant in async_created_chat_participant.to_list()
44+
if chat_participant["contact"]["id"] == contact_id
45+
)
4046

41-
await async_chat_participants_service.delete(result.id)
47+
await async_chat_participants_service.delete(result["id"])
4248

4349

4450
async def test_update_chat_participant_not_found(

tests/e2e/helpdesk/chats/participants/test_sync_participants.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from mpt_api_client.exceptions import MPTAPIError
6+
from mpt_api_client.models import ModelCollection
67
from mpt_api_client.resources.helpdesk.chat_participants import ChatParticipant
78

89
pytestmark = [pytest.mark.flaky]
@@ -15,23 +16,31 @@ def test_list_chat_participants(chat_participants_service):
1516
assert all(isinstance(participant, ChatParticipant) for participant in result)
1617

1718

18-
@pytest.mark.skip(reason="Unskip after MPT-20015 completed") # noqa: AAA01
19-
def test_create_chat_participant(created_chat_participant):
20-
assert isinstance(created_chat_participant, ChatParticipant)
19+
def test_create_chat_participant(created_chat_participant, contact_id): # noqa: AAA01
20+
assert isinstance(created_chat_participant, ModelCollection)
21+
assert all(isinstance(cp, ChatParticipant) for cp in created_chat_participant)
22+
chat_participants_list = created_chat_participant.to_list()
23+
assert any(cp["contact"]["id"] == contact_id for cp in chat_participants_list)
2124

2225

23-
@pytest.mark.skip(reason="Unskip after MPT-20015 completed")
2426
def test_update_chat_participant(chat_participants_service, created_chat_participant):
25-
result = chat_participants_service.update(created_chat_participant.id, {"status": "Active"})
27+
chat_participant = created_chat_participant[0].to_dict()
28+
new_muted_status = not chat_participant["muted"]
29+
chat_participant["muted"] = new_muted_status
2630

27-
assert isinstance(result, ChatParticipant)
31+
result = chat_participants_service.update(chat_participant["id"], chat_participant)
2832

33+
assert result.to_dict().get("muted") == new_muted_status
2934

30-
@pytest.mark.skip(reason="Unskip after MPT-20015 completed")
31-
def test_delete_chat_participant(chat_participants_service, created_chat_participant):
32-
result = created_chat_participant
3335

34-
chat_participants_service.delete(result.id)
36+
def test_delete_chat_participant(chat_participants_service, created_chat_participant, contact_id):
37+
result = next(
38+
chat_participant
39+
for chat_participant in created_chat_participant.to_list()
40+
if chat_participant["contact"]["id"] == contact_id
41+
)
42+
43+
chat_participants_service.delete(result["id"])
3544

3645

3746
def test_update_chat_participant_not_found(chat_participants_service, invalid_chat_participant_id):

0 commit comments

Comments
 (0)