Skip to content

Commit f0bf751

Browse files
authored
Merge pull request #227
MPT-18371 Helpdesk Chats core
2 parents 046a5fb + bf74d41 commit f0bf751

File tree

15 files changed

+257
-0
lines changed

15 files changed

+257
-0
lines changed

e2e_config.test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"commerce.product.listing.id": "LST-5489-0806",
5757
"commerce.product.template.id": "TPL-1767-7355-0002",
5858
"commerce.user.id": "USR-4303-2348",
59+
"helpdesk.chat.id": "CHT-5064-0262-3671",
5960
"commerce.subscription.agreement.id": "AGR-2473-3299-1721",
6061
"commerce.subscription.id": "SUB-3678-1831-2188",
6162
"commerce.subscription.product.item.id": "ITM-1767-7355-0001",

mpt_api_client/mpt_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
AsyncBilling,
99
AsyncCatalog,
1010
AsyncCommerce,
11+
AsyncHelpdesk,
1112
AsyncNotifications,
1213
Audit,
1314
Billing,
1415
Catalog,
1516
Commerce,
17+
Helpdesk,
1618
Notifications,
1719
)
1820

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

75+
@property
76+
def helpdesk(self) -> AsyncHelpdesk:
77+
"""Helpdesk MPT API Client."""
78+
return AsyncHelpdesk(http_client=self.http_client)
79+
7380

7481
class MPTClient:
7582
"""MPT API Client."""
@@ -128,3 +135,8 @@ def accounts(self) -> Accounts:
128135
def notifications(self) -> Notifications:
129136
"""Notifications MPT API Client."""
130137
return Notifications(http_client=self.http_client)
138+
139+
@property
140+
def helpdesk(self) -> Helpdesk:
141+
"""Helpdesk MPT API Client."""
142+
return Helpdesk(http_client=self.http_client)

mpt_api_client/resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from mpt_api_client.resources.billing import AsyncBilling, Billing
44
from mpt_api_client.resources.catalog import AsyncCatalog, Catalog
55
from mpt_api_client.resources.commerce import AsyncCommerce, Commerce
6+
from mpt_api_client.resources.helpdesk import AsyncHelpdesk, Helpdesk
67
from mpt_api_client.resources.notifications import AsyncNotifications, Notifications
78

89
__all__ = [ # noqa: WPS410
@@ -12,10 +13,12 @@
1213
"AsyncBilling",
1314
"AsyncCatalog",
1415
"AsyncCommerce",
16+
"AsyncHelpdesk",
1517
"AsyncNotifications",
1618
"Audit",
1719
"Billing",
1820
"Catalog",
1921
"Commerce",
22+
"Helpdesk",
2023
"Notifications",
2124
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from mpt_api_client.resources.helpdesk.helpdesk import AsyncHelpdesk, Helpdesk
2+
3+
__all__ = ["AsyncHelpdesk", "Helpdesk"] # noqa: WPS410
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCollectionMixin,
4+
AsyncCreateMixin,
5+
AsyncGetMixin,
6+
AsyncUpdateMixin,
7+
CollectionMixin,
8+
CreateMixin,
9+
GetMixin,
10+
UpdateMixin,
11+
)
12+
from mpt_api_client.models import Model
13+
14+
15+
class Chat(Model):
16+
"""Helpdesk Chat resource."""
17+
18+
19+
class ChatsServiceConfig:
20+
"""Helpdesk Chats service configuration."""
21+
22+
_endpoint = "/public/v1/helpdesk/chats"
23+
_model_class = Chat
24+
_collection_key = "data"
25+
26+
27+
class ChatsService(
28+
CreateMixin[Chat],
29+
UpdateMixin[Chat],
30+
GetMixin[Chat],
31+
CollectionMixin[Chat],
32+
Service[Chat],
33+
ChatsServiceConfig,
34+
):
35+
"""Helpdesk Chats service."""
36+
37+
38+
class AsyncChatsService(
39+
AsyncCreateMixin[Chat],
40+
AsyncUpdateMixin[Chat],
41+
AsyncGetMixin[Chat],
42+
AsyncCollectionMixin[Chat],
43+
AsyncService[Chat],
44+
ChatsServiceConfig,
45+
):
46+
"""Async Helpdesk Chats service."""
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
2+
from mpt_api_client.resources.helpdesk.chats import AsyncChatsService, ChatsService
3+
4+
5+
class Helpdesk:
6+
"""Helpdesk MPT API Module."""
7+
8+
def __init__(self, http_client: HTTPClient):
9+
self.http_client = http_client
10+
11+
@property
12+
def chats(self) -> ChatsService:
13+
"""Chats service."""
14+
return ChatsService(http_client=self.http_client)
15+
16+
17+
class AsyncHelpdesk:
18+
"""Async Helpdesk MPT API Module."""
19+
20+
def __init__(self, http_client: AsyncHTTPClient):
21+
self.http_client = http_client
22+
23+
@property
24+
def chats(self) -> AsyncChatsService:
25+
"""Async Chats service."""
26+
return AsyncChatsService(http_client=self.http_client)

tests/e2e/helpdesk/__init__.py

Whitespace-only changes.

tests/e2e/helpdesk/chats/__init__.py

Whitespace-only changes.
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 chat_id(e2e_config):
6+
return e2e_config["helpdesk.chat.id"]
7+
8+
9+
@pytest.fixture
10+
def invalid_chat_id():
11+
return "CHT-0000-0000-0000"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
5+
6+
async def test_get_chat(async_mpt_ops, chat_id):
7+
service = async_mpt_ops.helpdesk.chats
8+
9+
result = await service.get(chat_id)
10+
11+
assert result.id == chat_id
12+
13+
14+
async def test_list_chats(async_mpt_ops):
15+
service = async_mpt_ops.helpdesk.chats
16+
17+
result = await service.fetch_page(limit=1)
18+
19+
assert len(result) > 0
20+
21+
22+
async def test_update_chat(async_mpt_ops, chat_id, short_uuid):
23+
service = async_mpt_ops.helpdesk.chats
24+
new_description = f"e2e update {short_uuid}"
25+
26+
result = await service.update(chat_id, {"description": new_description})
27+
28+
assert result.id == chat_id
29+
assert result.to_dict().get("description") == new_description
30+
31+
32+
async def test_not_found(async_mpt_ops, invalid_chat_id):
33+
service = async_mpt_ops.helpdesk.chats
34+
35+
with pytest.raises(MPTAPIError):
36+
await service.get(invalid_chat_id)

0 commit comments

Comments
 (0)