Skip to content

Commit

Permalink
Added move_item_to_group and archive_item_by_id (#73)
Browse files Browse the repository at this point in the history
* Added move item to group and archive item

* Added tests for move item to group and archive item

* Updated README.md

* Update package version
  • Loading branch information
tonymorello authored Sep 2, 2022
1 parent 2de9c46 commit 0f1ce2f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion monday/__version__.py
Original file line number Diff line number Diff line change
@@ -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'
26 changes: 25 additions & 1 deletion monday/query_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion monday/resources/items.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
20 changes: 19 additions & 1 deletion monday/tests/test_item_resource.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)

0 comments on commit 0f1ce2f

Please sign in to comment.