diff --git a/test/test_checklist.py b/test/test_checklist.py index 88df2efc..8a7ca1ad 100644 --- a/test/test_checklist.py +++ b/test/test_checklist.py @@ -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'] diff --git a/trello/checklist.py b/trello/checklist.py index ad1134cc..b53ccf0d 100644 --- a/trello/checklist.py +++ b/trello/checklist.py @@ -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 @@ -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 '' % self.id