From 1f75070b3688a83baa90c4d8a5eacc33ffc70eb3 Mon Sep 17 00:00:00 2001 From: Benjamin Reitzammer Date: Tue, 1 Mar 2016 01:19:28 +0100 Subject: [PATCH] implement clearing of checklists --- test/test_checklist.py | 14 +++++++++++--- trello/checklist.py | 8 +++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/test/test_checklist.py b/test/test_checklist.py index 8a7ca1ad..1cdd141d 100644 --- a/test/test_checklist.py +++ b/test/test_checklist.py @@ -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']) @@ -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(): diff --git a/trello/checklist.py b/trello/checklist.py index 38ca1c18..8ecd4b66 100644 --- a/trello/checklist.py +++ b/trello/checklist.py @@ -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