Skip to content

Commit

Permalink
Fixed gh-124.
Browse files Browse the repository at this point in the history
 -Added support for a source_board parameter to add_board
 - Added tests for add_board, copy_board, close_board
 - Modified list boards to only look at open boards
 - This commit now causes the test account to accumulate closed boards
  • Loading branch information
David Stenglein committed Jan 30, 2016
1 parent af4d7cc commit 0d43bce
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
*swp
.project
.pydevproject
.idea/
34 changes: 33 additions & 1 deletion test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime
import unittest
import os
from trello import TrelloClient
from trello import TrelloClient, Board


class TrelloBoardTestCase(unittest.TestCase):
Expand Down Expand Up @@ -103,6 +103,38 @@ def test90_get_board(self):
board = self._trello.get_board(self._board.id)
self.assertEqual(self._board.name, board.name)

def test100_add_board(self):
test_board = self._trello.add_board("test_create_board")
test_list = test_board.add_list("test_list")
test_list.add_card("test_card")
open_boards = self._trello.list_boards(board_filter="open")
self.assertEqual(len([x for x in open_boards if x.name == "test_create_board"]), 1)

def test110_copy_board(self):
boards = self._trello.list_boards(board_filter="open")
source_board = next( x for x in boards if x.name == "test_create_board")
self._trello.add_board("copied_board", source_board=source_board)
listed_boards = self._trello.list_boards(board_filter="open")
copied_board = next(iter([x for x in listed_boards if x.name == "copied_board"]), None)
self.assertIsNotNone(copied_board)
open_lists = source_board.open_lists()
self.assertEqual(len(open_lists), 4) # default lists plus mine
test_list = open_lists[0]
self.assertEqual(len(test_list.list_cards()), 1)
test_card = next ( iter([ x for x in test_list.list_cards() if x.name == "test_card"]), None )
self.assertIsNotNone(test_card)

def test120_close_board(self):
boards = self._trello.list_boards(board_filter="open")
open_count = len(boards)
test_create_board = next( x for x in boards if x.name == "test_create_board") # type: Board
copied_board = next( x for x in boards if x.name == "copied_board") # type: Board
test_create_board.close()
copied_board.close()
still_open_boards = self._trello.list_boards(board_filter="open")
still_open_count = len(still_open_boards)
self.assertEqual(still_open_count, open_count - 2)


def suite():
# tests = ['test01_list_boards', 'test10_board_attrs', 'test20_add_card']
Expand Down
2 changes: 1 addition & 1 deletion test/test_trello_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self):

def test01_list_boards(self):
self.assertEquals(
len(self._trello.list_boards()),
len(self._trello.list_boards(board_filter="open")),
int(os.environ['TRELLO_TEST_BOARD_COUNT']))

def test10_board_attrs(self):
Expand Down
9 changes: 7 additions & 2 deletions trello/trelloclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,16 @@ def get_board(self, board_id):
obj = self.fetch_json('/boards/' + board_id)
return Board.from_json(self, json_obj=obj)

def add_board(self, board_name):
def add_board(self, board_name, source_board=None):
'''Create board
:param board_name: Name of the board to create
:param source_board: Optional Board to copy
:rtype: Board
'''
post_args={'name': board_name}
if source_board is not None:
post_args['idBoardSource'] = source_board.id

obj = self.fetch_json('/boards', http_method='POST',
post_args={'name': board_name})
return Board.from_json(self, json_obj=obj)
Expand Down

0 comments on commit 0d43bce

Please sign in to comment.