From 86fb6170292b70369ac94f20805f3e2cf4600a5e Mon Sep 17 00:00:00 2001 From: SblipDev Date: Tue, 8 Feb 2022 23:19:14 +0530 Subject: [PATCH] Added Notification Resource Query to query_joins --- monday/query_joins.py | 15 +++++++++++++++ monday/resources/__init__.py | 3 ++- monday/resources/notification.py | 14 ++++++++++++++ monday/tests/test_case_resource.py | 2 ++ monday/tests/test_notification_resource.py | 15 +++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 monday/resources/notification.py create mode 100644 monday/tests/test_notification_resource.py diff --git a/monday/query_joins.py b/monday/query_joins.py index 4971614..dd58a66 100644 --- a/monday/query_joins.py +++ b/monday/query_joins.py @@ -540,3 +540,18 @@ def delete_teams_from_workspace_query(id, team_ids): } ''' % (id, team_ids) return query + + +def create_notification_query(user_id, target_id, text, target_type): + query = ''' + mutation { + create_notification (user_id: %s, target_id: %s, text: "%s", target_type: %s) { + text + user_id + target_id + target_type + } + } + ''' % (user_id, target_id, text, target_type) + # Target type may be: Project/Post + return query diff --git a/monday/resources/__init__.py b/monday/resources/__init__.py index 92bcd5a..fe382b1 100644 --- a/monday/resources/__init__.py +++ b/monday/resources/__init__.py @@ -6,5 +6,6 @@ from .groups import GroupResource from .complexity import ComplexityResource from .workspaces import WorkspaceResource +from .notification import NotificationResource -__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource', 'WorkspaceResource'] +__all__ = ['ItemResource', 'UpdateResource', 'TagResource', 'BoardResource', 'UserResource', 'GroupResource', 'ComplexityResource', 'WorkspaceResource', 'NotificationResource'] diff --git a/monday/resources/notification.py b/monday/resources/notification.py new file mode 100644 index 0000000..b6cceb8 --- /dev/null +++ b/monday/resources/notification.py @@ -0,0 +1,14 @@ +from monday.resources.base import BaseResource +from monday.query_joins import create_notification_query + + +class NotificationResource(BaseResource): + def __init__(self, token): + super().__init__(token) + + def create_notification(self, user_id, target_id, text, target_type): + """ + Refer to here for more information -> https://api.developer.monday.com/docs/notification-queries + """ + query = create_notification_query(user_id, target_id, text, target_type) + return self.client.execute(query) diff --git a/monday/tests/test_case_resource.py b/monday/tests/test_case_resource.py index da86e6b..d8ad9f0 100644 --- a/monday/tests/test_case_resource.py +++ b/monday/tests/test_case_resource.py @@ -21,4 +21,6 @@ def setUp(self): self.workspace_id = "123456" self.workspace_user_kind = "subscriber" self.team_ids = [105939, 105940, 105941] + self.notification_text = "This is an awesome notification." + self.notification_target_type = "Project" diff --git a/monday/tests/test_notification_resource.py b/monday/tests/test_notification_resource.py new file mode 100644 index 0000000..017546a --- /dev/null +++ b/monday/tests/test_notification_resource.py @@ -0,0 +1,15 @@ +from monday.tests.test_case_resource import BaseTestCase +from monday.query_joins import create_notification_query + + +class NotificationsTestCase(BaseTestCase): + def setUp(self): + super(NotificationsTestCase, self).setUp() + + def test_create_notification_query(self): + query = create_notification_query(self.user_ids[0], self.item_id, self.notification_text, self.notification_target_type) + self.assertIn(str(self.user_ids[0]), query) + self.assertIn(str(self.item_id), query) + self.assertIn(str(self.notification_text), query) + self.assertIn(str(self.notification_target_type), query) + \ No newline at end of file