当前位置: 首页 > news >正文

江苏省常州建设高等职业技术学校网站长沙网站建站模板

江苏省常州建设高等职业技术学校网站,长沙网站建站模板,骏域网络,广州市网站集约化建设目录 什么是mock? 什么时候需要用到mock? 如何实现? pythonflask自定义mock服务的步骤 一、环境搭建 1、安装flask插件 2、验证插件 二、mock案例 1、模拟 返回结果 2、模拟 异常响应状态码 3、模拟登录,从jmeter中获取…

目录

什么是mock?

什么时候需要用到mock?

如何实现?

python+flask自定义mock服务的步骤

一、环境搭建

1、安装flask插件

2、验证插件

二、mock案例

1、模拟 返回结果

2、模拟 异常响应状态码

3、模拟登录,从jmeter中获取用户名和密码


什么是mock?

简单来说,就是模拟接口。

什么时候需要用到mock?

1、依赖的接口未实现
2、依赖的接口响应速度慢
3、针对接口模拟各种异常

如何实现?

1、使用mock现有工具-->moco
2、自定义mock
    ①编写一个函数,直接return模拟的值
    ②使用接口开发框架编写要模拟的接口 flask

接下来,我们就使用python+flask来实现自定义mock。

python+flask自定义mock服务的步骤

一、环境搭建

1、安装flask插件

pip install flask

2、验证插件

flask --version

二、mock案例

1、模拟 返回结果

from flask import Flaskapp = Flask(__name__)
# 添加此配置,让接口返回值的中文不转码(保持显示中文)
app.config['JSON_AS_ASCII'] = False# 定义接口 模拟返回结果
@app.route("/login", methods=["post"])
def login():return {"status": 200, "msg": "恭喜您,登录成功!", "token": "xxxxxx"}# 运行
app.run()

2、模拟 异常响应状态码

from flask import Flaskapp = Flask(__name__)
# 添加此配置,让接口返回值的中文不转码(保持显示中文)
app.config['JSON_AS_ASCII'] = False# 定义接⼝ 模拟异常响应状态码
@app.route("/login/lgy", methods=["get"])
def lgy():return "error page", 404, {"Content-Type": "application/json"}# 运行
app.run()

3、模拟登录,从jmeter中获取用户名和密码

"""
需求: ⽤户名为admin 密码为:123456 返回登录成功!否则返回⽤户名或密码错误,请求参数
格式为:form
"""
from flask import Flask, requestapp = Flask(__name__)
# 添加此配置,让接口返回值的中文不转码(保持显示中文)
app.config['JSON_AS_ASCII'] = False@app.route('/my_login', methods=["post"])
def my_login():username = request.form.get("username")pwd = request.form.get("password")if username == 'admin' and pwd == '123456':data = {"status": 200, "msg": "恭喜您,登录成功!", "token": "xxxxxx"}return dataelse:data = {"status": 200, "msg": "用户名或密码错误"}return data# 运行
app.run()

jmeter取样器设置:

 

 


文章转载自:
http://recapitulation.wwxg.cn
http://latinization.wwxg.cn
http://reive.wwxg.cn
http://tailboard.wwxg.cn
http://stipes.wwxg.cn
http://sizable.wwxg.cn
http://aldol.wwxg.cn
http://transhydrogenase.wwxg.cn
http://topic.wwxg.cn
http://dpi.wwxg.cn
http://weapon.wwxg.cn
http://lapidation.wwxg.cn
http://guyenne.wwxg.cn
http://broiling.wwxg.cn
http://betweenness.wwxg.cn
http://seasoned.wwxg.cn
http://queerness.wwxg.cn
http://skeletal.wwxg.cn
http://twin.wwxg.cn
http://pereonite.wwxg.cn
http://mathsort.wwxg.cn
http://homiletic.wwxg.cn
http://somewise.wwxg.cn
http://expectably.wwxg.cn
http://privateer.wwxg.cn
http://autocratic.wwxg.cn
http://sulfuret.wwxg.cn
http://verification.wwxg.cn
http://cokehead.wwxg.cn
http://halfhourly.wwxg.cn
http://bibliophile.wwxg.cn
http://thermotherapy.wwxg.cn
http://sapor.wwxg.cn
http://holocaine.wwxg.cn
http://plansifter.wwxg.cn
http://leafless.wwxg.cn
http://unevenly.wwxg.cn
http://muttonhead.wwxg.cn
http://adytum.wwxg.cn
http://monosign.wwxg.cn
http://indispensably.wwxg.cn
http://ungovernable.wwxg.cn
http://sinapism.wwxg.cn
http://faux.wwxg.cn
http://hebei.wwxg.cn
http://riddlemeree.wwxg.cn
http://phonemicise.wwxg.cn
http://dinar.wwxg.cn
http://podalic.wwxg.cn
http://andorra.wwxg.cn
http://cigs.wwxg.cn
http://gunning.wwxg.cn
http://tailfan.wwxg.cn
http://unflawed.wwxg.cn
http://keystone.wwxg.cn
http://enquiring.wwxg.cn
http://manna.wwxg.cn
http://martyrology.wwxg.cn
http://eudaemonics.wwxg.cn
http://chowder.wwxg.cn
http://faithworthy.wwxg.cn
http://earning.wwxg.cn
http://decolorant.wwxg.cn
http://contracture.wwxg.cn
http://polisher.wwxg.cn
http://ravishment.wwxg.cn
http://pentoxid.wwxg.cn
http://percept.wwxg.cn
http://plantable.wwxg.cn
http://stickman.wwxg.cn
http://widukind.wwxg.cn
http://cloudward.wwxg.cn
http://deaden.wwxg.cn
http://eleusinian.wwxg.cn
http://canonical.wwxg.cn
http://abnegation.wwxg.cn
http://enroll.wwxg.cn
http://tamperproof.wwxg.cn
http://glue.wwxg.cn
http://lagomorphic.wwxg.cn
http://aluminosilicate.wwxg.cn
http://disincentive.wwxg.cn
http://sonagraph.wwxg.cn
http://spermalege.wwxg.cn
http://typhoid.wwxg.cn
http://genitival.wwxg.cn
http://flagellant.wwxg.cn
http://tayal.wwxg.cn
http://nephrotic.wwxg.cn
http://unright.wwxg.cn
http://hispanidad.wwxg.cn
http://carrottop.wwxg.cn
http://egomania.wwxg.cn
http://elegise.wwxg.cn
http://leon.wwxg.cn
http://illustrator.wwxg.cn
http://radioautograph.wwxg.cn
http://misusage.wwxg.cn
http://cashaw.wwxg.cn
http://aghan.wwxg.cn
http://www.hrbkazy.com/news/81504.html

相关文章:

  • 网站建设业务员怎么着客户深圳网站公司排名
  • 网业怎么保存到桌面seo关键词优化报价
  • 山东网站建设找哪家网站优化排名推广
  • 做网站算运营吗长尾关键词举例
  • 贵阳做网站好的公司域名估价
  • 免费个人网站注册方法创意广告
  • 用什么网站做封面最好智慧软文发布系统
  • 备案网站容易被收录网络营销优秀案例
  • html5网站抓取网络优化工程师骗局
  • 医疗网站建设计划书优质友情链接
  • 苏州做外贸网站seo内部优化包括哪些内容
  • 深圳石岩做网站的公司山东seo推广公司
  • 国外做网站的软件如何查询百度收录情况
  • 手机产品展示网站模板武汉网站建设推广公司
  • 工商联网站建设方案友情链接平台站长资源
  • 做网站需要些什么资料seo百家论坛
  • 域名网站购买怎么搭建自己的网站
  • 手机如何建立网站平台常用的seo查询工具有哪些
  • 企业网站源码程序多少钱?武汉企业seo推广
  • 仿政府网站国内seo做最好的公司
  • 搜索视频 网站开发模板网站如何建站
  • 刷q币网站建设以网红引流促业态提升
  • 做医疗竞价网站百度推广官方电话
  • 浏览器免费下载seo免费优化工具
  • wordpress 3.8seochinaz查询
  • 怎样用html制作网站营销方式都有哪些
  • 搭建广告网站费用排名优化服务
  • 网站内容建设方法步骤链爱交易平台
  • 网站建设上市公司seo是什么意思知乎
  • 在线做网站怎么做百度关键词热搜