Skip to content

Commit ca33fd5

Browse files
committed
feat: add helpdesk channel api services and tests
1 parent 676f1c1 commit ca33fd5

File tree

12 files changed

+416
-0
lines changed

12 files changed

+416
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import AsyncCollectionMixin, CollectionMixin
3+
from mpt_api_client.resources.helpdesk.chat_messages import ChatMessage
4+
5+
6+
class ChannelMessagesServiceConfig:
7+
"""Helpdesk channel messages service configuration."""
8+
9+
_endpoint = "/public/v1/helpdesk/channels/{channel_id}/messages"
10+
_model_class = ChatMessage
11+
_collection_key = "data"
12+
13+
14+
class ChannelMessagesService(
15+
CollectionMixin[ChatMessage],
16+
Service[ChatMessage],
17+
ChannelMessagesServiceConfig,
18+
):
19+
"""Helpdesk channel messages service."""
20+
21+
22+
class AsyncChannelMessagesService(
23+
AsyncCollectionMixin[ChatMessage],
24+
AsyncService[ChatMessage],
25+
ChannelMessagesServiceConfig,
26+
):
27+
"""Async helpdesk channel messages service."""
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from mpt_api_client.http import AsyncService, Service, mixins
2+
from mpt_api_client.models import Model
3+
from mpt_api_client.resources.helpdesk.channel_messages import (
4+
AsyncChannelMessagesService,
5+
ChannelMessagesService,
6+
)
7+
8+
9+
class Channel(Model):
10+
"""Helpdesk Channel resource."""
11+
12+
13+
class ChannelsServiceConfig:
14+
"""Helpdesk Channels service configuration."""
15+
16+
_endpoint = "/public/v1/helpdesk/channels"
17+
_model_class = Channel
18+
_collection_key = "data"
19+
20+
21+
class ChannelsService(
22+
mixins.CreateMixin[Channel],
23+
mixins.UpdateMixin[Channel],
24+
mixins.GetMixin[Channel],
25+
mixins.DeleteMixin,
26+
mixins.CollectionMixin[Channel],
27+
Service[Channel],
28+
ChannelsServiceConfig,
29+
):
30+
"""Helpdesk Channels service."""
31+
32+
def messages(self, channel_id: str) -> ChannelMessagesService:
33+
"""Return channel messages service."""
34+
return ChannelMessagesService(
35+
http_client=self.http_client,
36+
endpoint_params={"channel_id": channel_id},
37+
)
38+
39+
40+
class AsyncChannelsService(
41+
mixins.AsyncCreateMixin[Channel],
42+
mixins.AsyncUpdateMixin[Channel],
43+
mixins.AsyncGetMixin[Channel],
44+
mixins.AsyncDeleteMixin,
45+
mixins.AsyncCollectionMixin[Channel],
46+
AsyncService[Channel],
47+
ChannelsServiceConfig,
48+
):
49+
"""Async Helpdesk Channels service."""
50+
51+
def messages(self, channel_id: str) -> AsyncChannelMessagesService:
52+
"""Return async channel messages service."""
53+
return AsyncChannelMessagesService(
54+
http_client=self.http_client,
55+
endpoint_params={"channel_id": channel_id},
56+
)

mpt_api_client/resources/helpdesk/helpdesk.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
22
from mpt_api_client.resources.helpdesk.cases import AsyncCasesService, CasesService
3+
from mpt_api_client.resources.helpdesk.channels import AsyncChannelsService, ChannelsService
34
from mpt_api_client.resources.helpdesk.chats import AsyncChatsService, ChatsService
45
from mpt_api_client.resources.helpdesk.parameter_groups import (
56
AsyncParameterGroupsService,
@@ -23,6 +24,11 @@ def chats(self) -> ChatsService:
2324
"""Chats service."""
2425
return ChatsService(http_client=self.http_client)
2526

27+
@property
28+
def channels(self) -> ChannelsService:
29+
"""Channels service."""
30+
return ChannelsService(http_client=self.http_client)
31+
2632
@property
2733
def cases(self) -> CasesService:
2834
"""Cases service."""
@@ -55,6 +61,11 @@ def chats(self) -> AsyncChatsService:
5561
"""Async Chats service."""
5662
return AsyncChatsService(http_client=self.http_client)
5763

64+
@property
65+
def channels(self) -> AsyncChannelsService:
66+
"""Async Channels service."""
67+
return AsyncChannelsService(http_client=self.http_client)
68+
5869
@property
5970
def cases(self) -> AsyncCasesService:
6071
"""Async Cases service."""
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 channel_id(e2e_config):
11+
return e2e_config["helpdesk.channel.id"]
12+
13+
14+
@pytest.fixture
15+
def invalid_channel_id():
16+
return "CHN-0000-0000-0000"
17+
18+
19+
@pytest.fixture
20+
def channel_data(short_uuid):
21+
return {"name": f"E2E Channel {short_uuid}"}
22+
23+
24+
@pytest.fixture
25+
def created_channel(mpt_ops, channel_data):
26+
with create_fixture_resource_and_delete(mpt_ops.helpdesk.channels, channel_data) as channel:
27+
yield channel
28+
29+
30+
@pytest.fixture
31+
async def async_created_channel(async_mpt_ops, channel_data):
32+
async with async_create_fixture_resource_and_delete(
33+
async_mpt_ops.helpdesk.channels, channel_data
34+
) as channel:
35+
yield channel
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def channel_messages_service(mpt_ops, channel_id):
6+
return mpt_ops.helpdesk.channels.messages(channel_id)
7+
8+
9+
@pytest.fixture
10+
def async_channel_messages_service(async_mpt_ops, channel_id):
11+
return async_mpt_ops.helpdesk.channels.messages(channel_id)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
5+
pytestmark = [pytest.mark.flaky]
6+
7+
8+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
9+
async def test_list_channel_messages(async_channel_messages_service):
10+
result = await async_channel_messages_service.fetch_page(limit=1)
11+
12+
assert len(result) > 0
13+
14+
15+
async def test_list_channel_messages_not_found(async_mpt_ops, invalid_channel_id):
16+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
17+
await async_mpt_ops.helpdesk.channels.messages(invalid_channel_id).fetch_page(limit=1)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
5+
pytestmark = [pytest.mark.flaky]
6+
7+
8+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
9+
def test_list_channel_messages(channel_messages_service):
10+
result = channel_messages_service.fetch_page(limit=1)
11+
12+
assert len(result) > 0
13+
14+
15+
def test_list_channel_messages_not_found(mpt_ops, invalid_channel_id):
16+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
17+
mpt_ops.helpdesk.channels.messages(invalid_channel_id).fetch_page(limit=1)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
5+
pytestmark = [pytest.mark.flaky]
6+
7+
8+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
9+
async def test_get_channel(async_mpt_ops, channel_id):
10+
service = async_mpt_ops.helpdesk.channels
11+
12+
result = await service.get(channel_id)
13+
14+
assert result.id == channel_id
15+
16+
17+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
18+
async def test_list_channels(async_mpt_ops):
19+
service = async_mpt_ops.helpdesk.channels
20+
21+
result = await service.fetch_page(limit=1)
22+
23+
assert len(result) > 0
24+
25+
26+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
27+
def test_create_channel(async_created_channel):
28+
result = async_created_channel
29+
30+
assert result.id is not None
31+
32+
33+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
34+
async def test_update_channel(async_mpt_ops, async_created_channel, short_uuid):
35+
service = async_mpt_ops.helpdesk.channels
36+
new_name = f"E2E Updated Channel {short_uuid}"
37+
38+
result = await service.update(async_created_channel.id, {"name": new_name})
39+
40+
assert result.id == async_created_channel.id
41+
assert result.to_dict().get("name") == new_name
42+
43+
44+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
45+
async def test_delete_channel(async_mpt_ops, async_created_channel):
46+
result = async_created_channel
47+
48+
await async_mpt_ops.helpdesk.channels.delete(result.id)
49+
50+
51+
async def test_not_found(async_mpt_ops, invalid_channel_id):
52+
service = async_mpt_ops.helpdesk.channels
53+
54+
with pytest.raises(MPTAPIError):
55+
await service.get(invalid_channel_id)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
5+
pytestmark = [pytest.mark.flaky]
6+
7+
8+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
9+
def test_get_channel(mpt_ops, channel_id):
10+
service = mpt_ops.helpdesk.channels
11+
12+
result = service.get(channel_id)
13+
14+
assert result.id == channel_id
15+
16+
17+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
18+
def test_list_channels(mpt_ops):
19+
service = mpt_ops.helpdesk.channels
20+
21+
result = service.fetch_page(limit=1)
22+
23+
assert len(result) > 0
24+
25+
26+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
27+
def test_create_channel(created_channel):
28+
result = created_channel
29+
30+
assert result.id is not None
31+
32+
33+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
34+
def test_update_channel(mpt_ops, created_channel, short_uuid):
35+
service = mpt_ops.helpdesk.channels
36+
new_name = f"E2E Updated Channel {short_uuid}"
37+
38+
result = service.update(created_channel.id, {"name": new_name})
39+
40+
assert result.id == created_channel.id
41+
assert result.to_dict().get("name") == new_name
42+
43+
44+
@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
45+
def test_delete_channel(mpt_ops, created_channel):
46+
result = created_channel
47+
48+
mpt_ops.helpdesk.channels.delete(result.id)
49+
50+
51+
def test_not_found(mpt_ops, invalid_channel_id):
52+
service = mpt_ops.helpdesk.channels
53+
54+
with pytest.raises(MPTAPIError):
55+
service.get(invalid_channel_id)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.helpdesk.channel_messages import (
4+
AsyncChannelMessagesService,
5+
ChannelMessagesService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def channel_messages_service(http_client) -> ChannelMessagesService:
11+
return ChannelMessagesService(
12+
http_client=http_client, endpoint_params={"channel_id": "CHN-0000-0000-0001"}
13+
)
14+
15+
16+
@pytest.fixture
17+
def async_channel_messages_service(async_http_client) -> AsyncChannelMessagesService:
18+
return AsyncChannelMessagesService(
19+
http_client=async_http_client,
20+
endpoint_params={"channel_id": "CHN-0000-0000-0001"},
21+
)
22+
23+
24+
def test_endpoint(channel_messages_service) -> None:
25+
result = (
26+
channel_messages_service.path == "/public/v1/helpdesk/channels/CHN-0000-0000-0001/messages"
27+
)
28+
29+
assert result is True
30+
31+
32+
def test_async_endpoint(async_channel_messages_service) -> None:
33+
result = (
34+
async_channel_messages_service.path
35+
== "/public/v1/helpdesk/channels/CHN-0000-0000-0001/messages"
36+
)
37+
38+
assert result is True
39+
40+
41+
@pytest.mark.parametrize("method", ["fetch_page", "iterate"])
42+
def test_methods_present(channel_messages_service, method: str) -> None:
43+
result = hasattr(channel_messages_service, method)
44+
45+
assert result is True
46+
47+
48+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
49+
def test_methods_absent(channel_messages_service, method: str) -> None:
50+
result = hasattr(channel_messages_service, method)
51+
52+
assert result is False
53+
54+
55+
@pytest.mark.parametrize("method", ["fetch_page", "iterate"])
56+
def test_async_methods_present(async_channel_messages_service, method: str) -> None:
57+
result = hasattr(async_channel_messages_service, method)
58+
59+
assert result is True
60+
61+
62+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
63+
def test_async_methods_absent(async_channel_messages_service, method: str) -> None:
64+
result = hasattr(async_channel_messages_service, method)
65+
66+
assert result is False

0 commit comments

Comments
 (0)