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
1 change: 1 addition & 0 deletions e2e_config.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"commerce.product.listing.id": "LST-5489-0806",
"commerce.product.template.id": "TPL-1767-7355-0002",
"commerce.user.id": "USR-4303-2348",
"helpdesk.chat.id": "CHT-5064-0262-3671",
"commerce.subscription.agreement.id": "AGR-2473-3299-1721",
"commerce.subscription.id": "SUB-3678-1831-2188",
"commerce.subscription.product.item.id": "ITM-1767-7355-0001",
Expand Down
12 changes: 12 additions & 0 deletions mpt_api_client/mpt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
AsyncBilling,
AsyncCatalog,
AsyncCommerce,
AsyncHelpdesk,
AsyncNotifications,
Audit,
Billing,
Catalog,
Commerce,
Helpdesk,
Notifications,
)

Expand Down Expand Up @@ -70,6 +72,11 @@ def notifications(self) -> AsyncNotifications:
"""Notifications MPT API Client."""
return AsyncNotifications(http_client=self.http_client)

@property
def helpdesk(self) -> AsyncHelpdesk:
"""Helpdesk MPT API Client."""
return AsyncHelpdesk(http_client=self.http_client)


class MPTClient:
"""MPT API Client."""
Expand Down Expand Up @@ -128,3 +135,8 @@ def accounts(self) -> Accounts:
def notifications(self) -> Notifications:
"""Notifications MPT API Client."""
return Notifications(http_client=self.http_client)

@property
def helpdesk(self) -> Helpdesk:
"""Helpdesk MPT API Client."""
return Helpdesk(http_client=self.http_client)
3 changes: 3 additions & 0 deletions mpt_api_client/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mpt_api_client.resources.billing import AsyncBilling, Billing
from mpt_api_client.resources.catalog import AsyncCatalog, Catalog
from mpt_api_client.resources.commerce import AsyncCommerce, Commerce
from mpt_api_client.resources.helpdesk import AsyncHelpdesk, Helpdesk
from mpt_api_client.resources.notifications import AsyncNotifications, Notifications

__all__ = [ # noqa: WPS410
Expand All @@ -12,10 +13,12 @@
"AsyncBilling",
"AsyncCatalog",
"AsyncCommerce",
"AsyncHelpdesk",
"AsyncNotifications",
"Audit",
"Billing",
"Catalog",
"Commerce",
"Helpdesk",
"Notifications",
]
3 changes: 3 additions & 0 deletions mpt_api_client/resources/helpdesk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from mpt_api_client.resources.helpdesk.helpdesk import AsyncHelpdesk, Helpdesk

__all__ = ["AsyncHelpdesk", "Helpdesk"] # noqa: WPS410
46 changes: 46 additions & 0 deletions mpt_api_client/resources/helpdesk/chats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCollectionMixin,
AsyncCreateMixin,
AsyncGetMixin,
AsyncUpdateMixin,
CollectionMixin,
CreateMixin,
GetMixin,
UpdateMixin,
)
from mpt_api_client.models import Model


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


class ChatsServiceConfig:
"""Helpdesk Chats service configuration."""

_endpoint = "/public/v1/helpdesk/chats"
_model_class = Chat
_collection_key = "data"


class ChatsService(
CreateMixin[Chat],
UpdateMixin[Chat],
GetMixin[Chat],
CollectionMixin[Chat],
Service[Chat],
ChatsServiceConfig,
):
"""Helpdesk Chats service."""


class AsyncChatsService(
AsyncCreateMixin[Chat],
AsyncUpdateMixin[Chat],
AsyncGetMixin[Chat],
AsyncCollectionMixin[Chat],
AsyncService[Chat],
ChatsServiceConfig,
):
"""Async Helpdesk Chats service."""
26 changes: 26 additions & 0 deletions mpt_api_client/resources/helpdesk/helpdesk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources.helpdesk.chats import AsyncChatsService, ChatsService


class Helpdesk:
"""Helpdesk MPT API Module."""

def __init__(self, http_client: HTTPClient):
self.http_client = http_client

@property
def chats(self) -> ChatsService:
"""Chats service."""
return ChatsService(http_client=self.http_client)


class AsyncHelpdesk:
"""Async Helpdesk MPT API Module."""

def __init__(self, http_client: AsyncHTTPClient):
self.http_client = http_client

@property
def chats(self) -> AsyncChatsService:
"""Async Chats service."""
return AsyncChatsService(http_client=self.http_client)
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions tests/e2e/helpdesk/chats/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest


@pytest.fixture
def chat_id(e2e_config):
return e2e_config["helpdesk.chat.id"]


@pytest.fixture
def invalid_chat_id():
return "CHT-0000-0000-0000"
36 changes: 36 additions & 0 deletions tests/e2e/helpdesk/chats/test_async_chats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest

from mpt_api_client.exceptions import MPTAPIError


async def test_get_chat(async_mpt_ops, chat_id):
service = async_mpt_ops.helpdesk.chats

result = await service.get(chat_id)

assert result.id == chat_id


async def test_list_chats(async_mpt_ops):
service = async_mpt_ops.helpdesk.chats

result = await service.fetch_page(limit=1)

assert len(result) > 0


async def test_update_chat(async_mpt_ops, chat_id, short_uuid):
service = async_mpt_ops.helpdesk.chats
new_description = f"e2e update {short_uuid}"

result = await service.update(chat_id, {"description": new_description})

assert result.id == chat_id
assert result.to_dict().get("description") == new_description


async def test_not_found(async_mpt_ops, invalid_chat_id):
service = async_mpt_ops.helpdesk.chats

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

from mpt_api_client.exceptions import MPTAPIError


def test_get_chat(mpt_ops, chat_id):
service = mpt_ops.helpdesk.chats

result = service.get(chat_id)

assert result.id == chat_id


def test_list_chats(mpt_ops):
service = mpt_ops.helpdesk.chats

result = service.fetch_page(limit=1)

assert len(result) > 0


def test_update_chat(mpt_ops, chat_id, short_uuid):
service = mpt_ops.helpdesk.chats
new_description = f"e2e update {short_uuid}"

result = service.update(chat_id, {"description": new_description})

assert result.id == chat_id
assert result.to_dict().get("description") == new_description


def test_not_found(mpt_ops, invalid_chat_id):
service = mpt_ops.helpdesk.chats

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

from mpt_api_client.resources.helpdesk.chats import AsyncChatsService, ChatsService


@pytest.fixture
def chats_service(http_client):
return ChatsService(http_client=http_client)


@pytest.fixture
def async_chats_service(async_http_client):
return AsyncChatsService(http_client=async_http_client)


@pytest.mark.parametrize(
"method",
["get", "create", "update", "iterate"],
)
def test_mixins_present(chats_service, method):
result = hasattr(chats_service, method)

assert result is True


@pytest.mark.parametrize(
"method",
["get", "create", "update", "iterate"],
)
def test_async_mixins_present(async_chats_service, method):
result = hasattr(async_chats_service, method)

assert result is True
46 changes: 46 additions & 0 deletions tests/unit/resources/helpdesk/test_helpdesk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest

from mpt_api_client.resources.helpdesk import AsyncHelpdesk, Helpdesk
from mpt_api_client.resources.helpdesk.chats import AsyncChatsService, ChatsService


def test_helpdesk_init(http_client):
result = Helpdesk(http_client=http_client)

assert isinstance(result, Helpdesk)
assert result.http_client is http_client


def test_async_helpdesk_init(async_http_client):
result = AsyncHelpdesk(http_client=async_http_client)

assert isinstance(result, AsyncHelpdesk)
assert result.http_client is async_http_client


@pytest.mark.parametrize(
("attr_name", "expected"),
[
("chats", ChatsService),
],
)
def test_helpdesk_properties(http_client, attr_name, expected):
helpdesk = Helpdesk(http_client=http_client)

result = getattr(helpdesk, attr_name)

assert isinstance(result, expected)


@pytest.mark.parametrize(
("attr_name", "expected"),
[
("chats", AsyncChatsService),
],
)
def test_async_helpdesk_properties(async_http_client, attr_name, expected):
helpdesk = AsyncHelpdesk(http_client=async_http_client)

result = getattr(helpdesk, attr_name)

assert isinstance(result, expected)
4 changes: 4 additions & 0 deletions tests/unit/test_mpt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
AsyncBilling,
AsyncCatalog,
AsyncCommerce,
AsyncHelpdesk,
AsyncNotifications,
Audit,
Billing,
Catalog,
Commerce,
Helpdesk,
Notifications,
)
from tests.unit.conftest import API_TOKEN, API_URL
Expand All @@ -32,6 +34,7 @@ def get_mpt_client():
("billing", Billing),
("accounts", Accounts),
("notifications", Notifications),
("helpdesk", Helpdesk),
],
)
def test_mpt_client(resource_name: str, expected_type: type) -> None:
Expand Down Expand Up @@ -62,6 +65,7 @@ def test_mpt_client_env(monkeypatch: pytest.MonkeyPatch) -> None:
("billing", AsyncBilling),
("accounts", AsyncAccounts),
("notifications", AsyncNotifications),
("helpdesk", AsyncHelpdesk),
],
)
def test_async_mpt_client(resource_name: str, expected_type: type) -> None:
Expand Down
Loading