def get(self): query = request.args try: res = Borrowbook.get_detail(query.get("id")) if res: return jsonify(res) return make_response(jsonify({"message": " Not Found"}), 404) except Exception as e: return make_response(jsonify({"message": str(e)}), 400)
def put(self): query = request.get_json() try: id_ = Borrowbook.updateInfo(**query) if id_: res = Borrowbook.get_detail(id_) return make_response(jsonify({"data": res}), 200) return make_response(jsonify({"message": "ok"}), 201) except Exception as e: return make_response(jsonify({"message": str(e)}), 400)
def test_get_detail(self): self.assertTrue(Borrowbook.get_detail(2)) self.assertTrue(Borrowbook.get_detail(4))
def test_get_detail(self): with library_mysql.atomic() as txn: Borrowbook.get_detail(7) Borrowbook.get_detail(10) txn.rollback()