def get(self, board_id=None): """ View a board. """ if board_id: board = Board.get(id=board_id) if isinstance(board, dict): return { 'status': 'fail', 'message': 'The board does not exist.', 'help': 'Ensure board_id is of an existent board.' }, 404 else: return { 'status': 'success', 'data': { 'board': board.view() } }, 200 else: boards = Board.get_all() if isinstance(boards, dict): return { 'status': 'fail', 'message': 'No boards exist.', 'help': 'Ensure there are boards in the database.' }, 404 else: return { 'status': 'success', 'data': { 'boards': [board.view() for board in boards] } }, 200
def test_insert_wrong_field(self): self.user1.save() self.board1.save() user1 = User.get(id=1) excepted = { "message": "Ensure the field passed is valid.", "help": "The field should be an attribute of the object." } actual = user1.insert('random', Board.get_all()) self.assertDictEqual(excepted, actual)
def test_add_and_remove_board_from_user(self): self.user1.save() self.board1.save() self.board2.save() user1 = User.get(id=1) self.assertEqual(0, len(user1.boards)) user1.insert('boards', Board.get_all()) self.assertEqual(2, len(user1.boards)) user1.remove('boards', id=1) self.assertEqual(1, len(user1.boards)) user1.remove('boards') self.assertEqual(0, len(user1.boards))
def test_get_many_boards(self): self.assertTrue(isinstance(Board.get_all(), dict)) self.board1.save() self.board2.save() self.assertEqual(2, len(Board.get_all()))