From 0f1ce2f1249bbb4775dd7877b78fe9cf6df14036 Mon Sep 17 00:00:00 2001 From: Tony Morello Date: Fri, 2 Sep 2022 10:52:55 -0700 Subject: [PATCH] Added move_item_to_group and archive_item_by_id (#73) * Added move item to group and archive item * Added tests for move item to group and archive item * Updated README.md * Update package version --- README.md | 4 ++++ monday/__version__.py | 2 +- monday/query_joins.py | 26 +++++++++++++++++++++++++- monday/resources/items.py | 11 ++++++++++- monday/tests/test_item_resource.py | 20 +++++++++++++++++++- 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7720eb6..769e35b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a - `add_file_to_column(item_id, column_id, file)` - Upload a file to a file type column specified by column_id. Monday limits uploads to 500MB in size. +- `move_item_to_group(item_id, group_id)` - Move the item to a group within the same board. + +- `archive_item_by_id(item_id)` - Archive the item by item_id. + - `delete_item_by_id(item_id)` - Delete the item by item_id. #### Updates Resource (monday.updates) diff --git a/monday/__version__.py b/monday/__version__.py index 8ef82a1..eace817 100644 --- a/monday/__version__.py +++ b/monday/__version__.py @@ -1,3 +1,3 @@ -__version__ = '1.3.0' +__version__ = '1.3.1' __author__ = 'Christina D\'Astolfo' __email__ = 'chdastolfo@gmail.com, pevner@prodperfect.com, lemi@prodperfect.com' diff --git a/monday/query_joins.py b/monday/query_joins.py index db34840..84f918f 100644 --- a/monday/query_joins.py +++ b/monday/query_joins.py @@ -127,6 +127,30 @@ def update_item_query(board_id, item_id, column_id, value): return query +def move_item_to_group_query(item_id, group_id): + query = ''' + mutation + { + move_item_to_group (item_id: %s, group_id: %s) + { + id + } + }''' % (item_id, group_id) + return query + + +def archive_item_query(item_id): + query = ''' + mutation + { + archive_item (item_id: %s) + { + id + } + }''' % item_id + return query + + def delete_item_query(item_id): query = ''' mutation @@ -189,7 +213,7 @@ def create_update_query(item_id, update_value): def get_updates_for_item_query(board, item, limit): - query = '''query + query = '''query {boards (ids: %s) {items (ids: %s) { updates (limit: %s) { diff --git a/monday/resources/items.py b/monday/resources/items.py index 7d8aa1d..73e365c 100644 --- a/monday/resources/items.py +++ b/monday/resources/items.py @@ -1,6 +1,7 @@ from monday.resources.base import BaseResource from monday.query_joins import mutate_item_query, get_item_query, update_item_query, get_item_by_id_query, \ - update_multiple_column_values_query, mutate_subitem_query, add_file_to_column_query, delete_item_query + update_multiple_column_values_query, mutate_subitem_query, add_file_to_column_query, delete_item_query, \ + archive_item_query, move_item_to_group_query class ItemResource(BaseResource): @@ -40,6 +41,14 @@ def add_file_to_column(self, item_id, column_id, file): query = add_file_to_column_query(item_id, column_id) return self.file_upload_client.execute(query, variables={'file': file}) + def move_item_to_group(self, item_id, group_id): + query = move_item_to_group_query(item_id, group_id) + return self.client.execute(query) + + def archive_item_by_id(self, item_id): + query = archive_item_query(item_id) + return self.client.execute(query) + def delete_item_by_id(self, item_id): query = delete_item_query(item_id) return self.client.execute(query) diff --git a/monday/tests/test_item_resource.py b/monday/tests/test_item_resource.py index 0141db9..5623781 100644 --- a/monday/tests/test_item_resource.py +++ b/monday/tests/test_item_resource.py @@ -1,6 +1,7 @@ from monday.tests.test_case_resource import BaseTestCase from monday.query_joins import mutate_item_query, get_item_query, update_item_query, get_item_by_id_query, \ - update_multiple_column_values_query, mutate_subitem_query, add_file_to_column_query, delete_item_query + update_multiple_column_values_query, mutate_subitem_query, add_file_to_column_query, delete_item_query, \ + archive_item_query, move_item_to_group_query from monday.utils import monday_json_stringify @@ -68,3 +69,20 @@ def test_delete_item_by_id(self): id } }'''.replace(" ", ""), query.replace(" ", "")) + + def test_archive_item_by_id(self): + query = archive_item_query(item_id=self.item_id) + self.assertIn(str(self.item_id), query) + self.assertEqual(''' + mutation + { + archive_item (item_id: 24) + { + id + } + }'''.replace(" ", ""), query.replace(" ", "")) + + def test_move_item_to_group_query(self): + query = move_item_to_group_query(item_id=self.item_id, group_id=self.group_id) + self.assertIn(str(self.item_id), query) + self.assertIn(str(self.group_id), query)