Skip to content

Commit

Permalink
implement clearing of checklists
Browse files Browse the repository at this point in the history
  • Loading branch information
benjmin-r committed Mar 1, 2016
1 parent f2e7541 commit 1f75070
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions test/test_checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def test_checklist_rename(self):

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

name = 'Checklist'
checklist = self._add_checklist(card, name, ['item1', 'item2'])
Expand All @@ -94,7 +93,16 @@ def test_delete_checklist_item(self):
self.assertEqual(len(checklists[0].items), 1)
self.assertEqual(checklists[0].items[0]['name'], 'item1')

card.delete()
def test_clear_checklist(self):
name = "Testing checklist clear"
card = self._list.add_card(name, "Description goes here")

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

checklists = card.fetch_checklists()
self.assertEqual(len(checklists[0].items), 0)


def suite():
Expand Down
8 changes: 7 additions & 1 deletion trello/checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ def delete_checklist_item(self, name):
if ix is None:
return

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

def clear(self):
"""Clear checklist by removing all checklist items"""
# iterate over names as list is modified while iterating and this breaks
# for-loops behaviour
for name in [item['name'] for item in self.items]:
self.delete_checklist_item(name)

def set_checklist_item(self, name, checked):
"""Set the state of an item on this checklist
Expand Down

0 comments on commit 1f75070

Please sign in to comment.