diff --git a/.gitignore b/.gitignore index 3691423e..dab83450 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist *swp .project .pydevproject +.idea/ diff --git a/test/test_board.py b/test/test_board.py index 680551ed..b90d9bb4 100644 --- a/test/test_board.py +++ b/test/test_board.py @@ -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): @@ -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'] diff --git a/test/test_trello_client.py b/test/test_trello_client.py index 9fa0ef96..c1feec14 100644 --- a/test/test_trello_client.py +++ b/test/test_trello_client.py @@ -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): diff --git a/trello/trelloclient.py b/trello/trelloclient.py index 217e4732..ccf46417 100644 --- a/trello/trelloclient.py +++ b/trello/trelloclient.py @@ -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)