Skip to content

Commit

Permalink
Added obtaining all checklists directly from the board and the respec…
Browse files Browse the repository at this point in the history
…tive test
  • Loading branch information
t0ffel committed Mar 17, 2016
1 parent 1325e31 commit 2d121d3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def _add_card(self, name, description=None):
print(str(e))
self.fail("Caught Exception adding card")

def _add_checklist(self, card, name, items=[], itemstates=None):
checklist = card.add_checklist(name, items, itemstates)
self.assertIsNotNone(checklist, msg="checklist is None")
self.assertIsNotNone(checklist.id, msg="id not provided")
self.assertEquals(checklist.name, name)
return checklist

def test_get_cards(self):
# Let's ensure we have no cards in board
for card in self._board.get_cards():
Expand Down Expand Up @@ -165,6 +172,24 @@ def test120_close_board(self):
still_open_count = len(still_open_boards)
self.assertEqual(still_open_count, open_count - 2)

def test130_get_checklists_board(self):
chklists = self._board.get_checklists(cards = 'open')
for chklst in chklists:
chklst.delete()
card = self._add_card('For checklist testing')
chklist = self._add_checklist(card, "Test Checklist", items=["item1","item2"], itemstates = [True, False])
new_chklists = self._board.get_checklists()
test_chk = new_chklists[0]
self.assertEqual(test_chk.name, "Test Checklist")
self.assertEqual(test_chk.trello_card, card.id)
self.assertEqual(len(new_chklists), 1)
i1 = test_chk.items[0]
i2 = test_chk.items[1]
self.assertEqual(len(test_chk.items), 2)
self.assertEqual(i1['name'], "item1")
self.assertEqual(i1['state'], "complete")
self.assertEqual(i2['name'], "item2")
self.assertEqual(i2['state'], "incomplete")

def suite():
# tests = ['test01_list_boards', 'test10_board_attrs', 'test20_add_card']
Expand Down
16 changes: 16 additions & 0 deletions trello/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from trello.card import Card
from trello.trellolist import List
from trello.label import Label
from trello.checklist import Checklist
from dateutil import parser as dateparser


Expand Down Expand Up @@ -144,6 +145,21 @@ def get_labels(self, fields='all', limit=50):
query_params={'fields': fields, 'limit': limit})
return Label.from_json_list(self, json_obj)

def get_checklists(self, cards='all'):
'''Get checklists
:rtype: Checklist
'''
checklists = []
json_obj = self.client.fetch_json(
'/boards/' + self.id + '/checklists',
query_params={'cards': cards})
json_obj = sorted(json_obj, key=lambda checklist: checklist['pos'])
for cl in json_obj:
checklists.append(Checklist(self.client, cl.get('checkItemStates',[]), cl,
trello_card=cl.get('idCard')))
return checklists

def add_list(self, name):
"""Add a list to this board
Expand Down

0 comments on commit 2d121d3

Please sign in to comment.