def test_delete_board(self): self.board1.save() self.estate1.save() self.unit1.save() board1 = Board.get(id=1) board1.insert('estates_owned', [Estate.get(id=1)]) board1.units_owned.append(Unit.get(id=1)) self.assertEqual(True, Board.get(id=1).delete()) self.assertEqual(True, isinstance(Board.get(id=1), dict))
def test_add_and_remove_users_from_board(self): self.board1.save() self.user1.save() self.user2.save() board1 = Board.get(id=1) board1.insert('members', [User.get(id=1), User.get(id=2)]) self.assertEqual(2, len(Board.get(id=1).members)) board1.remove('members', id=1) self.assertEqual(1, len(Board.get(id=1).members))
def test_add_and_remove_estates_owned_to_board(self): self.board1.save() self.estate1.save() self.estate2.save() board1 = Board.get(id=1) board1.insert('estates_owned', [Estate.get(id=1), Estate.get(id=2)]) estates = Board.get(id=1).estates_owned self.assertEqual("Random Address 1", estates[0].address) self.assertEqual("Random Address 2", estates[1].address) self.assertEqual(2, len(estates)) self.assertEqual(True, isinstance(estates[0], Estate)) self.assertEqual(True, isinstance(estates[1], Estate)) board1.remove('estates_owned', id=1) self.assertEqual(1, len(Board.get(id=1).estates_owned))
def test_add_and_remove_units_owned_to_board(self): self.board1.save() self.unit1.save() self.unit2.save() board1 = Board.get(id=1) board1.insert('units_owned', [Unit.get(id=1), Unit.get(id=2)]) units = Board.get(id=1).units_owned self.assertEqual("Random Unit 1", units[0].name) self.assertEqual("Random Unit 2", units[1].name) self.assertEqual(2, len(units)) self.assertEqual(True, isinstance(units[0], Unit)) self.assertEqual(True, isinstance(units[1], Unit)) board1.remove('units_owned', id=1) self.assertEqual(1, len(Board.get(id=1).units_owned))
def test_get_estate_board(self): self.estate1.save() self.board1.save() board1 = Board.get(id=1) board1.insert('estates_owned', [Estate.get(id=1)]) estate1 = Estate.get(id=1) self.assertEqual(1, estate1.board_id)
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_add_remove_conversation_from_board(self): self.board1.save() self.conversation1.save() board1 = Board.get(id=1) board1.insert('conversation', Conversation.get(id=1)) self.assertEqual(True, isinstance(board1.conversation, Conversation)) board1.remove('conversation') self.assertEqual(None, board1.conversation)
def test_insert_many_not_list(self): self.user1.save() self.board1.save() user1 = User.get(id=1) excepted = { "message": "Ensure objects passed are as a list.", "help": "This eases updating of (one)many-to-many fields" } actual = user1.insert('boards', Board.get(id=1)) self.assertDictEqual(excepted, actual)
def test_add_and_remove_board_estate_resident(self): self.board1.save() self.estate1.save() self.user1.save() self.unit1.save() unit1 = Unit.get(id=1) unit1.insert('resident', User.get(id=1)) unit1.insert('board', Board.get(id=1)) unit1.insert('estate', Estate.get(id=1)) self.assertEqual(True, isinstance(unit1.board, Board)) self.assertEqual(True, isinstance(unit1.resident, User)) self.assertEqual(True, isinstance(unit1.estate, Estate)) unit1.remove('resident') unit1.remove('board') unit1.remove('estate') self.assertEqual(None, unit1.board) self.assertEqual(None, unit1.estate) self.assertEqual(None, unit1.resident)
def test_get_board(self): self.board1.save() self.assertTrue(isinstance(Board.get(id=1), Board))