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
27 changes: 27 additions & 0 deletions mpt_api_client/resources/helpdesk/channel_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import AsyncCollectionMixin, CollectionMixin
from mpt_api_client.resources.helpdesk.chat_messages import ChatMessage


class ChannelMessagesServiceConfig:
"""Helpdesk channel messages service configuration."""

_endpoint = "/public/v1/helpdesk/channels/{channel_id}/messages"
_model_class = ChatMessage
_collection_key = "data"


class ChannelMessagesService(
CollectionMixin[ChatMessage],
Service[ChatMessage],
ChannelMessagesServiceConfig,
):
"""Helpdesk channel messages service."""


class AsyncChannelMessagesService(
AsyncCollectionMixin[ChatMessage],
AsyncService[ChatMessage],
ChannelMessagesServiceConfig,
):
"""Async helpdesk channel messages service."""
56 changes: 56 additions & 0 deletions mpt_api_client/resources/helpdesk/channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from mpt_api_client.http import AsyncService, Service, mixins
from mpt_api_client.models import Model
from mpt_api_client.resources.helpdesk.channel_messages import (
AsyncChannelMessagesService,
ChannelMessagesService,
)


class Channel(Model):
"""Helpdesk Channel resource."""


class ChannelsServiceConfig:
"""Helpdesk Channels service configuration."""

_endpoint = "/public/v1/helpdesk/channels"
_model_class = Channel
_collection_key = "data"


class ChannelsService(
mixins.CreateMixin[Channel],
mixins.UpdateMixin[Channel],
mixins.GetMixin[Channel],
mixins.DeleteMixin,
mixins.CollectionMixin[Channel],
Service[Channel],
ChannelsServiceConfig,
):
"""Helpdesk Channels service."""

def messages(self, channel_id: str) -> ChannelMessagesService:
"""Return channel messages service."""
return ChannelMessagesService(
http_client=self.http_client,
endpoint_params={"channel_id": channel_id},
)


class AsyncChannelsService(
mixins.AsyncCreateMixin[Channel],
mixins.AsyncUpdateMixin[Channel],
mixins.AsyncGetMixin[Channel],
mixins.AsyncDeleteMixin,
mixins.AsyncCollectionMixin[Channel],
AsyncService[Channel],
ChannelsServiceConfig,
):
"""Async Helpdesk Channels service."""

def messages(self, channel_id: str) -> AsyncChannelMessagesService:
"""Return async channel messages service."""
return AsyncChannelMessagesService(
http_client=self.http_client,
endpoint_params={"channel_id": channel_id},
)
11 changes: 11 additions & 0 deletions mpt_api_client/resources/helpdesk/helpdesk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources.helpdesk.cases import AsyncCasesService, CasesService
from mpt_api_client.resources.helpdesk.channels import AsyncChannelsService, ChannelsService
from mpt_api_client.resources.helpdesk.chats import AsyncChatsService, ChatsService
from mpt_api_client.resources.helpdesk.parameter_groups import (
AsyncParameterGroupsService,
Expand All @@ -23,6 +24,11 @@ def chats(self) -> ChatsService:
"""Chats service."""
return ChatsService(http_client=self.http_client)

@property
def channels(self) -> ChannelsService:
"""Channels service."""
return ChannelsService(http_client=self.http_client)

@property
def cases(self) -> CasesService:
"""Cases service."""
Expand Down Expand Up @@ -55,6 +61,11 @@ def chats(self) -> AsyncChatsService:
"""Async Chats service."""
return AsyncChatsService(http_client=self.http_client)

@property
def channels(self) -> AsyncChannelsService:
"""Async Channels service."""
return AsyncChannelsService(http_client=self.http_client)

@property
def cases(self) -> AsyncCasesService:
"""Async Cases service."""
Expand Down
35 changes: 35 additions & 0 deletions tests/e2e/helpdesk/channels/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest

from tests.e2e.helper import (
async_create_fixture_resource_and_delete,
create_fixture_resource_and_delete,
)


@pytest.fixture
def channel_id(e2e_config):
return e2e_config["helpdesk.channel.id"]


@pytest.fixture
def invalid_channel_id():
return "CHN-0000-0000-0000"


@pytest.fixture
def channel_data(short_uuid):
return {"name": f"E2E Channel {short_uuid}"}


@pytest.fixture
def created_channel(mpt_ops, channel_data):
with create_fixture_resource_and_delete(mpt_ops.helpdesk.channels, channel_data) as channel:
yield channel


@pytest.fixture
async def async_created_channel(async_mpt_ops, channel_data):
async with async_create_fixture_resource_and_delete(
async_mpt_ops.helpdesk.channels, channel_data
) as channel:
yield channel
11 changes: 11 additions & 0 deletions tests/e2e/helpdesk/channels/messages/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest


@pytest.fixture
def channel_messages_service(mpt_ops, channel_id):
return mpt_ops.helpdesk.channels.messages(channel_id)


@pytest.fixture
def async_channel_messages_service(async_mpt_ops, channel_id):
return async_mpt_ops.helpdesk.channels.messages(channel_id)
17 changes: 17 additions & 0 deletions tests/e2e/helpdesk/channels/messages/test_async_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from mpt_api_client.exceptions import MPTAPIError

pytestmark = [pytest.mark.flaky]


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
async def test_list_channel_messages(async_channel_messages_service):
result = await async_channel_messages_service.fetch_page(limit=1)

assert len(result) > 0


async def test_list_channel_messages_not_found(async_mpt_ops, invalid_channel_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await async_mpt_ops.helpdesk.channels.messages(invalid_channel_id).fetch_page(limit=1)
17 changes: 17 additions & 0 deletions tests/e2e/helpdesk/channels/messages/test_sync_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from mpt_api_client.exceptions import MPTAPIError

pytestmark = [pytest.mark.flaky]


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
def test_list_channel_messages(channel_messages_service):
result = channel_messages_service.fetch_page(limit=1)

assert len(result) > 0


def test_list_channel_messages_not_found(mpt_ops, invalid_channel_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
mpt_ops.helpdesk.channels.messages(invalid_channel_id).fetch_page(limit=1)
55 changes: 55 additions & 0 deletions tests/e2e/helpdesk/channels/test_async_channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest

from mpt_api_client.exceptions import MPTAPIError

pytestmark = [pytest.mark.flaky]


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
async def test_get_channel(async_mpt_ops, channel_id):
service = async_mpt_ops.helpdesk.channels

result = await service.get(channel_id)

assert result.id == channel_id


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
async def test_list_channels(async_mpt_ops):
service = async_mpt_ops.helpdesk.channels

result = await service.fetch_page(limit=1)

assert len(result) > 0


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
def test_create_channel(async_created_channel):
result = async_created_channel

assert result.id is not None


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
async def test_update_channel(async_mpt_ops, async_created_channel, short_uuid):
service = async_mpt_ops.helpdesk.channels
new_name = f"E2E Updated Channel {short_uuid}"

result = await service.update(async_created_channel.id, {"name": new_name})

assert result.id == async_created_channel.id
assert result.to_dict().get("name") == new_name


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
async def test_delete_channel(async_mpt_ops, async_created_channel):
result = async_created_channel

await async_mpt_ops.helpdesk.channels.delete(result.id)


async def test_not_found(async_mpt_ops, invalid_channel_id):
service = async_mpt_ops.helpdesk.channels

with pytest.raises(MPTAPIError):
await service.get(invalid_channel_id)
55 changes: 55 additions & 0 deletions tests/e2e/helpdesk/channels/test_sync_channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest

from mpt_api_client.exceptions import MPTAPIError

pytestmark = [pytest.mark.flaky]


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
def test_get_channel(mpt_ops, channel_id):
service = mpt_ops.helpdesk.channels

result = service.get(channel_id)

assert result.id == channel_id


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
def test_list_channels(mpt_ops):
service = mpt_ops.helpdesk.channels

result = service.fetch_page(limit=1)

assert len(result) > 0


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
def test_create_channel(created_channel):
result = created_channel

assert result.id is not None


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
def test_update_channel(mpt_ops, created_channel, short_uuid):
service = mpt_ops.helpdesk.channels
new_name = f"E2E Updated Channel {short_uuid}"

result = service.update(created_channel.id, {"name": new_name})

assert result.id == created_channel.id
assert result.to_dict().get("name") == new_name


@pytest.mark.skip(reason="Unskip after MPT-19124 completed")
def test_delete_channel(mpt_ops, created_channel):
result = created_channel

mpt_ops.helpdesk.channels.delete(result.id)


def test_not_found(mpt_ops, invalid_channel_id):
service = mpt_ops.helpdesk.channels

with pytest.raises(MPTAPIError):
service.get(invalid_channel_id)
66 changes: 66 additions & 0 deletions tests/unit/resources/helpdesk/test_channel_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import pytest

from mpt_api_client.resources.helpdesk.channel_messages import (
AsyncChannelMessagesService,
ChannelMessagesService,
)


@pytest.fixture
def channel_messages_service(http_client) -> ChannelMessagesService:
return ChannelMessagesService(
http_client=http_client, endpoint_params={"channel_id": "CHN-0000-0000-0001"}
)


@pytest.fixture
def async_channel_messages_service(async_http_client) -> AsyncChannelMessagesService:
return AsyncChannelMessagesService(
http_client=async_http_client,
endpoint_params={"channel_id": "CHN-0000-0000-0001"},
)


def test_endpoint(channel_messages_service) -> None:
result = (
channel_messages_service.path == "/public/v1/helpdesk/channels/CHN-0000-0000-0001/messages"
)

assert result is True


def test_async_endpoint(async_channel_messages_service) -> None:
result = (
async_channel_messages_service.path
== "/public/v1/helpdesk/channels/CHN-0000-0000-0001/messages"
)

assert result is True


@pytest.mark.parametrize("method", ["fetch_page", "iterate"])
def test_methods_present(channel_messages_service, method: str) -> None:
result = hasattr(channel_messages_service, method)

assert result is True


@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
def test_methods_absent(channel_messages_service, method: str) -> None:
result = hasattr(channel_messages_service, method)

assert result is False


@pytest.mark.parametrize("method", ["fetch_page", "iterate"])
def test_async_methods_present(async_channel_messages_service, method: str) -> None:
result = hasattr(async_channel_messages_service, method)

assert result is True


@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
def test_async_methods_absent(async_channel_messages_service, method: str) -> None:
result = hasattr(async_channel_messages_service, method)

assert result is False
Loading
Loading