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