From 7342d94d4ae199a547624c9d1e7712709c3259f0 Mon Sep 17 00:00:00 2001 From: Albert Sola Date: Fri, 3 Oct 2025 11:15:54 +0200 Subject: [PATCH] MPT-14076 Add notifications messages --- .../resources/notifications/messages.py | 28 +++++++++++++++ .../resources/notifications/notifications.py | 11 ++++++ .../resources/notifications/test_messages.py | 34 +++++++++++++++++++ .../notifications/test_notifications.py | 3 ++ 4 files changed, 76 insertions(+) create mode 100644 mpt_api_client/resources/notifications/messages.py create mode 100644 tests/resources/notifications/test_messages.py diff --git a/mpt_api_client/resources/notifications/messages.py b/mpt_api_client/resources/notifications/messages.py new file mode 100644 index 00000000..c74343b3 --- /dev/null +++ b/mpt_api_client/resources/notifications/messages.py @@ -0,0 +1,28 @@ +from mpt_api_client.http import AsyncService, Service +from mpt_api_client.models import Model + + +class Message(Model): + """Notifications Message resource.""" + + +class MessagesServiceConfig: + """Notifications Messages service configuration.""" + + _endpoint = "/public/v1/notifications/messages" + _model_class = Message + _collection_key = "data" + + +class MessagesService( + Service[Message], + MessagesServiceConfig, +): + """Notifications Messages service (no CRUD, no block/unblock).""" + + +class AsyncMessagesService( + AsyncService[Message], + MessagesServiceConfig, +): + """Async Notifications Messages service (no CRUD, no block/unblock).""" diff --git a/mpt_api_client/resources/notifications/notifications.py b/mpt_api_client/resources/notifications/notifications.py index 7c283d60..22a33802 100644 --- a/mpt_api_client/resources/notifications/notifications.py +++ b/mpt_api_client/resources/notifications/notifications.py @@ -4,6 +4,7 @@ CategoriesService, ) from mpt_api_client.resources.notifications.contacts import AsyncContactsService, ContactsService +from mpt_api_client.resources.notifications.messages import AsyncMessagesService, MessagesService class Notifications: @@ -22,6 +23,11 @@ def contacts(self) -> ContactsService: """Contacts service.""" return ContactsService(http_client=self.http_client) + @property + def messages(self) -> MessagesService: + """Messages service.""" + return MessagesService(http_client=self.http_client) + class AsyncNotifications: """Notifications MPT API Module.""" @@ -38,3 +44,8 @@ def categories(self) -> AsyncCategoriesService: def contacts(self) -> AsyncContactsService: """Async Contacts service.""" return AsyncContactsService(http_client=self.http_client) + + @property + def messages(self) -> AsyncMessagesService: + """Async Messages service.""" + return AsyncMessagesService(http_client=self.http_client) diff --git a/tests/resources/notifications/test_messages.py b/tests/resources/notifications/test_messages.py new file mode 100644 index 00000000..64aaa717 --- /dev/null +++ b/tests/resources/notifications/test_messages.py @@ -0,0 +1,34 @@ +import pytest + +from mpt_api_client.resources.notifications.messages import ( + AsyncMessagesService, + MessagesService, +) + + +@pytest.fixture +def messages_service(http_client): + return MessagesService(http_client=http_client) + + +@pytest.fixture +def async_messages_service(async_http_client): + return AsyncMessagesService(http_client=async_http_client) + + +def test_messages_service_instance(messages_service): + assert isinstance(messages_service, MessagesService) + + +def test_async_messages_service_instance(async_messages_service): + assert isinstance(async_messages_service, AsyncMessagesService) + + +@pytest.mark.parametrize("method", ["get", "iterate"]) +def test_sync_messages_service_methods(messages_service, method): + assert hasattr(messages_service, method) + + +@pytest.mark.parametrize("method", ["get", "iterate"]) +def test_async_messages_service_methods(async_messages_service, method): + assert hasattr(async_messages_service, method) diff --git a/tests/resources/notifications/test_notifications.py b/tests/resources/notifications/test_notifications.py index 21eecc34..f06aabf0 100644 --- a/tests/resources/notifications/test_notifications.py +++ b/tests/resources/notifications/test_notifications.py @@ -6,6 +6,7 @@ CategoriesService, ) from mpt_api_client.resources.notifications.contacts import AsyncContactsService, ContactsService +from mpt_api_client.resources.notifications.messages import AsyncMessagesService, MessagesService def test_notifications_init(http_client): @@ -27,6 +28,7 @@ def test_async_notifications_init(async_http_client): [ ("categories", CategoriesService), ("contacts", ContactsService), + ("messages", MessagesService), ], ) def test_notifications_properties(http_client, attr_name, expected): @@ -42,6 +44,7 @@ def test_notifications_properties(http_client, attr_name, expected): [ ("categories", AsyncCategoriesService), ("contacts", AsyncContactsService), + ("messages", AsyncMessagesService), ], ) def test_async_notifications_properties(http_client, attr_name, expected):