JavaScript如何调用Python后端服务
欢迎关注【无量测试之道】公众号,回复【领取资源】,
Python编程学习资源干货、
Python+Appium框架APP的UI自动化、
Python+Selenium框架Web的UI自动化、
Python+Unittest框架API自动化、
资源和代码 免费送啦~
文章下方有公众号二维码,可直接微信扫一扫关注即可。
本篇文章旨在通过一段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自动化测试等,微信搜索公众号:“无量测试之道”,或扫描下方二维码:
添加关注,一起共同成长吧。
 
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号