测开之路七十八:性能测试蓝图之视图层
Posted zhongyehai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测开之路七十八:性能测试蓝图之视图层相关的知识,希望对你有一定的参考价值。
from flask import request
from flask import jsonify
from flask import Blueprint
from flask import render_template
from performance.logic import Logic
performance = Blueprint(‘performance‘, __name__,
static_folder=‘static‘,
template_folder=‘templates‘,
url_prefix=‘/performance‘)
@performance.route(‘/‘)
def index():
""" 首页 """
return render_template("performance.html")
@performance.route(‘/api/v1/start‘, methods=[‘POST‘])
def api_v1_start():
""" 执行压测 """
data = request.get_json()
# 判断host必传
if ‘host‘ not in data or not data[‘host‘]:
return jsonify(
‘status‘: 400,
‘message‘: "invalid paramenter [‘host‘]",
‘data‘: data
)
# 判断代码必传
if ‘code‘ not in data or not data[‘code‘]:
return jsonify(
‘status‘: 400,
‘message‘: "invalid paramenter [‘code‘]",
‘data‘: data
)
# 执行运行逻辑
try:
case_id, _, _ = Logic().start(data)
return jsonify(
‘status‘: 0,
‘message‘: ‘success‘,
‘data‘: case_id
)
except Exception as error:
return jsonify(
‘status‘: 500,
‘message‘: str(error),
‘data‘: data,
)
以上是关于测开之路七十八:性能测试蓝图之视图层的主要内容,如果未能解决你的问题,请参考以下文章