本篇文章旨在通過一段JavaScript來演示如何調用python後端服務的,這是我開發的一個構建測試數據的工具。
第一部分:html 代碼部分
第二部分:JavaScript代碼部分
第三部分:Python後端代碼
@app.route('/insertInvertory',methods=['GET'])
def insertInvertory():
env=request.args.get('env')
code=request.args.get('code')
datenow = time.strftime("%Y-%m-%d")
db=DBUtils(env)
selectsql="SELECT a.id propertyId,c.id roomTypeId,c.code RoomType FROM info.property AS a,info.room_class AS b,info.room_type AS c WHERE a.code ='"+code+"' AND b.property_id =a.id AND c.room_class_id =b.id"
result=db.dbSelect(selectsql)
for i in range(len(result)):
property_id=str(result[i]['propertyId'])
delsql = "DELETE FROM inv.`property_inventory_detail` WHERE property_id ='"+property_id+"' AND effective_date >='" + str(datenow) + "'"
dbs = DBUtils(env)
resutls = dbs.dbExcute(delsql)
print("the resutls is:",resutls)
print(delsql)
for i in range(len(result)):
property_id=str(result[i]['propertyId'])
relation_id=str(result[i]['roomTypeId'])
insertsql="INSERT INTO inv.`property_inventory_detail`(property_id,relation_type,relation_id,effective_date,original,consume,STATUS,create_time,update_time,deducted,out_order,non_deducted) \
VALUES \
("+property_id+",4,"+relation_id+",DATE_ADD('"+str(datenow)+"',INTERVAL 0 DAY),100,0,1,NOW(),NOW(),0,0,0),\
("+property_id+",4,"+relation_id+",DATE_ADD('"+str(datenow)+"',INTERVAL 1 DAY),100,0,1,NOW(),NOW(),0,0,0),\
("+property_id+",4,"+relation_id+",DATE_ADD('"+str(datenow)+"',INTERVAL 90 DAY),100,0,1,NOW(),NOW(),0,0,0);"
dbs = DBUtils(env)
resutls=dbs.dbExcute(insertsql)
print(resutls)
print(insertsql)
return jsonify("<p color='green'>{status:200,msg:it's success!!!}</p>")
第四步:執行成功後返回結果
總結:測試工程師要進步就得不斷的學習充電,掌握的技能(不僅是測試技能)越多你對測試的認識也就越深入,與君共勉。
備註:我的個人公衆號已正式開通,致力於測試技術的分享,包含:大數據測試、功能測試,測試開發,API接口自動化、測試運維、UI自動化測試等,微信搜索公衆號:“無量測試之道”,或掃描下方二維碼:
添加關注,一起共同成長吧。