Skip to content

Commit

Permalink
implement deletion of single checklist items
Browse files Browse the repository at this point in the history
  • Loading branch information
benjmin-r committed Mar 1, 2016
1 parent 9518127 commit 77eb3f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/test_checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ def test_checklist_rename(self):
self.assertEqual(len(card.checklists), 1)
self.assertEqual(card.checklists[0].name, new_name)

def test_delete_checklist_item(self):
name = "Testing checklist item delete"
description = "Description goes here"
card = self._list.add_card(name, description)

name = 'Checklist'
checklist = self._add_checklist(card, name, ['item1', 'item2'])
checklist.delete_checklist_item('item2')

checklists = card.fetch_checklists()
self.assertEqual(len(checklists[0].items), 1)
self.assertEqual(checklists[0].items[0]['name'], 'item1')

card.delete()


def suite():
# tests = ['test01_list_boards', 'test10_board_attrs', 'test20_add_card']
Expand Down
25 changes: 25 additions & 0 deletions trello/checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ def add_checklist_item(self, name, checked=False):
self.items.append(json_obj)
return json_obj

def delete_checklist_item(self, name):
"""Delete an item on this checklist
:name: name of the checklist item to delete
"""
ix = self._get_item_id(name)
if ix is None:
return

obj = self.client.fetch_json(
'/checklists/'+ self.id +
'/checkItems/'+ self.items[ix]['id'],
http_method='DELETE')
del self.items[ix]


def set_checklist_item(self, name, checked):
"""Set the state of an item on this checklist
Expand Down Expand Up @@ -103,5 +119,14 @@ def delete(self):
'/checklists/%s' % self.id,
http_method='DELETE')

def _get_item_id(self, name):
"""Locate the id of the checklist item"""
try:
[ix] = [i for i in range(len(self.items)) if
self.items[i]['name'] == name]
return ix
except ValueError:
return None

def __repr__(self):
return '<Checklist %s>' % self.id

0 comments on commit 77eb3f4

Please sign in to comment.