def test_board(self): q = BoardQuery().get_all_boards() r = Database().run_query(q) self.assertEqual(r, []) bid1 = str(uuid.uuid1()) q = BoardQuery().create_board({'id': bid1, 'title': 'Board#1'}) Database().run_query(q) bid2 = str(uuid.uuid1()) q = BoardQuery().create_board({'id': bid2, 'title': 'Board#2'}) Database().run_query(q) q = BoardQuery().get_all_boards() r = Database().run_query(q) self.assertEqual(len(r), 2) q = BoardQuery().update_board({'title': 'Board#3'}, bid2) Database().run_query(q) q = BoardQuery().get_board_by_id(bid2) r = Database().run_query(q) self.assertEqual(r[0]['id'], bid2) self.assertEqual(r[0]['title'], 'Board#3') q = BoardQuery().delete_board(bid2) Database().run_query(q) q = BoardQuery().get_board_by_id(bid2) r = Database().run_query(q) self.assertEqual(r, []) q = BoardQuery().get_all_boards() r = Database().run_query(q) self.assertEqual(len(r), 1)
def delete_card(id): query = CardQuery().get_card_by_id(id) card = Database().run_query(query) if not card: abort(404) query = CardQuery().delete_card(id) Database().run_query(query) return "Delete successful"
def get_list(id): query = Query().get_list_by_id(id) list = Database().run_query(query) if not list: abort(404) query = CardQuery().get_list_cards(id) list[0]['cards'] = Database().run_query(query) return jsonify({'lists': list})
def delete_list(id): query = Query().get_list_by_id(id) list = Database().run_query(query) if not list: abort(404) query = Query().delete_list(id) Database().run_query(query) return "Delete successful"
def get_board(id): query = BoardQuery().get_board_by_id(id) board = Database().run_query(query) if not board: abort(404) query = Query().get_board_lists(id) lists = Database().run_query(query) for l in lists: query = CardQuery().get_list_cards(l['id']) l['cards'] = Database().run_query(query) board[0]['lists'] = lists return jsonify({'boards': board})
def create_board(): data = request.get_json() or {} if 'title' not in data: abort(400) cid = str(uuid.uuid1()) data['id'] = cid query = BoardQuery().create_board(data) Database().run_query(query) query = BoardQuery().get_board_by_id(cid) board = Database().run_query(query) return jsonify({'boards': board}), 201
def create_list(): data = request.get_json() or {} if 'title' not in data or 'board_id' not in data: abort(400) cid = str(uuid.uuid1()) data['id'] = cid query = Query().add_list(data) Database().run_query(query) query = Query().get_list_by_id(cid) list = Database().run_query(query) return jsonify({'lists': list}), 201
def create_card(): data = request.get_json() or {} if 'title' not in data or 'list_id' not in data: abort(400) cid = str(uuid.uuid1()) data['id'] = cid query = CardQuery().add_card(data) Database().run_query(query) query = CardQuery().get_card_by_id(cid) card = Database().run_query(query) return jsonify({'cards': card}), 201
def get_card(id): query = CardQuery().get_card_by_id(id) card = Database().run_query(query) if not card: abort(404) return jsonify({'cards': card})
def update_card(id): data = request.get_json() or {} if not data: abort(400) query = CardQuery().get_card_by_id(id) card = Database().run_query(query) if not card: abort(404) query = CardQuery().edit_card(data, id) Database().run_query(query) query = CardQuery().get_card_by_id(id) card = Database().run_query(query) return jsonify({'cards': card})
def update_board(id): data = request.get_json() or {} if not data: abort(400) query = BoardQuery().get_board_by_id(id) board = Database().run_query(query) if not board: abort(404) query = BoardQuery().update_board(data, id) Database().run_query(query) query = BoardQuery().get_board_by_id(id) board = Database().run_query(query) return jsonify({'boards': board})
def update_list(id): data = request.get_json() or {} if not data: abort(400) query = Query().get_list_by_id(id) list = Database().run_query(query) if not list: abort(404) query = Query().edit_list(data, id) Database().run_query(query) query = Query().get_list_by_id(id) list = Database().run_query(query) return jsonify({'lists': list})
def get_cards(): query = CardQuery().get_all_cards() cards = Database().run_query(query) return jsonify({'cards': cards})
def get_boards(): query = BoardQuery().get_all_boards() boards = Database().run_query(query) return jsonify({'boards': boards})
def tearDown(self): Database().run_query("DROP TABLE card") Database().run_query("DROP TABLE list") Database().run_query("DROP TABLE board") Database().close_connection()