添加接口测试模块
This commit is contained in:
parent
f521b28c7d
commit
fde22729e6
|
@ -1,6 +1,6 @@
|
|||
from flask import Flask
|
||||
from flask_bootstrap import Bootstrap
|
||||
from app.view import user,uitest,utils
|
||||
from app.view import user,uitest,utils,apinew
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object('config')
|
||||
|
@ -8,4 +8,5 @@ bootstrap = Bootstrap(app)
|
|||
app.register_blueprint(user.mod)
|
||||
app.register_blueprint(uitest.mod)
|
||||
app.register_blueprint(utils.mod)
|
||||
app.register_blueprint(apinew.mod)
|
||||
from app import views
|
||||
|
|
|
@ -0,0 +1,223 @@
|
|||
appKey = 'abc'
|
||||
|
||||
class api_manage():
|
||||
|
||||
def build_api_url(self,api_info,osign_list,type='default',host_id=''):
|
||||
"""
|
||||
Build test url for given api info.
|
||||
|
||||
:param api_info: json data with api info.
|
||||
e.g: {'url': {'host': 'http://172.16.100.53/sdk_bkd_qa', 'url': '/sdkapi/v2/config/client.do', 'type': 'sdkapi'}, 'paras': {'sdkVer': '{sdkVer}', 'gameUserId': 'gameuser1', 'osign': '8b28178232f363dcc18cbddeab5efc6e', 'appId': 'testLogin', 'userId': '-1', 'ghwToken': '', 'osVer': '{osVer}', 'serverId': 'server1', 'sdkType': '{osVer}', 'clientId': 'newjerryclientID1553063211469993', 'platform': 'GUEST', 'os': '{os}', 'runPlatform': '{runPlatform}', 'bindType': '1'}}
|
||||
:param osign_list: The list for paras to be reogin. e.g: ['appId', 'appKey', 'clientId', 'os', 'sdkVer', 'sdkType', 'runPlatform']
|
||||
:param type: by default , first value will be selected for para. If type is set to be random , a random value will be selected from paras.py file.
|
||||
:param host_id: the host you want to test with.
|
||||
0: 53
|
||||
1:product
|
||||
2:product cn
|
||||
3:sdk-test1
|
||||
4:sdk-test1 cn
|
||||
:return: the final url. e.g: http://172.16.100.53/sdk_bkd_qa/sdkapi/v2/config/client.do?sdkVer=3.7.0.1&gameUserId=gameuser1&osign=2eea2c803ae16f0acb02ebac226f1731&appId=testLogin&userId=-1&ghwToken=&osVer=10.0&serverId=server1&sdkType=8.0&clientId=newjerryclientID1553063211469993&platform=GUEST&os=mac&runPlatform=android&bindType=1
|
||||
|
||||
"""
|
||||
para_info = self.get_para_info(api_info,osign_list,type=type)
|
||||
if host_id =='':
|
||||
host = api_info['url']['host']
|
||||
else:
|
||||
from app.api_new import paras
|
||||
host = getattr(paras.paraValues(), 'sdkHosts')[host_id]
|
||||
url = host+api_info['url']['url']+'?'+self.dict_2_str(para_info)
|
||||
return url
|
||||
|
||||
def split_api_info(self,example_url):
|
||||
"""
|
||||
This function will split all infomation from a given url, including host, url path,paras.
|
||||
|
||||
:param example_url: http://172.16.100.53/sdk_bkd_qa/sdkapi/v2/config/client.do?sdkVer=3.7.0.1&gameUserId=gameuser1&osign=2eea2c803ae16f0acb02ebac226f1731&appId=testLogin&userId=-1&ghwToken=&osVer=10.0&serverId=server1&sdkType=8.0&clientId=newjerryclientID1553063211469993&platform=GUEST&os=mac&runPlatform=android&bindType=1
|
||||
:return: json format data, e.g: {'url': {'host': 'http://172.16.100.53/sdk_bkd_qa', 'url': '/sdkapi/v2/config/client.do', 'type': 'sdkapi'}, 'paras': {'sdkVer': '{sdkVer}', 'gameUserId': 'gameuser1', 'osign': '8b28178232f363dcc18cbddeab5efc6e', 'appId': 'testLogin', 'userId': '-1', 'ghwToken': '', 'osVer': '{osVer}', 'serverId': 'server1', 'sdkType': '{osVer}', 'clientId': 'newjerryclientID1553063211469993', 'platform': 'GUEST', 'os': '{os}', 'runPlatform': '{runPlatform}', 'bindType': '1'}}
|
||||
|
||||
"""
|
||||
api_url,para_url = example_url.split('?')
|
||||
paras = para_url.split('&')
|
||||
para_list = {}
|
||||
for para in paras:
|
||||
para_name,value = para.split('=')
|
||||
para_list[para_name]=value
|
||||
api_info = {}
|
||||
api_info['url']=self.split_url_info(api_url)
|
||||
api_info['paras']=para_list
|
||||
return api_info
|
||||
|
||||
def split_url_info(self,url):
|
||||
"""
|
||||
This function will split all infomation from a given url, including host, url path,type.
|
||||
|
||||
:param url:
|
||||
:return:
|
||||
"""
|
||||
api_type_list = ['/sdkapi','/cpapi','/api/']
|
||||
url_info={}
|
||||
host, api_url ,type ='','',''
|
||||
for api_type in api_type_list:
|
||||
if api_type in url:
|
||||
host,api_url = url.split(api_type)
|
||||
api_url = api_type+api_url
|
||||
type = api_type.replace('/','')
|
||||
break
|
||||
url_info['host']=host
|
||||
url_info['url']=api_url
|
||||
url_info['type']=type
|
||||
return url_info
|
||||
|
||||
def get_para_info(self,api_info,osign_list,type='default', needOsign=True):
|
||||
"""
|
||||
Get target value for all paras and do the osign process.
|
||||
|
||||
:param api_info:
|
||||
:param osign_list:
|
||||
:param type:
|
||||
:param needOsign:
|
||||
:return:
|
||||
"""
|
||||
para_info = api_info['paras']
|
||||
para_info = self.get_api_paras(para_info,type=type)
|
||||
if needOsign:
|
||||
para_info = self.api_osign(para_info,osign_list,appkey=appKey)
|
||||
return para_info
|
||||
|
||||
|
||||
def get_api_paras(self,para_info,type='default'):
|
||||
"""
|
||||
Convert all changeable values in the para list.
|
||||
|
||||
:param para_info:
|
||||
:param type:
|
||||
:return:
|
||||
"""
|
||||
for para in para_info:
|
||||
if '{' in para_info[para] and '}' in para_info[para]:
|
||||
para_info[para]=self.get_para_values(para_info[para],type=type)
|
||||
return para_info
|
||||
|
||||
def get_para_values(self,para_name,type='default'):
|
||||
"""
|
||||
Convert para's value to target value. If you want to set a para to be changeable, set the value to be {paraname} in api info. e.g: 'sdkType': '{sdkType}'
|
||||
the value is saved on paras.py , such as : sdkType = ['html5','android','ios']
|
||||
:param para_info:
|
||||
:param type: there are three types:
|
||||
default : return the first value on the value list.
|
||||
random : return a random value on the value list.
|
||||
all : return the the whole value list.
|
||||
:return:
|
||||
"""
|
||||
para_name = para_name.replace('{','')
|
||||
para_name = para_name.replace('}','')
|
||||
from app.api_new import paras
|
||||
try:
|
||||
values = getattr(paras.paraValues(), para_name)
|
||||
except AttributeError as e:
|
||||
print(e)
|
||||
values = []
|
||||
if len(values)>1:
|
||||
if type=='all':
|
||||
return values
|
||||
elif type == 'random':
|
||||
import random
|
||||
randomIndex = random.randrange(1,100)%len(values)
|
||||
return values[randomIndex]
|
||||
else:
|
||||
return values[0]
|
||||
else:
|
||||
return values
|
||||
|
||||
def api_osign(self,para_info, osign_list,appkey=appKey):
|
||||
"""
|
||||
Calculate the osign value using the osign list.
|
||||
:param para_info:
|
||||
:param osign_list:
|
||||
:param appkey:
|
||||
:return:
|
||||
"""
|
||||
para_info['osign'] = self.getOsign(para_info, osign_list, appkey=appkey)
|
||||
return para_info
|
||||
|
||||
def getOsign(self,para_info, osignList, appkey):
|
||||
"""
|
||||
The real osign method.
|
||||
|
||||
:param para_info:
|
||||
:param osignList:
|
||||
:param appkey:
|
||||
:return:
|
||||
"""
|
||||
paraPand = ''
|
||||
print('osign list is :',osignList)
|
||||
for para in osignList:
|
||||
if para == 'appKey':
|
||||
paraPand += appkey
|
||||
else:
|
||||
paraPand += str(para_info[para])
|
||||
print(para_info[para])
|
||||
print(paraPand)
|
||||
return self.md5(paraPand)
|
||||
|
||||
def md5(self,preosign):
|
||||
"""
|
||||
MD5 osign.
|
||||
:param preosign:
|
||||
:return:
|
||||
"""
|
||||
import hashlib
|
||||
m = hashlib.md5()
|
||||
preosign = preosign.encode('utf-8')
|
||||
print(preosign)
|
||||
m.update(preosign)
|
||||
return m.hexdigest()
|
||||
|
||||
def dict_2_str(self,para_info):
|
||||
'''
|
||||
将字典变成,key='value',key='value' 的形式
|
||||
'''
|
||||
tmplist = []
|
||||
import urllib.parse
|
||||
for k, v in para_info.items():
|
||||
if str(k) != 'appKey':
|
||||
tmp = "%s=%s" % (str(k), urllib.parse.quote(str(v)))
|
||||
tmplist.append(tmp)
|
||||
return '&'.join(tmplist)
|
||||
|
||||
|
||||
|
||||
def sendRequest(self,url, usingHeader=True):
|
||||
import httplib2
|
||||
print(url)
|
||||
http = httplib2.Http(timeout=30)
|
||||
headers1 = {'Content-type': 'application/json;charset=utf8',
|
||||
'Referer': 'http://game.chipsgames.com/sdk_resource/h5/index.html?channelId=jerrychannel1&campaignId=jerrycampaign1'}
|
||||
headers2 = {'Content-type': 'application/json;charset=utf8',
|
||||
'Referer': 'http://172.16.100.55/sdk_resource/h5/index.html?channelId=jerrychannel1&campaignId=jerrycampaign1'}
|
||||
# headers = {'Content-type': 'application/json;charset=utf8'}
|
||||
tryTime = 3
|
||||
while tryTime:
|
||||
try:
|
||||
if usingHeader:
|
||||
response, content = http.request(url, 'POST', headers=headers2)
|
||||
else:
|
||||
response, content = http.request(url, 'POST', headers=headers1)
|
||||
content = content.decode('utf-8')
|
||||
break
|
||||
except Exception as e:
|
||||
response = "Error"
|
||||
content = e
|
||||
tryTime += -1
|
||||
return response, content
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
url = "http://172.16.100.53/sdk_bkd_qa/sdkapi/v2/config/client.do?sdkVer={sdkVer}&gameUserId=gameuser1&osign=8b28178232f363dcc18cbddeab5efc6e&appId=testLogin&userId=-1&ghwToken=&osVer={osVer}&serverId=server1&sdkType={osVer}&clientId=newjerryclientID1553063211469993&platform=GUEST&os={os}&runPlatform={runPlatform}&bindType=1"
|
||||
api_info = api_manage().get_api_paras(api_manage().split_api_info(url))
|
||||
print(api_info)
|
||||
osign_list = ['appId', 'appKey', 'clientId', 'os', 'sdkVer', 'sdkType', 'runPlatform']
|
||||
# print(api_manage().build_api_url(api_info,osign_list))
|
||||
# print(api_manage().build_api_url(api_info,osign_list,type='random',host_id=1))
|
||||
from app.db import test_api_new_manange
|
||||
test_api_new_manange.test_api_new_manange().new_test_api(name='client',product=api_info['url']['type'],module='config',url=api_info['url']['url'],paras=api_info['paras'],osign_list=osign_list,description='test')
|
|
@ -0,0 +1,16 @@
|
|||
class paraValues:
|
||||
def __init__(self):
|
||||
|
||||
self.gamePlatform = ['chipsgames','fbcanvas','officialwebsit','fbmessenger','android','ios','others']
|
||||
self.locale = ['en_US','zh_CN']
|
||||
self.sdkVer = ['1.0','3.8.0','3.6.7','3.7.0.1']
|
||||
self.browser = ['Chrome','Firefox','Safari','IE']
|
||||
self.sdkType = ['android','html5','ios']
|
||||
self.runPlatform = ['android','ios','html5','fbinstant','miniclient','gameroom']
|
||||
self.osVer = ['8.0','10.0']
|
||||
self.browserVersion = ['70.0.3538.77','69.0.3538.77','68.0.3538.77']
|
||||
self.os = ['android','ios','windows','mac']
|
||||
self.browserType = ['1','2']
|
||||
self.bindType = ['1','2']
|
||||
self.sdkHosts = [ "http://172.16.100.53/sdk_bkd_qa/","https://api.wingsdk.com/", "https://api.wingsdk.cn/","https://sdk-test1.gamehollywood.com/sdk_bkd_qa/","http://sdk-test1.wingsdk.cn/sdk_bkd_qa/"]
|
||||
self.CGHosts = [ "http://172.16.100.165/","http://apipre.chipsgamestest.com", "https://api.chipsgames.com"]
|
|
@ -0,0 +1,70 @@
|
|||
import string
|
||||
from app import useDB,log
|
||||
|
||||
|
||||
class test_api_new_manange():
|
||||
#新增接口测试用例
|
||||
def new_test_api(self,product,module,name,url,paras,osign_list,description):
|
||||
paras = paras.replace('"',"'")
|
||||
sql = string.Template('insert into api_new (product,module,name,url,paras,osign_list,description) values ("$product","$module","$name","$url","$paras","$osign_list","$description");')
|
||||
sql = sql.substitute(product=product,module=module,name=name,url=url,paras=paras,osign_list=osign_list,description=description)
|
||||
try:
|
||||
useDB.useDB().insert(sql)
|
||||
result = 1
|
||||
except :
|
||||
result = 0
|
||||
return result
|
||||
|
||||
#查询测试用例配置信息
|
||||
def show_test_api(self, conditionList, valueList, fieldlist, rows,type='all'):
|
||||
from app.api_new import api_manage
|
||||
import json
|
||||
print(conditionList, valueList, fieldlist, rows)
|
||||
condition = ''
|
||||
if len(conditionList)!=0:
|
||||
for i in range(len(conditionList)):
|
||||
if str(conditionList[i])=='id':
|
||||
if str(valueList[i])!='':
|
||||
condition += ' and ' + str(conditionList[i]) + ' =' + str(valueList[i])
|
||||
elif str(valueList[i])!='':
|
||||
condition += ' and ' + str(conditionList[i]) + ' like "%' + str(valueList[i]) + '%"'
|
||||
results = []
|
||||
sql = 'select id,product,module,name,url,paras,osign_list,description from api_new where 1=1 and status=1'+str(condition)+ ' order by id desc limit ' + str(rows) + ';'
|
||||
list = useDB.useDB().search(sql)
|
||||
log.log().logger.info('cases : %s ' %list)
|
||||
for i in range(len(list)):
|
||||
result = {}
|
||||
result['id'] = list[i][0]
|
||||
result['product'] = list[i][1]
|
||||
result['module'] = list[i][2]
|
||||
result['name'] = list[i][3]
|
||||
result['url'] = list[i][4]
|
||||
paras = list[i][5].replace("'",'"')
|
||||
if type=='default':
|
||||
paras = api_manage.api_manage().get_api_paras(para_info=json.loads(paras),type='default')
|
||||
elif type=='ramdon':
|
||||
paras = api_manage.api_manage().get_api_paras(para_info=json.loads(paras),type='ramdon')
|
||||
result['paras'] = json.dumps(paras).replace('"',"'")
|
||||
result['osign_list'] = list[i][6]
|
||||
result['description'] = list[i][7]
|
||||
results.append(result)
|
||||
return results
|
||||
|
||||
|
||||
#删除接口测试用例
|
||||
def del_test_api(self,id):
|
||||
return self.update_test_api(id,fieldlist=['status'],valueList=['0'])
|
||||
|
||||
#修改接口测试用例
|
||||
def update_test_api(self,id,fieldlist,valueList):
|
||||
update_value = '%s = "%s"' %(fieldlist[0],valueList[0].replace('"',"'"))
|
||||
for i in range(1,len(fieldlist)):
|
||||
update_value += ', %s = "%s"' %(fieldlist[i],valueList[i].replace('"',"'"))
|
||||
sql = string.Template('update api_new set $field where id = "$id";')
|
||||
sql = sql.substitute(field = update_value, id = id)
|
||||
try:
|
||||
useDB.useDB().insert(sql)
|
||||
result = 1
|
||||
except :
|
||||
result = 0
|
||||
return result
|
|
@ -0,0 +1,555 @@
|
|||
|
||||
//// submit form
|
||||
//function submitAddForm() {
|
||||
// $("#new_test_api").validate();
|
||||
// $.validator.setDefaults({
|
||||
// submitHandler: function() {
|
||||
// document.getElementById("new_test_api").submit();
|
||||
// }
|
||||
//});
|
||||
// }
|
||||
|
||||
|
||||
|
||||
$(function () {
|
||||
//初始化可编辑表格
|
||||
// modelEdit();
|
||||
|
||||
// //获取测试ip 列表
|
||||
// getApiUrl();
|
||||
|
||||
var oTable = new TableInit();
|
||||
oTable.Init();
|
||||
});
|
||||
|
||||
|
||||
|
||||
var TableInit = function () {
|
||||
var oTableInit = new Object();
|
||||
//初始化Table
|
||||
oTableInit.Init = function () {
|
||||
$('#tb_test_api').bootstrapTable({
|
||||
url: '/test_api_new.json', //请求后台的URL(*)
|
||||
method: 'get', //请求方式(*)
|
||||
toolbar: '#toolbar', //工具按钮用哪个容器
|
||||
striped: true, //是否显示行间隔色
|
||||
cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
|
||||
pagination: true, //是否显示分页(*)
|
||||
sortable: true, //是否启用排序
|
||||
sortOrder: "asc", //排序方式
|
||||
queryParams: oTableInit.queryParams,//传递参数(*)
|
||||
sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
|
||||
pageNumber:1, //初始化加载第一页,默认第一页
|
||||
pageSize: 10, //每页的记录行数(*)
|
||||
pageList: [10, 25, 50, 100, 500], //可供选择的每页的行数(*)
|
||||
search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
|
||||
strictSearch: false,
|
||||
showColumns: true, //是否显示所有的列
|
||||
showRefresh: true, //是否显示刷新按钮
|
||||
minimumCountColumns: 2, //最少允许的列数
|
||||
clickToSelect: true, //是否启用点击选中行
|
||||
height: 500, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
|
||||
uniqueId: "id", //每一行的唯一标识,一般为主键列
|
||||
showToggle:true, //是否显示详细视图和列表视图的切换按钮
|
||||
cardView: false, //是否显示详细视图
|
||||
detailView: false, //是否显示父子表
|
||||
columns: [{
|
||||
checkbox: true
|
||||
}, {
|
||||
field: 'id',
|
||||
title: 'id',
|
||||
width : '10'
|
||||
}, {
|
||||
field: 'product',
|
||||
title: '所属产品',
|
||||
width : '20'
|
||||
}, {
|
||||
field: 'module',
|
||||
title: '模块',
|
||||
width : '20'
|
||||
}, {
|
||||
field: 'name',
|
||||
title: '接口名称',
|
||||
width : '20'
|
||||
}, {
|
||||
field: 'url',
|
||||
title: '接口地址',
|
||||
width : '20'
|
||||
},
|
||||
{
|
||||
field: 'operate',
|
||||
title: '操作',
|
||||
// align: 'center',
|
||||
formatter: function (value, row, index) {
|
||||
var a = '<a href="javascript:;" onclick="window.location.href=(\'/edit_test_api_new?id='+ row.id + '\')">编辑</a> ';
|
||||
var d = '<a href="javascript:;" onclick="window.location.href=(\'/test_api_new_test?id='+ row.id + '\')">测试</a> ';
|
||||
var b = '<a href="javascript:;" onclick="delete_test_api_new(\'' + row.id + '\')">删除</a> ';
|
||||
var div = "<div style='width:30px;'>"+a+d+b+"</div>";
|
||||
return div;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'osign_list',
|
||||
title: '加密参数列表',
|
||||
width : '50'
|
||||
},{
|
||||
field: 'description',
|
||||
title: '备注'
|
||||
// width : '50'
|
||||
},
|
||||
{
|
||||
field: 'paras',
|
||||
title: '参数列表'
|
||||
// width : '50'
|
||||
}
|
||||
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
function operateFormatter(value, row, index) {
|
||||
return [
|
||||
'<button type="button" class="RoleOfEdit btn btn-default btn-sm" style="margin-right:15px;">编辑</button>',
|
||||
'<button type="button" class="RoleOfDelete btn btn-default btn-sm" style="margin-right:15px;">删除</button>'
|
||||
].join('');
|
||||
}
|
||||
|
||||
window.operateEvents = {
|
||||
'click .RoleOfEdit': function (e, value, row, index) {
|
||||
window.location.href=('/add_test_api');
|
||||
},
|
||||
'click .RoleOfDelete': function (e, value, row, index) {
|
||||
alert("B");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//得到查询的参数
|
||||
oTableInit.queryParams = function (params) {
|
||||
var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
|
||||
limit: params.limit, //页面大小
|
||||
offset: params.offset, //页码
|
||||
name: $("#name").val(),
|
||||
module: $("#module").val(),
|
||||
type:"test_api"
|
||||
};
|
||||
return temp;
|
||||
};
|
||||
return oTableInit;
|
||||
};
|
||||
|
||||
|
||||
function searchTestCase(){
|
||||
var name=$('#name').val();
|
||||
var product=$('#product').val();
|
||||
var module=$('#module').val();
|
||||
$('#tb_test_api').bootstrapTable('refresh', {url: '/test_api_new.json',query:{'name': name,'product':product,'module':module}});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addApiNew(){
|
||||
var paras = getParaTable();
|
||||
$.ajax(
|
||||
{
|
||||
url: "/add_test_api_new.json",
|
||||
data:{'name':$('#name').val(),'product':$('#product').val(),'module':$('#module').val(),'url':$('#url').val(),'osign_list':$('#osignList').val(),'description':$('#description').val(),'paras':paras},
|
||||
type: "post",
|
||||
async: false,
|
||||
// dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
console.log(data);
|
||||
console.log(data['code']);
|
||||
if(data['code']==200)
|
||||
{
|
||||
alert('新增成功!');
|
||||
window.location.href=('/test_api_new');
|
||||
}
|
||||
else
|
||||
{
|
||||
// $("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
alert('失败,请重试');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
// document.getElementById('btn_back').click();
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
// document.getElementById('btn_back').click();
|
||||
window.location.href=('/test_api_new');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function update_api_new(id){
|
||||
var paras = getParaTable();
|
||||
$.ajax(
|
||||
{
|
||||
url: "/update_test_api_new.json",
|
||||
data:{'id':id,'name':$('#name').val(),'product':$('#product').val(),'module':$('#module').val(),'url':$('#url').val(),'osign_list':$('#osign_list').val(),'description':$('#description').val(),'paras':paras},
|
||||
type: "post",
|
||||
// dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
console.log(data);
|
||||
console.log(data['code']);
|
||||
if(data['code']==200)
|
||||
{
|
||||
alert('保存成功!');
|
||||
// document.getElementById('btn_back').click();
|
||||
window.location.href=('/test_api_new');
|
||||
}
|
||||
else
|
||||
{
|
||||
// $("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
alert('失败,请重试');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
// document.getElementById('btn_back').click();
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
window.location.href=('/test_api_new');
|
||||
// document.getElementById('btn_back').click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 编辑表单
|
||||
function get_api_info(active_id)
|
||||
|
||||
{
|
||||
if(!active_id)
|
||||
{
|
||||
alert('Error!');
|
||||
return false;
|
||||
}
|
||||
$.ajax(
|
||||
{
|
||||
url: "/test_api_new.json",
|
||||
data:{"id":active_id,'type':'all'},
|
||||
type: "get",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
// 解析json数据
|
||||
var data_obj = data.rows[0]
|
||||
console.log(data_obj.paras);
|
||||
var paras = JSON.parse(data_obj.paras.replace(/'/g, '"'));
|
||||
// var paras = JSON.parse(data_obj.paras);
|
||||
console.log(paras);
|
||||
console.log(typeof(paras));
|
||||
var paras = JSON.parse(paras);
|
||||
console.log(typeof(paras));
|
||||
console.log(paras['appId']);
|
||||
// var paras = data_obj.paras;
|
||||
$("#name").val(data_obj.name);
|
||||
$("#description").val(data_obj.description);
|
||||
$("#url").val(data_obj.url);
|
||||
$("#product").val(data_obj.product);
|
||||
$("#module").val(data_obj.module);
|
||||
$("#osign_list").val(data_obj.osign_list);
|
||||
setParaTable(paras);
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
// alert('操作失败');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 删除表单
|
||||
function delete_test_api_new(active_id)
|
||||
{
|
||||
if(confirm("确认删除吗?"))
|
||||
{
|
||||
if(!active_id)
|
||||
{
|
||||
alert('Error!');
|
||||
return false;
|
||||
}
|
||||
$.ajax(
|
||||
{
|
||||
url: "/delete_test_api_new",
|
||||
data:{"id":active_id},
|
||||
type: "post",
|
||||
beforeSend:function()
|
||||
{
|
||||
$("#tip").html("<span style='color:blue'>正在处理...</span>");
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data.code = 200)
|
||||
{
|
||||
alert('恭喜,删除成功!');
|
||||
$("#tip").html("<span style='color:blueviolet'>恭喜,删除成功!</span>");
|
||||
|
||||
|
||||
document.getElementById('btn_query').click();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
alert('失败,请重试'+data.msg);
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function run_test_api(id){
|
||||
$.ajax(
|
||||
{
|
||||
url: "/runurltest.json",
|
||||
data:{"id":id},
|
||||
type: "get",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
// 解析json数据
|
||||
var data = data;
|
||||
if(data.code==200){
|
||||
alert('success!');
|
||||
window.location.href=('/test_api_batch_case_detail?batch_id=1&url_id='+id+'&id='+data.test_case_id);
|
||||
}else{
|
||||
alert('code is :'+data.code+' and message is :'+data.msg);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
// alert('操作失败');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
function runTest(){
|
||||
var id=$("#urlId").val();
|
||||
var apiUrl=$('#apiUrl option:selected') .val();
|
||||
$.ajax(
|
||||
{
|
||||
url: "/runurltest.json",
|
||||
data:{"id":id,"apiUrl":apiUrl},
|
||||
type: "get",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
// 解析json数据
|
||||
var data = data;
|
||||
if(data.code==200){
|
||||
// alert('success!');
|
||||
window.location.href=('/test_api_case_run?batch_id=1&url_id='+id+'&id='+data.test_case_id);
|
||||
}else{
|
||||
alert('code is :'+data.code+' and message is :'+data.msg);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
// alert('操作失败');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function readPara(){
|
||||
var url = $("#paraList").val();
|
||||
$.ajax(
|
||||
{
|
||||
url: "/split_test_api_url.json",
|
||||
data:{'url':url},
|
||||
type: "get",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
// 解析json数据
|
||||
var data = data;
|
||||
console.log(data);
|
||||
$("#name").val(data['url']['url']);
|
||||
$("#url").val(data['url']['url']);
|
||||
$("#module").val(data['url']['url']);
|
||||
$("#description").val(data['url']['url']);
|
||||
if (data['url']['type']=='api'){
|
||||
setProduct('CG');
|
||||
}else{
|
||||
setProduct('sdkapi');
|
||||
}
|
||||
setParaTable(data['paras']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
// alert('操作失败');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function setProduct(type)
|
||||
{
|
||||
setSelectOption('product',type);
|
||||
}
|
||||
|
||||
function setSelectOption(selectObj, value) {
|
||||
selectObj = document.getElementById(selectObj);
|
||||
// 清空选项
|
||||
// console.log(value);
|
||||
// console.log(selectObj.options);
|
||||
for (var i =0;i< selectObj.options.length;i++) {
|
||||
// console.log(selectObj.options[i].value,value);
|
||||
if(selectObj.options[i].value==value) {
|
||||
selectObj.options[i].selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setParaTable(para_info){
|
||||
var tbodies= $("#para_table");
|
||||
console.log(para_info);
|
||||
for (var key in para_info){
|
||||
// console.log(key);
|
||||
// console.log(para_info[key]);
|
||||
var tr = '<tr>';
|
||||
tr+= "<td class='hidden-phone'><a class='para_name' data-placement='right'>"+key+"</a></td>";
|
||||
tr+= "<td class='hidden-phone'><a class='para_value' data-placement='right'>"+para_info[key]+"</a></td>";
|
||||
if (key.indexOf("Ver") != -1 || key.indexOf("Type") != -1 || key.indexOf("Platform") != -1){
|
||||
tr+= "<td class='hidden-phone'><input class='isParamized' type='checkbox' checked='checked'></td>";
|
||||
}else{
|
||||
tr+= "<td class='hidden-phone'><input class='isParamized' type='checkbox'></td>";
|
||||
}
|
||||
tr += "<td class='hidden-phone'><input class='paramized_value' type='text' value='{"+key+"}'></td>";
|
||||
tr += '</tr>';
|
||||
// console.log(tr);
|
||||
tbodies.append(tr);
|
||||
// console.log(tbodies);
|
||||
}
|
||||
}
|
||||
|
||||
function getParaTable(){
|
||||
var tbodies= $("#para_table");
|
||||
var para_name_list = document.getElementsByClassName('para_name');
|
||||
var para_value_list = document.getElementsByClassName('para_value');
|
||||
var isParamized_list = document.getElementsByClassName('isParamized');
|
||||
var paramized_value_list = document.getElementsByClassName('paramized_value');
|
||||
|
||||
var paras = {};
|
||||
for (var i=0;i< para_name_list.length;i++){
|
||||
console.log(para_name_list[i].text+para_value_list[i].text+isParamized_list[i].checked+paramized_value_list[i].value);
|
||||
if (isParamized_list[i].checked){
|
||||
paras[para_name_list[i].text]=paramized_value_list[i].value;
|
||||
}else{
|
||||
paras[para_name_list[i].text]=para_value_list[i].text;
|
||||
}
|
||||
}
|
||||
console.log(paras);
|
||||
var jsonString = JSON.stringify(paras);
|
||||
console.log(jsonString);
|
||||
return jsonString;
|
||||
}
|
|
@ -0,0 +1,374 @@
|
|||
$(function () {
|
||||
var id=$("#id").val();
|
||||
get_info(id);
|
||||
fullurl();
|
||||
});
|
||||
|
||||
|
||||
|
||||
//查找apiUrl
|
||||
function getApiHostList(type){
|
||||
$.ajax(
|
||||
{
|
||||
url: "/test_api_host.json",
|
||||
data:{'type':type},
|
||||
type: "get",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
// 解析json数据
|
||||
var data = data;
|
||||
console.log(data);
|
||||
$("#host_id").html("");
|
||||
var option_group='';
|
||||
for (var i=0;i<data.rows.length;i++){
|
||||
var selectdata=data.rows[i];
|
||||
var option='<option value="'+i+'">'+data.rows[i]+'</option>';
|
||||
console.log(option);
|
||||
option_group+=option;
|
||||
console.log(option_group);
|
||||
}
|
||||
console.log(option_group);
|
||||
$("#host_id").append(option_group);
|
||||
$("#host").val(data.rows[0]);
|
||||
fullurl();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
// alert('操作失败');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 编辑表单
|
||||
function get_info(active_id)
|
||||
{
|
||||
if(!active_id)
|
||||
{
|
||||
alert('Error!');
|
||||
return false;
|
||||
}
|
||||
$.ajax(
|
||||
{
|
||||
url: "/test_api_new.json",
|
||||
data:{"id":active_id,'type':'default'},
|
||||
type: "get",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
// 解析json数据
|
||||
var data_obj = data.rows[0]
|
||||
console.log(data_obj.paras);
|
||||
var paras = JSON.parse(data_obj.paras.replace(/'/g, '"'));
|
||||
console.log(paras);
|
||||
$("#name").val(data_obj.name);
|
||||
// $("#product").val(data_obj.product);
|
||||
$("#description").val(data_obj.description);
|
||||
$("#url").val(data_obj.url);
|
||||
$("#osign_list").val(data_obj.osign_list);
|
||||
console.log(paras);
|
||||
addBody(paras);
|
||||
getApiHostList(data_obj.product);
|
||||
reosign();
|
||||
// fullurl();
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
// alert('操作失败');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function addBody(content){
|
||||
|
||||
$("#tbody").html("");
|
||||
var tbody=document.getElementById('tbody');
|
||||
console.log('body is:'+tbody);
|
||||
// data =(new Function("","return "+content))();
|
||||
var data = content;
|
||||
for(var key in data){
|
||||
var tr=document.createElement('tr');
|
||||
var tdname=document.createElement('td')
|
||||
var tdvalue=document.createElement('td')
|
||||
tdvalue.contentEditable="true";
|
||||
tdname.innerHTML=key;
|
||||
tdvalue.innerHTML=data[key];
|
||||
tr.appendChild(tdname);
|
||||
tr.appendChild(tdvalue);
|
||||
tbody.appendChild(tr);
|
||||
|
||||
}
|
||||
|
||||
console.log('body is:'+tbody);
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// // 编辑表单
|
||||
//function runtest()
|
||||
// {
|
||||
// var mytable = document.getElementById('paraTable');
|
||||
// var url = $("#url").val();
|
||||
// var context={};
|
||||
// for(var i=1,rows=mytable.rows.length; i<rows; i++){
|
||||
// context[mytable.rows[i].cells[0].innerHTML]=mytable.rows[i].cells[1].innerHTML;
|
||||
// }
|
||||
// var context = JSON.stringify(context);
|
||||
//
|
||||
// $.ajax(
|
||||
// {
|
||||
// url: "/test_api_new.json",
|
||||
// data:{"url":url,"context":context},
|
||||
// type: "get",
|
||||
// dataType:"json",
|
||||
// beforeSend:function()
|
||||
// {
|
||||
// return true;
|
||||
// },
|
||||
// success:function(data)
|
||||
// {
|
||||
// if(data)
|
||||
// {
|
||||
// // 解析json数据
|
||||
// var data = data;
|
||||
//// alert(data);
|
||||
// var data_obj = data.rows[0];
|
||||
//// alert(data_obj);
|
||||
// // 赋值
|
||||
//// $("#url").val(url+'?'+paraList);
|
||||
// $("#response").val(data_obj.response);
|
||||
// $("#content").val(data_obj.content);
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
// // alert('操作失败');
|
||||
// }
|
||||
// },
|
||||
// error:function()
|
||||
// {
|
||||
// alert('请求出错');
|
||||
// },
|
||||
// complete:function()
|
||||
// {
|
||||
// // $('#tips').hide();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
|
||||
// 编辑表单
|
||||
function runapitest()
|
||||
{
|
||||
fullurl();
|
||||
var fullurlcontext = $("#fullurlcontext").val();
|
||||
$.ajax(
|
||||
{
|
||||
url: "/test_api_new_run.json",
|
||||
data:{"url":fullurlcontext},
|
||||
type: "post",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
// 解析json数据
|
||||
var data = data;
|
||||
// alert(data);
|
||||
var data_obj = data.rows[0];
|
||||
// alert(data_obj);
|
||||
// 赋值
|
||||
// $("#url").val(url+'?'+paraList);
|
||||
$("#response").val(data_obj.response);
|
||||
$("#content").val(data_obj.content);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
// alert('操作失败');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 编辑表单
|
||||
function reosign()
|
||||
{
|
||||
var mytable = document.getElementById('paraTable');
|
||||
var context={};
|
||||
for(var i=1,rows=mytable.rows.length; i<rows; i++){
|
||||
// context.push(mytable.rows[i].cells[0].innerHTML:mytable.rows[i].cells[1].innerHTML,);
|
||||
context[mytable.rows[i].cells[0].innerHTML]=mytable.rows[i].cells[1].innerHTML;
|
||||
}
|
||||
var context = JSON.stringify(context);
|
||||
var osign_list = $("#osign_list").val();
|
||||
$.ajax(
|
||||
{
|
||||
url: "/test_api_reosign_new.json",
|
||||
data:{"osign_list":osign_list,"context":context},
|
||||
type: "get",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data && data.code == '200')
|
||||
{
|
||||
// 解析json数据
|
||||
var data_obj = data.rows[0]
|
||||
console.log(data_obj.context);
|
||||
var paras = JSON.parse(data_obj.context.replace(/'/g, '"'));
|
||||
addBody(paras);
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
alert('重签名失败,请确认参数中是否有签名字段');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function changehost(){
|
||||
var selectedIndex = document.getElementById('host_id').selectedIndex;
|
||||
console.log(selectedIndex);
|
||||
var host = document.getElementById('host_id').options[selectedIndex].text;
|
||||
console.log(host);
|
||||
$("#host").val(host);
|
||||
fullurl();
|
||||
}
|
||||
|
||||
//function refreshhost(apiUrl){
|
||||
// $("#host").val(apiUrl);
|
||||
// $("#apiUrl").val(apiUrl);
|
||||
//}
|
||||
|
||||
function fullurl(){
|
||||
var host = $("#host").val();
|
||||
var url = $("#url").val();
|
||||
var mytable = document.getElementById('paraTable');
|
||||
var context='?';
|
||||
for(var i=1,rows=mytable.rows.length; i<rows; i++){
|
||||
if(i>1){
|
||||
context = context+'&' + mytable.rows[i].cells[0].innerHTML+'='+mytable.rows[i].cells[1].innerHTML;
|
||||
}
|
||||
else{
|
||||
context = context + mytable.rows[i].cells[0].innerHTML+'='+mytable.rows[i].cells[1].innerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
$("#fullurlcontext").val(host+url+context);
|
||||
}
|
||||
|
||||
|
||||
// 刷新前置参数
|
||||
function refresh_prepose(batch_id,url_id)
|
||||
{
|
||||
var url = $("#host").val();
|
||||
$.ajax(
|
||||
{
|
||||
url: "/test_api_refresh_prepose.json",
|
||||
data:{"url":url,"url_id":url_id,"batch_id":batch_id},
|
||||
type: "get",
|
||||
dataType:"json",
|
||||
beforeSend:function()
|
||||
{
|
||||
return true;
|
||||
},
|
||||
success:function(data)
|
||||
{
|
||||
if(data)
|
||||
{
|
||||
// alert('刷新前置参数成功!');
|
||||
window.location.reload();
|
||||
alert('刷新前置参数成功!');
|
||||
refreshhost(url);
|
||||
}
|
||||
else
|
||||
{
|
||||
// $("#tip").html("<span style='color:red'>失败,请重试</span>");
|
||||
alert('操作失败');
|
||||
}
|
||||
},
|
||||
error:function()
|
||||
{
|
||||
alert('请求出错');
|
||||
},
|
||||
complete:function()
|
||||
{
|
||||
// $('#tips').hide();
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,116 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}WingSDK 测试平台 - edit test api{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<script src="../static/jquery-1.12.4.js"></script>
|
||||
<script src="../static/scripts/util/init.js"></script>
|
||||
<script src="../static/scripts/util/util.js"></script>
|
||||
<script src="../static/scripts/api_new/test_api_new.js"></script>
|
||||
|
||||
<script src="../static/bootstrap-3.3.7-dist/dist/js/bootstrap.js"></script>
|
||||
<link href="../static/bootstrap-3.3.7-dist/dist/css/bootstrap.css" rel="stylesheet" />
|
||||
|
||||
<script src="../static/bootstrap-table-develop/dist/bootstrap-table.js"></script>
|
||||
<link href="../static/bootstrap-table-develop/dist/bootstrap-table.css" rel="stylesheet" />
|
||||
<script src="../static/scripts/util/jquery.validate.min.js"></script>
|
||||
<script>get_api_info({{id}});</script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="panel-body" style="padding-bottom:0px;">
|
||||
<h1 style="text-align:center">编辑接口</h1>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control required" id="paraList" name="paraList"
|
||||
placeholder="请输入参数URL">
|
||||
<button id="btn_copy" type="button" class="btn btn-default" onclick="readPara();">读取</button>
|
||||
</div>
|
||||
<div class="form-horizontal">
|
||||
<!--action="/save_new_test_case" method="post"-->
|
||||
<div class="form-group">
|
||||
<label for="id" class="col-sm-2 control-label">id</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="id" name="id"
|
||||
readonly="readonly" value="{{id}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-sm-2 control-label">名称</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="name" name="name"
|
||||
placeholder="请输入接口用例名称">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description" class="col-sm-2 control-label">描述</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="longtext" class="form-control" id="description" name="description"
|
||||
placeholder="请输入描述">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description" class="col-sm-2 control-label">所属产品</label>
|
||||
<div class="col-sm-10">
|
||||
<select class="form-control" onchange="selectOnchang(this)" id="product">
|
||||
<option value="">请选择</option>
|
||||
<option value="sdkapi">SDK api</option>
|
||||
<option value="CG">CG api</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description" class="col-sm-2 control-label">模块</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="module" name="module"
|
||||
placeholder="请输入接口所属模块">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-sm-2 control-label">接口地址</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="url" name="url"
|
||||
placeholder="请输入接口所属模块">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="osign_list" class="col-sm-2 control-label">签名参数</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="osign_list" name="osign_list"
|
||||
placeholder="请输入接口签名参数列表">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tb_para" class="col-sm-2 control-label">参数列表</label>
|
||||
<div class="col-sm-10">
|
||||
<table id="tb_para" class="table table-striped table-hover table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="hidden-phone">字段名称</th>
|
||||
<th class="hidden-phone">默认值</th>
|
||||
<th class="hidden-phone">是否参数化</th>
|
||||
<th class="hidden-phone">默认参数名</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="para_table">
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button id="submitButton" class="btn btn-default" onclick="update_api_new({{id}})">保存</button>
|
||||
<button id="btn_back" type="button" class="btn btn-default" onclick="window.location.href=('/test_api_new')">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.error{
|
||||
color:red;
|
||||
}
|
||||
</style>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -0,0 +1,107 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}WingSDK 测试平台 - new test api{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<script src="../static/jquery-1.12.4.js"></script>
|
||||
<script src="../static/scripts/util/init.js"></script>
|
||||
<script src="../static/scripts/util/util.js"></script>
|
||||
<script src="../static/scripts/api_new/test_api_new.js"></script>
|
||||
|
||||
<script src="../static/bootstrap-3.3.7-dist/dist/js/bootstrap.js"></script>
|
||||
<link href="../static/bootstrap-3.3.7-dist/dist/css/bootstrap.css" rel="stylesheet" />
|
||||
|
||||
<script src="../static/bootstrap-table-develop/dist/bootstrap-table.js"></script>
|
||||
<link href="../static/bootstrap-table-develop/dist/bootstrap-table.css" rel="stylesheet" />
|
||||
<script src="../static/scripts/util/jquery.validate.min.js"></script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="panel-body" style="padding-bottom:0px;">
|
||||
<h1 style="text-align:center">新增接口</h1>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control required" id="paraList" name="paraList"
|
||||
placeholder="请输入参数URL">
|
||||
<button id="btn_copy" type="button" class="btn btn-default" onclick="readPara();">读取</button>
|
||||
</div>
|
||||
<div class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-sm-2 control-label">名称</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="name" name="name"
|
||||
placeholder="请输入接口用例名称">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description" class="col-sm-2 control-label">描述</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="longtext" class="form-control" id="description" name="description"
|
||||
placeholder="请输入描述">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description" class="col-sm-2 control-label">所属产品</label>
|
||||
<div class="col-sm-10">
|
||||
<select class="form-control" onchange="selectOnchang(this)" id="product">
|
||||
<option value="">请选择</option>
|
||||
<option value="sdkapi">SDK api</option>
|
||||
<option value="CG">CG api</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="description" class="col-sm-2 control-label">模块</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="module" name="module"
|
||||
placeholder="请输入接口所属模块">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-sm-2 control-label">接口地址</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="url" name="url"
|
||||
placeholder="请输入接口所属模块">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="osignList" class="col-sm-2 control-label">签名参数</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control required" id="osignList" name="osignList"
|
||||
placeholder="请输入接口签名参数列表">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tb_para" class="col-sm-2 control-label">参数列表</label>
|
||||
<div class="col-sm-10">
|
||||
<table id="tb_para" class="table table-striped table-hover table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="hidden-phone">字段名称</th>
|
||||
<th class="hidden-phone">默认值</th>
|
||||
<th class="hidden-phone">是否参数化</th>
|
||||
<th class="hidden-phone">默认参数名</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="para_table">
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button id="submitButton" class="btn btn-default" onclick="addApiNew();">保存</button>
|
||||
<button id="btn_back" type="button" class="btn btn-default" onclick="window.location.href=('/test_api_new')">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.error{
|
||||
color:red;
|
||||
}
|
||||
</style>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -0,0 +1,125 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}WingSDK 测试平台 - 手工测试api{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<script src="../static/jquery-1.12.4.js"></script>
|
||||
<script src="../static/scripts/util/init.js"></script>
|
||||
<script src="../static/scripts/util/util.js"></script>
|
||||
<script src="../static/scripts/api_new/test_api_run_new.js"></script>
|
||||
|
||||
<script src="../static/bootstrap-3.3.7-dist/dist/js/bootstrap.js"></script>
|
||||
<link href="../static/bootstrap-3.3.7-dist/dist/css/bootstrap.css" rel="stylesheet" />
|
||||
|
||||
<script src="../static/bootstrap-table-develop/dist/bootstrap-table.js"></script>
|
||||
<link href="../static/bootstrap-table-develop/dist/bootstrap-table.css" rel="stylesheet" />
|
||||
<script src="../static/scripts/util/jquery.validate.min.js"></script>
|
||||
<!--<script>window.onload =function(){-->
|
||||
<!--document.getElementById('btn_fullurl').click();-->
|
||||
<!--}</script>-->
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div class="panel-body" style="padding-bottom:0px;">
|
||||
<h1 style="text-align:center">手动测试接口</h1>
|
||||
<form class="form-horizontal">
|
||||
<!--action="/save_new_test_case" method="post"-->
|
||||
<div class="form-group">
|
||||
<label for="id" class="col-sm-2 control-label">测试ID</label>
|
||||
<div class="col-sm-1">
|
||||
<input type="text" class="form-control readonly" id="id" name="id" value="{{id}}" readonly="readonly">
|
||||
</div>
|
||||
<label for="name" class="col-sm-2 control-label">name</label>
|
||||
<div class="col-sm-1">
|
||||
<input type="text" class="form-control readonly" id="name" name="name" readonly="readonly">
|
||||
</div>
|
||||
<label for="url" class="col-sm-2 control-label">url</label>
|
||||
<div class="col-sm-2">
|
||||
<input type="text" class="form-control readonly" id="url" name="url" readonly="readonly">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="osign_list" class="col-sm-2 control-label">加密参数列表</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control readonly" id="osign_list" name="osign_list" readonly="readonly">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="select-editable">
|
||||
<label for="host_id" class="col-sm-2 control-label">host</label>
|
||||
<div class="col-sm-10" >
|
||||
<select class="form-control" id="host_id" name="host_id" onchange="changehost();">
|
||||
<option value="">-请选择-</option>
|
||||
</select>
|
||||
<input class="form-control" type="text" id="host" value="" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-sm-2 control-label">完整链接</label>
|
||||
<div class="col-sm-10">
|
||||
<button id="btn_fullurl" type="button" class="btn btn-default" onclick="fullurl();">刷新链接</button>
|
||||
<textarea class="form-control required" id="fullurlcontext" name="content" cols="30" rows="3" readonly="readonly"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
||||
<label class="col-sm-2 control-label">参数列表 :</label>
|
||||
<div class="col-sm-10">
|
||||
<button id="btn_reosign" type="button" class="btn btn-default" onclick="reosign();">重算签名</button>
|
||||
<table id="paraTable" class="col-sm-2 control-tabel">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>参数名称</th>
|
||||
<th>参数值</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id='tbody'>
|
||||
</tbody>
|
||||
</table></div></div>
|
||||
<div class="form-group">
|
||||
<label for="response" class="col-sm-2 control-label">response</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea class="form-control required" id="response" name="response" cols="30" rows="3" readonly="readonly"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="content" class="col-sm-2 control-label">content</label>
|
||||
|
||||
<div class="col-sm-10">
|
||||
<textarea class="form-control required" id="content" name="content" cols="30" rows="3" readonly="readonly"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button id="btn_add" type="button" class="btn btn-default" onclick="window.location.href=('/test_api_new')">返回</button>
|
||||
<button id="btn_test" type="button" class="btn btn-default" onclick="runapitest();">测试</button>
|
||||
<!--<button id="btn_refresh_prepose" type="button" class="btn btn-default" onclick="refresh_prepose({{batch_id}},{{url_id}});">刷新前置参数</button>-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style type="text/css">
|
||||
*{
|
||||
margin:0px;
|
||||
padding:0px;
|
||||
}
|
||||
body table{
|
||||
border:1px solid black;
|
||||
}
|
||||
th{
|
||||
border:1px solid black;
|
||||
text-align:center;
|
||||
line-height:center;
|
||||
width:400px;
|
||||
height:30px;
|
||||
}
|
||||
td{
|
||||
border:1px solid black;
|
||||
text-align:center;
|
||||
line-height:center;
|
||||
}
|
||||
</style>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -0,0 +1,92 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}WingSDK 测试平台 - test apis{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<script src="../static/jquery-1.12.4.js"></script>
|
||||
<script src="../static/scripts/util/init.js"></script>
|
||||
<script src="../static/scripts/util/util.js"></script>
|
||||
<script src="../static/scripts/api_new/test_api_new.js"></script>
|
||||
|
||||
<script src="../static/bootstrap-3.3.7-dist/dist/js/bootstrap.js"></script>
|
||||
<link href="../static/bootstrap-3.3.7-dist/dist/css/bootstrap.css" rel="stylesheet" />
|
||||
|
||||
<script src="../static/bootstrap-table-develop/dist/bootstrap-table.js"></script>
|
||||
<link href="../static/bootstrap-table-develop/dist/bootstrap-table.css" rel="stylesheet" />
|
||||
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div class="panel-body" style="padding-bottom:0px;">
|
||||
<h1 style="text-align:center">查询接口</h1>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">查询条件</div>
|
||||
<div class="panel-body">
|
||||
<form id="formSearch" class="form-horizontal">
|
||||
<div class="form-group" style="margin-top:15px">
|
||||
<label class="control-label col-sm-1" for="name">名称</label>
|
||||
<div class="col-sm-2">
|
||||
<input type="text" class="form-control" id="name" name="name">
|
||||
</div>
|
||||
<label class="control-label col-sm-1" for="product">所属产品</label>
|
||||
<div class="col-sm-2">
|
||||
<select class="form-control" onchange="selectOnchang(this)" id="product">
|
||||
<option value="">请选择</option>
|
||||
<option value="sdkapi">SDK api</option>
|
||||
<option value="CG">CG api</option>
|
||||
</select>
|
||||
</div>
|
||||
<label class="control-label col-sm-1" for="module">模块</label>
|
||||
<div class="col-sm-2">
|
||||
<input type="text" class="form-control" id="module" name="module">
|
||||
</div>
|
||||
<div class="col-sm-2" style="text-align:left;">
|
||||
<button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary" onclick="searchTestCase()">查询</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toolbar" class="btn-group">
|
||||
<button id="btn_add" type="button" class="btn btn-default" onclick="window.location.href=('/add_test_api_new')">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
|
||||
</button>
|
||||
</div>
|
||||
<table id="tb_test_api" table-layout="fixed"></table>
|
||||
</div>
|
||||
<!-- 模拟窗口 开始 -->
|
||||
<div class="modal fade" id="testModal" >
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
|
||||
×
|
||||
</button>
|
||||
<h4 class="modal-title">
|
||||
请选择执行接口地址
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="urlId">
|
||||
<div class="form-group">
|
||||
<label for="apiUrl" class="col-sm-2 control-label"> 接口地址</label>
|
||||
<div class="col-sm-10">
|
||||
<select class="form-control" id="apiUrl" name="apiUrl">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h4></h4>
|
||||
<div class="modal-footer">
|
||||
<button data-dismiss="modal" class="btn btn-default" type="button">
|
||||
关闭
|
||||
</button>
|
||||
<button data-dismiss="modal" class="btn btn-default" type="button" onclick="runTest();">
|
||||
提交
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -35,7 +35,7 @@
|
|||
<li><a href="/testhubs">节点管理</a></li>
|
||||
<li><a href="/testkeywords">步骤说明</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</li><li><a href="/test_api_new">新接口管理</a></li>
|
||||
<li><a href="/unittest">单元测试</a></li>
|
||||
|
||||
<li class="dropdown">
|
||||
|
|
|
@ -0,0 +1,830 @@
|
|||
from flask import Blueprint,render_template, jsonify, request,redirect
|
||||
from app import log
|
||||
from app.view import viewutil,user
|
||||
from app.api_new import api_manage
|
||||
from app.db import test_api_new_manange
|
||||
|
||||
mod = Blueprint('apinew', __name__,
|
||||
template_folder='templates')
|
||||
|
||||
|
||||
#########################api自动化功能开发开始###############################################
|
||||
#api功能主页
|
||||
@mod.route('/test_api_new')
|
||||
@user.authorize
|
||||
def test_api():
|
||||
return render_template("apinew/test_api_new.html")
|
||||
|
||||
#api查询
|
||||
@mod.route('/test_api_new.json', methods=['POST', 'GET'])
|
||||
@user.authorize
|
||||
def search_test_api():
|
||||
if request.method == 'POST':
|
||||
log.log().logger.info('post')
|
||||
if request.method == 'GET':
|
||||
info = request.values
|
||||
log.log().logger.info('info : %s' %info)
|
||||
limit = info.get('limit', 10) # 每页显示的条数
|
||||
offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点
|
||||
log.log().logger.info('get %s' %limit)
|
||||
log.log().logger.info('get offset %s' %offset)
|
||||
|
||||
type = viewutil.getInfoAttribute(info, 'type')
|
||||
id = viewutil.getInfoAttribute(info, 'id')
|
||||
name = viewutil.getInfoAttribute(info, 'name')
|
||||
product = viewutil.getInfoAttribute(info, 'product')
|
||||
module = viewutil.getInfoAttribute(info, 'module')
|
||||
conditionList = ['id','name','product','module']
|
||||
valueList = [id,name,product,module]
|
||||
fieldlist = []
|
||||
rows = 1000
|
||||
caseList = test_api_new_manange.test_api_new_manange().show_test_api(conditionList, valueList, fieldlist, rows,type=type)
|
||||
log.log().logger.info(caseList)
|
||||
data = caseList
|
||||
data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]})
|
||||
log.log().logger.info('data1: %s' %data1)
|
||||
return data1, {'Content-Type': 'application/json'}
|
||||
#api新增界面入口与新增成功跳转
|
||||
@mod.route('/add_test_api_new', methods=['GET'])
|
||||
@user.authorize
|
||||
def new_test_api():
|
||||
log.log().logger.info(request)
|
||||
if request.method == 'GET':
|
||||
log.log().logger.info('post')
|
||||
return render_template("apinew/new_test_api.html")
|
||||
|
||||
#api新增界面入口与新增成功跳转
|
||||
@mod.route('/add_test_api_new.json', methods=['POST'])
|
||||
@user.authorize
|
||||
def save_new_test_api():
|
||||
log.log().logger.info(request)
|
||||
if request.method == 'POST':
|
||||
info = request.form
|
||||
log.log().logger.info('info : %s' %info)
|
||||
name = viewutil.getInfoAttribute(info, 'name')
|
||||
description = viewutil.getInfoAttribute(info, 'description')
|
||||
module = viewutil.getInfoAttribute(info, 'module')
|
||||
product = viewutil.getInfoAttribute(info, 'product')
|
||||
url = viewutil.getInfoAttribute(info, 'url')
|
||||
paras = viewutil.getInfoAttribute(info, 'paras')
|
||||
osign_list = viewutil.getInfoAttribute(info, 'osign_list')
|
||||
osign_list=osign_list.replace('[','').replace(']','').replace("'",'').replace(" ",'')
|
||||
result = test_api_new_manange.test_api_new_manange().new_test_api(product,module,name,url,paras,osign_list,description)
|
||||
if result:
|
||||
code = 200
|
||||
message = 'success'
|
||||
else:
|
||||
code = 500
|
||||
message = 'failed'
|
||||
data1 = jsonify({'code': code, 'msg': message})
|
||||
log.log().logger.info('data1: %s' % data1)
|
||||
return data1, {'Content-Type': 'application/json'}
|
||||
|
||||
|
||||
@mod.route('/split_test_api_url.json', methods=['POST', 'GET'])
|
||||
@user.authorize
|
||||
def split_test_api_url():
|
||||
if request.method == 'POST':
|
||||
log.log().logger.info('post')
|
||||
if request.method == 'GET':
|
||||
info = request.values
|
||||
log.log().logger.info('info : %s' % info)
|
||||
|
||||
url = viewutil.getInfoAttribute(info, 'url')
|
||||
api_info = api_manage.api_manage().split_api_info(url)
|
||||
data1 = jsonify(api_info)
|
||||
log.log().logger.info('data1: %s' % data1)
|
||||
return data1, {'Content-Type': 'application/json'}
|
||||
|
||||
#api删除s
|
||||
@mod.route('/delete_test_api_new', methods=['POST', 'GET'])
|
||||
@user.authorize
|
||||
def delete_test_api():
|
||||
log.log().logger.info(request)
|
||||
if request.method == 'GET':
|
||||
log.log().logger.info('post')
|
||||
info = request.values
|
||||
log.log().logger.info('info : %s' %info)
|
||||
id = viewutil.getInfoAttribute(info, 'id')
|
||||
log.log().logger.info('id: %s' %id)
|
||||
return render_template("apinew/test_api_new.html")
|
||||
if request.method == 'POST':
|
||||
info = request.form
|
||||
log.log().logger.info('info : %s' %info)
|
||||
id = viewutil.getInfoAttribute(info, 'id')
|
||||
result = test_api_new_manange.test_api_new_manange().del_test_api(id)
|
||||
if result:
|
||||
code = 200
|
||||
message = 'delete success!'
|
||||
else:
|
||||
code = 500
|
||||
message = 'please try again!'
|
||||
result = jsonify({'code': code, 'msg': message})
|
||||
return result, {'Content-Type': 'application/json'}
|
||||
#api修改页面入口
|
||||
@mod.route('/edit_test_api_new', methods=['POST', 'GET'])
|
||||
@user.authorize
|
||||
def edit_test_api():
|
||||
log.log().logger.info(request)
|
||||
if request.method == 'GET':
|
||||
log.log().logger.info('post')
|
||||
info = request.values
|
||||
log.log().logger.info('info : %s' %info)
|
||||
id = viewutil.getInfoAttribute(info, 'id')
|
||||
log.log().logger.info('id: %s' %id)
|
||||
return render_template("apinew/edit_test_api.html", id=id)
|
||||
|
||||
#api 修改保存
|
||||
@mod.route('/update_test_api_new.json', methods=['POST'])
|
||||
@user.authorize
|
||||
def update_test_api_new():
|
||||
log.log().logger.info(request)
|
||||
if request.method == 'POST':
|
||||
info = request.form
|
||||
log.log().logger.info('info : %s' %info)
|
||||
id = viewutil.getInfoAttribute(info, 'id')
|
||||
name = viewutil.getInfoAttribute(info, 'name')
|
||||
description = viewutil.getInfoAttribute(info, 'description')
|
||||
module = viewutil.getInfoAttribute(info, 'module')
|
||||
product = viewutil.getInfoAttribute(info, 'product')
|
||||
url = viewutil.getInfoAttribute(info, 'url')
|
||||
paras = viewutil.getInfoAttribute(info, 'paras')
|
||||
osign_list = viewutil.getInfoAttribute(info, 'osign_list')
|
||||
result = test_api_new_manange.test_api_new_manange().update_test_api(id,fieldlist=['product','module','name','url','paras','osign_list','description'] ,valueList=[product,module,name,url,paras,osign_list,description])
|
||||
if result:
|
||||
data1 = jsonify({'code':200})
|
||||
else:
|
||||
data1 = jsonify({'code':500})
|
||||
log.log().logger.info('data1: %s' % data1)
|
||||
return data1, {'Content-Type': 'application/json'}
|
||||
|
||||
|
||||
|
||||
# 手工测试某个url 页面
|
||||
@mod.route('/test_api_new_test', methods=['GET'])
|
||||
@user.authorize
|
||||
def test_api_single_test_page():
|
||||
log.log().logger.info(request)
|
||||
if request.method == 'GET':
|
||||
log.log().logger.info(request.values)
|
||||
info = request.values
|
||||
id = viewutil.getInfoAttribute(info, 'id')
|
||||
return render_template('apinew/test_api_case_new_run.html',id=id)
|
||||
|
||||
# 手工测试某个url
|
||||
@mod.route('/test_api_new_run.json', methods=['POST'])
|
||||
@user.authorize
|
||||
def test_api_single_test():
|
||||
log.log().logger.info(request)
|
||||
if request.method == 'POST':
|
||||
log.log().logger.info(request.values)
|
||||
info = request.values
|
||||
url = viewutil.getInfoAttribute(info, 'url')
|
||||
import json
|
||||
from app.api_new import api_manage
|
||||
response, content = api_manage.api_manage().sendRequest(url)
|
||||
log.log().logger.info(response)
|
||||
log.log().logger.info(content)
|
||||
result = jsonify({'code': 200, 'rows': [{'response': str(response), 'content': content}]})
|
||||
return result
|
||||
|
||||
|
||||
#重算签名
|
||||
@mod.route('/test_api_reosign_new.json', methods=['POST', 'GET'])
|
||||
@user.authorize
|
||||
def test_api_reosign():
|
||||
log.log().logger.info(request)
|
||||
if request.method == 'POST':
|
||||
log.log().logger.info('post')
|
||||
result = jsonify({'code': 500, 'msg': 'should be get!'})
|
||||
return result
|
||||
else:
|
||||
log.log().logger.info(request.values)
|
||||
info = request.values
|
||||
osign_list = viewutil.getInfoAttribute(info, 'osign_list').split(',')
|
||||
context=viewutil.getInfoAttribute(info, 'context')
|
||||
import json
|
||||
context = json.loads(context)
|
||||
# print(type(context))
|
||||
# print(context['appId'])
|
||||
# print(osign,context)
|
||||
log.log().logger.info('context is : %s' %context)
|
||||
print(len(osign_list),osign_list,'osign info')
|
||||
if len(osign_list)>1:
|
||||
log.log().logger.info('osign is not empty!')
|
||||
from app.api_new import api_manage
|
||||
appKey='abc'
|
||||
context= api_manage.api_manage().api_osign(osign_list=osign_list,para_info=context,appkey=appKey)
|
||||
log.log().logger.info(context['osign'])
|
||||
result = jsonify({'code': 200, 'rows': [{'context': str(context)}]})
|
||||
else:
|
||||
log.log().logger.info('osign list is empty!')
|
||||
result = jsonify({'code': 200, 'rows': [{'context': str(context)}]})
|
||||
return result
|
||||
|
||||
|
||||
|
||||
#api查询url
|
||||
@mod.route('/test_api_host.json', methods=['GET'])
|
||||
@user.authorize
|
||||
def search_test_api_host_manage():
|
||||
if request.method == 'GET':
|
||||
info = request.values
|
||||
log.log().logger.info('info : %s' %info)
|
||||
type = viewutil.getInfoAttribute(info, 'type')
|
||||
from app.api_new import paras
|
||||
if type == 'CG':
|
||||
hostList = paras.paraValues().CGHosts
|
||||
else:
|
||||
hostList = paras.paraValues().sdkHosts
|
||||
data1 = jsonify({'total': len(hostList), 'rows': hostList})
|
||||
log.log().logger.info('data1: %s' %data1)
|
||||
return data1, {'Content-Type': 'application/json'}
|
||||
|
||||
|
||||
# #########################api suit自动化功能开发开始###############################################
|
||||
# #api功能主页
|
||||
# @mod.route('/test_api_new_suit')
|
||||
# @user.authorize
|
||||
# def test_api_suit():
|
||||
# return render_template("apinew/test_api_new_suit.html")
|
||||
# #api查询
|
||||
# @mod.route('/test_api_new_suit.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def search_test_api_suit():
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# if request.method == 'GET':
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# limit = info.get('limit', 10) # 每页显示的条数
|
||||
# offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点
|
||||
# log.log().logger.info('get %s' %limit)
|
||||
# log.log().logger.info('get offset %s' %offset)
|
||||
#
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# name = viewutil.getInfoAttribute(info, 'name')
|
||||
# conditionList = ['id','name']
|
||||
# valueList = [id,name]
|
||||
# fieldlist = []
|
||||
# rows = 1000
|
||||
# caseList = test_api_suit_manage.test_api_suit_manage().show_test_api_suit(conditionList, valueList, fieldlist, rows)
|
||||
# log.log().logger.info(caseList)
|
||||
# data = caseList
|
||||
# data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]})
|
||||
# log.log().logger.info('data1: %s' %data1)
|
||||
# return data1, {'Content-Type': 'application/json'}
|
||||
# #api新增界面入口与新增成功跳转
|
||||
# @mod.route('/add_test_api_suit', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def save_new_test_api_suit():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'GET':
|
||||
# log.log().logger.info('post')
|
||||
# return render_template("apinew/new_test_api_suit.html")
|
||||
# if request.method == 'POST':
|
||||
# info = request.form
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# name = viewutil.getInfoAttribute(info, 'name')
|
||||
# description = viewutil.getInfoAttribute(info, 'description')
|
||||
# apiUrl = viewutil.getInfoAttribute(info, 'apiUrl')
|
||||
# if name == '':
|
||||
# return '必填字段不得为空!'
|
||||
# else:
|
||||
# test_api_suit_manage.test_api_suit_manage().new_test_api_suit(name, description, '', apiUrl)
|
||||
# return render_template("apinew/test_api_new_suit.html")
|
||||
# #api删除
|
||||
# @mod.route('/delete_test_api_suit', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def delete_test_api_suit():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'GET':
|
||||
# log.log().logger.info('post')
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# log.log().logger.info('id: %s' %id)
|
||||
# return render_template("apinew/test_api_new_suit.html")
|
||||
# if request.method == 'POST':
|
||||
# info = request.form
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# act = viewutil.getInfoAttribute(info, 'act')
|
||||
# if act == 'del':
|
||||
# test_api_suit_manage.test_api_suit_manage().del_test_api_suit(id)
|
||||
# code = 200
|
||||
# message = 'delete success!'
|
||||
# else:
|
||||
# code = 500
|
||||
# message = 'act is not del!'
|
||||
# result = jsonify({'code': code, 'msg': message})
|
||||
# return result, {'Content-Type': 'application/json'}
|
||||
# #api修改
|
||||
# @mod.route('/edit_test_api_suit', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def edit_test_api_suit():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'GET':
|
||||
# log.log().logger.info('post')
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# log.log().logger.info('id: %s' %id)
|
||||
# return render_template("apinew/edit_test_api_suit.html", id=id)
|
||||
# if request.method == 'POST':
|
||||
# info = request.form
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# name = viewutil.getInfoAttribute(info, 'name')
|
||||
# description = viewutil.getInfoAttribute(info, 'description')
|
||||
# if name == '':
|
||||
# return '必填字段不得为空!'
|
||||
# else:
|
||||
# test_api_suit_manage.test_api_suit_manage().update_test_api_suit(id, ['name', 'description'], [name, description])
|
||||
# return render_template("apinew/test_api_new_suit.html", id=id)
|
||||
# #复制
|
||||
# @mod.route('/copy_test_api_suite', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def copy_test_api_suite():
|
||||
# log.log().logger.info(request)
|
||||
# log.log().logger.info(request.method)
|
||||
# # log.log().logger.info(request.value)
|
||||
# if request.method == 'GET':
|
||||
# log.log().logger.info('post')
|
||||
# result = jsonify({'code': 500, 'msg': 'should be get!'})
|
||||
# return result
|
||||
# if request.method == 'POST':
|
||||
# info = request.form
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# log.log().logger.info('id: %s' %id)
|
||||
# if id == '':
|
||||
# result = jsonify({'code': 500, 'msg': 'test suite is not found!'})
|
||||
# else:
|
||||
# import random, time
|
||||
# #随机获取batchId
|
||||
# batchId = str(random.randint(10000, 99999)) + str(time.time())
|
||||
# #根据ID复制一条记录
|
||||
# test_api_suit_manage.test_api_suit_manage().copy_test_api_suite(id, batchId)
|
||||
# #根据batchId,返回记录Id
|
||||
# newId = test_api_suit_manage.test_api_suit_manage().show_test_api_suit(["batchId"], [batchId], ['id'], 1)
|
||||
# log.log().logger.info('newid %s' %newId)
|
||||
# if len(newId):
|
||||
# ext = newId[0]['id']
|
||||
# log.log().logger.info('ext: %s, id :%s'%(ext, id))
|
||||
# if ext != '0':
|
||||
# #根据Id,复制批次并插入批次
|
||||
# test_api_suit_manage.test_api_suit_manage().copy_test_api_batch(ext, id, batchId)
|
||||
# message = 'success!'
|
||||
# code = 200
|
||||
# result = jsonify({'code': 200, 'msg': 'copy success!'})
|
||||
# else:
|
||||
# result = jsonify({'code': 500, 'msg': 'test suite is not found!'})
|
||||
# return result
|
||||
# #关联测试主页
|
||||
# @mod.route('/attach_test_api_batch', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def attach_test_api_batch():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'GET':
|
||||
# log.log().logger.info('post')
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# id = viewutil.getInfoAttribute(info, 'test_suite_id')
|
||||
# log.log().logger.info('id: %s' %id)
|
||||
# return render_template("apinew/attach_test_api_batch.html", id=id)
|
||||
# else:
|
||||
# return render_template("apinew/test_api_new_suite.html")
|
||||
#
|
||||
# # 未关联api
|
||||
# @mod.route('/test_api_new_no_suit.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def test_api_no_suit():
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# if request.method == 'GET':
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# limit = info.get('limit', 10) # 每页显示的条数
|
||||
# offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点
|
||||
# log.log().logger.info('get %s' %limit)
|
||||
# log.log().logger.info('get offset %s' %offset)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# suite_id = viewutil.getInfoAttribute(info, 'suite_id')
|
||||
# name = viewutil.getInfoAttribute(info, 'name')
|
||||
# module = viewutil.getInfoAttribute(info, 'module')
|
||||
# conditionList = ['id', 'name','module']
|
||||
# valueList = [id, name,module]
|
||||
# fieldlist = []
|
||||
# rows = 1000
|
||||
# caseList = test_api_suit_manage.test_api_suit_manage().show_test_api_no_suit(conditionList, valueList, fieldlist, rows, suite_id)
|
||||
# log.log().logger.info(caseList)
|
||||
# data = caseList
|
||||
# data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]})
|
||||
# log.log().logger.info('data1: %s' %data1)
|
||||
# return data1, {'Content-Type': 'application/json'}
|
||||
# #新增关联测试
|
||||
# @mod.route('/attach_test_api_batch.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def attach_test_api_batch_to_suite():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# result = jsonify({'code': 500, 'msg': 'post'})
|
||||
# return result
|
||||
# else:
|
||||
# log.log().logger.info(request.values)
|
||||
# # log.log().logger.info(request.form)
|
||||
# info = request.values
|
||||
# test_suite_id = viewutil.getInfoAttribute(info, 'test_suite_id')
|
||||
# moduleVal = viewutil.getInfoAttribute(info, 'moduleVal')
|
||||
# rows = viewutil.getInfoAttribute(info, 'datarow')
|
||||
# log.log().logger.info('test suite id: %s, rows: %s' %(test_suite_id, rows))
|
||||
# rows = rows.split(',')
|
||||
# log.log().logger.info(rows)
|
||||
# idrows = []
|
||||
# for i in range(1, len(rows)):
|
||||
# idrows.append(rows[i])
|
||||
# log.log().logger.info(idrows)
|
||||
# result0 = test_api_suit_manage.test_api_suit_manage().new_test_api_batch_suit(test_suite_id, idrows, moduleVal)
|
||||
# if result0 == 0:
|
||||
# result = jsonify({'code': 500, 'msg': 'error, please check selected test cases!'})
|
||||
# else:
|
||||
# result = jsonify({'code': 200, 'msg': 'message'})
|
||||
# return result
|
||||
# #已关联api主页
|
||||
# @mod.route('/test_api_new_batch_url', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def test_api_batch_url():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'GET':
|
||||
# import pyecharts
|
||||
# REMOTE_HOST = "https://pyecharts.github.io/assets/js"
|
||||
# bar = pyecharts.Pie()
|
||||
# bar.width = 700
|
||||
# bar.height = 400
|
||||
# log.log().logger.info('post')
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'test_suite_id')
|
||||
# log.log().logger.info('batch_id: %s' %batch_id)
|
||||
# resultWait=0
|
||||
# resultNoPass=0
|
||||
# resultPass=0
|
||||
# resultPending =0
|
||||
# result = test_api_suit_manage.test_api_suit_manage().show_batch_cases_result_group(batch_id=batch_id)
|
||||
# log.log().logger.info('result is : %s' %result)
|
||||
# for i in range(len(result)):
|
||||
# if result[i]['result']==0:
|
||||
# resultWait = int(result[i]['count'])
|
||||
# elif result[i]['result']==1:
|
||||
# resultPass = int(result[i]['count'])
|
||||
# elif result[i]['result']==2:
|
||||
# resultNoPass = int(result[i]['count'])
|
||||
# elif result[i]['result']==3:
|
||||
# resultPending = int(result[i]['count'])
|
||||
# log.log().logger.info('%s, %s, %s, %s' %(resultWait,resultNoPass,resultPass,resultPending))
|
||||
# resultSum = resultWait+resultNoPass+resultPass+resultPending
|
||||
# if resultSum!=0:
|
||||
# passRate=str(round(resultPass/resultSum*100,2))+'%'
|
||||
# else:
|
||||
# passRate=0
|
||||
# log.log().logger.info('passRate : %s' %passRate)
|
||||
# bar.add("results", ['失败','待执行','执行完成','成功'], [resultNoPass,resultWait,resultPending,resultPass],
|
||||
# is_more_utils=True,is_area_show=True,is_label_show=True,legend_pos="50%")
|
||||
# return render_template("apinew/test_api_new_batch_url.html", batch_id=batch_id,resultPass=resultPass,resultNoPass=resultNoPass,resultPending=resultPending,resultWait=resultWait,resultSum=resultSum,passRate=passRate,myechart=bar.render_embed(),host=REMOTE_HOST,script_list=bar.get_js_dependencies())
|
||||
# else:
|
||||
# return render_template("apinew/test_api_new_suite.html")
|
||||
#
|
||||
# #查看本批次执行全部用例
|
||||
# @mod.route('/test_api_new_batch_all', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def test_api_batch_all():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'GET':
|
||||
# import pyecharts
|
||||
# REMOTE_HOST = "https://pyecharts.github.io/assets/js"
|
||||
# bar = pyecharts.Pie()
|
||||
# bar.width = 700
|
||||
# bar.height = 400
|
||||
# log.log().logger.info('post')
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'test_suite_id')
|
||||
# log.log().logger.info('batch_id: %s' %batch_id)
|
||||
# resultWait=0
|
||||
# resultNoPass=0
|
||||
# resultPass=0
|
||||
# resultPending =0
|
||||
# result = test_api_suit_manage.test_api_suit_manage().show_batch_cases_result_group(batch_id=batch_id)
|
||||
# log.log().logger.info('result is :', result)
|
||||
# for i in range(len(result)):
|
||||
# if result[i]['result']==0:
|
||||
# resultWait = int(result[i]['count'])
|
||||
# elif result[i]['result']==1:
|
||||
# resultPass = int(result[i]['count'])
|
||||
# elif result[i]['result']==2:
|
||||
# resultNoPass = int(result[i]['count'])
|
||||
# elif result[i]['result']==3:
|
||||
# resultPending = int(result[i]['count'])
|
||||
# log.log().logger.info('%s, %s, %s, %s' %(resultWait,resultNoPass,resultPass,resultPending))
|
||||
# resultSum = resultWait+resultNoPass+resultPass+resultPending
|
||||
# if resultSum!=0:
|
||||
# passRate=str(round(resultPass/resultSum*100,2))+'%'
|
||||
# else:
|
||||
# passRate=0
|
||||
# log.log().logger.info('passRate : %s' %passRate)
|
||||
# bar.add("results", ['失败','待执行','执行完成','成功'], [resultNoPass,resultWait,resultPending,resultPass],
|
||||
# is_more_utils=True,is_area_show=True,is_label_show=True,legend_pos="50%")
|
||||
# return render_template("apinew/test_api_new_batch_all.html", batch_id=batch_id,resultPass=resultPass,resultNoPass=resultNoPass,resultPending=resultPending,resultWait=resultWait,resultSum=resultSum,passRate=passRate,myechart=bar.render_embed(),host=REMOTE_HOST,script_list=bar.get_js_dependencies())
|
||||
# else:
|
||||
# return render_template("apinew/test_api_new_suite.html")
|
||||
#
|
||||
# # 查询执行全部用例
|
||||
# @mod.route('/test_api_new_batch_al.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def search_api_batch_all():
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# if request.method == 'GET':
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# limit = info.get('limit', 10) # 每页显示的条数
|
||||
# offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点
|
||||
# log.log().logger.info('get %s' %limit)
|
||||
# log.log().logger.info('get offset %s' %offset)
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'batch_id')
|
||||
# result = viewutil.getInfoAttribute(info, 'result')
|
||||
# type = viewutil.getInfoAttribute(info, 'type')
|
||||
#
|
||||
# conditionList = ['batch_id','result','type']
|
||||
# valueList = [batch_id,result,type]
|
||||
# fieldlist = []
|
||||
# rows = 1000
|
||||
# caseList = test_api_suit_manage.test_api_suit_manage().show_api_runhistory_all(conditionList, valueList, fieldlist, rows)
|
||||
# log.log().logger.info(caseList)
|
||||
# data = caseList
|
||||
# data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]})
|
||||
# log.log().logger.info('data1: %s' %data1)
|
||||
# return data1, {'Content-Type': 'application/json'}
|
||||
#
|
||||
# # 查询已关联url
|
||||
# @mod.route('/test_api_new_has_suit.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def test_api_has_suit():
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# if request.method == 'GET':
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# limit = info.get('limit', 10) # 每页显示的条数
|
||||
# offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点
|
||||
# log.log().logger.info('get limit %s' %limit)
|
||||
# log.log().logger.info('get offset %s' %offset)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'batch_id')
|
||||
# name = viewutil.getInfoAttribute(info, 'name')
|
||||
# log.log().logger.info('name %s' %name)
|
||||
# conditionList = ['id', 'name']
|
||||
# valueList = [id, name]
|
||||
# fieldlist = []
|
||||
# rows = 1000
|
||||
# caseList = test_api_suit_manage.test_api_suit_manage().show_test_api_has_suit(conditionList, valueList, fieldlist, rows, batch_id)
|
||||
# log.log().logger.info(caseList)
|
||||
# data = caseList
|
||||
# data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]})
|
||||
# log.log().logger.info('data1: %s' %data1)
|
||||
# return data1, {'Content-Type': 'application/json'}
|
||||
#
|
||||
# #查看执行结果主页
|
||||
# @mod.route('/test_api_new_runhistory', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def test_api_runhistory():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'GET':
|
||||
# log.log().logger.info('post')
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# url_id = viewutil.getInfoAttribute(info, 'url_id')
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'batch_id')
|
||||
# source = viewutil.getInfoAttribute(info, 'source')
|
||||
# if source =='':
|
||||
# source = 'batch'
|
||||
# import pyecharts
|
||||
# REMOTE_HOST = "https://pyecharts.github.io/assets/js"
|
||||
# bar = pyecharts.Pie()
|
||||
# bar.width = 700
|
||||
# bar.height = 400
|
||||
# log.log().logger.info('url_id : %s' %url_id)
|
||||
# log.log().logger.info('batch_id : %s' %batch_id)
|
||||
# conditionList = ['batch_id', 'url_id']
|
||||
# valueList = [batch_id, url_id]
|
||||
# fieldlist = []
|
||||
# caseList = test_api_suit_manage.test_api_suit_manage().show_batch_url(conditionList, valueList, fieldlist)
|
||||
# batch_url_id=caseList[0]["batch_url_id"]
|
||||
# log.log().logger.info('batch_url_id : %s' %batch_url_id)
|
||||
# # #通过率
|
||||
# resultWait=0
|
||||
# resultNoPass=0
|
||||
# resultPass=0
|
||||
# resultPending =0
|
||||
# result = test_api_suit_manage.test_api_suit_manage().show_batch_cases_result_group(batch_url_id=batch_url_id)
|
||||
# log.log().logger.info('result is : %s' %result)
|
||||
# for i in range(len(result)):
|
||||
# if result[i]['result']==0:
|
||||
# resultWait = int(result[i]['count'])
|
||||
# elif result[i]['result']==1:
|
||||
# resultPass = int(result[i]['count'])
|
||||
# elif result[i]['result']==2:
|
||||
# resultNoPass = int(result[i]['count'])
|
||||
# elif result[i]['result']==3:
|
||||
# resultPending = int(result[i]['count'])
|
||||
# log.log().logger.info('%s, %s ,%s ,%s ' %(resultWait,resultNoPass,resultPass,resultPending))
|
||||
# resultSum = resultWait+resultNoPass+resultPass+resultPending
|
||||
# if resultSum!=0:
|
||||
# passRate=str(round(resultPass/resultSum*100,2))+'%'
|
||||
# else:
|
||||
# passRate=0
|
||||
# log.log().logger.info('passRate : %s' %passRate)
|
||||
# bar.add("results", ['失败', '待执行', '执行完成', '成功'], [resultNoPass, resultWait, resultPending, resultPass],
|
||||
# is_more_utils=True, is_area_show=True, is_label_show=True, legend_pos="50%")
|
||||
# return render_template("apinew/test_api_new_runhistory.html", source = source, batch_id=batch_id,url_id=url_id,batch_url_id=batch_url_id,resultPass=resultPass,resultNoPass=resultNoPass,resultPending=resultPending,resultWait=resultWait,resultSum=resultSum,passRate=passRate,myechart=bar.render_embed(),host=REMOTE_HOST,script_list=bar.get_js_dependencies())
|
||||
# else:
|
||||
# return render_template("apinew/test_api_new_suite.html")
|
||||
# #执行结果
|
||||
# @mod.route('/test_api_new_runhistory.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def search_test_api_runhistory():
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# if request.method == 'GET':
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# limit = info.get('limit', 10) # 每页显示的条数
|
||||
# offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点
|
||||
# log.log().logger.info('get %s' %limit)
|
||||
# rows = 1000
|
||||
# log.log().logger.info('get offset %s' %offset)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# batch_url_id = viewutil.getInfoAttribute(info, 'batch_url_id')
|
||||
# type = viewutil.getInfoAttribute(info, 'type')
|
||||
# result = viewutil.getInfoAttribute(info, 'result')
|
||||
# conditionList = ['batch_url_id','result','type','id']
|
||||
# valueList = [batch_url_id,result,type,id]
|
||||
# fieldlist = []
|
||||
# caseList = test_api_suit_manage.test_api_suit_manage().show_api_runhistory(conditionList, valueList, fieldlist, rows)
|
||||
# log.log().logger.info('caselist: %s' %caseList)
|
||||
# data = caseList
|
||||
# data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]})
|
||||
# log.log().logger.info('data1: %s' %data1)
|
||||
# return data1, {'Content-Type': 'application/json'}
|
||||
#
|
||||
# #根据batch_url_id 查询结果
|
||||
# @mod.route('/test_api_new_batch_url.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def search_test_api_batch_url():
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# if request.method == 'GET':
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# limit = info.get('limit', 10) # 每页显示的条数
|
||||
# offset = info.get('offset', 0) # 分片数,(页码-1)*limit,它表示一段数据的起点
|
||||
# log.log().logger.info('get limit %s' %limit)
|
||||
# log.log().logger.info('get offset %s' %offset)
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'batch_id')
|
||||
# url_id = viewutil.getInfoAttribute(info, 'url_id')
|
||||
# conditionList = ['batch_id', 'url_id']
|
||||
# valueList = [batch_id, url_id]
|
||||
# fieldlist = []
|
||||
# caseList = test_api_suit_manage.test_api_suit_manage().show_batch_url(conditionList, valueList, fieldlist)
|
||||
# log.log().logger.info('caselist: %s' %caseList)
|
||||
# data = caseList
|
||||
# data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]})
|
||||
# log.log().logger.info('data1: %s' %data1)
|
||||
# return data1, {'Content-Type': 'application/json'}
|
||||
#
|
||||
# #测试用例详情
|
||||
# @mod.route('/test_api_new_batch_case_detail')
|
||||
# @user.authorize
|
||||
# def test_api_batch_case_detail():
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'batch_id')
|
||||
# url_id = viewutil.getInfoAttribute(info, 'url_id')
|
||||
# log.log().logger.info('batch_id : %s' %batch_id)
|
||||
# log.log().logger.info('url_id : %s' %url_id)
|
||||
# return render_template("apinew/test_api_new_batch_case_detail.html",id=id,batch_id=batch_id,url_id=url_id)
|
||||
#
|
||||
# #测试用例详情
|
||||
# @mod.route('/test_api_new_case_run')
|
||||
# @user.authorize
|
||||
# def test_api_case_run():
|
||||
# info = request.values
|
||||
# log.log().logger.info('info : %s' %info)
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'batch_id')
|
||||
# url_id = viewutil.getInfoAttribute(info, 'url_id')
|
||||
# log.log().logger.info('batch_id : %s' %batch_id)
|
||||
# log.log().logger.info('url_id : %s' %url_id)
|
||||
# return render_template("apinew/test_api_new_case_run.html",id=id,batch_id=batch_id,url_id=url_id)
|
||||
#
|
||||
# #直接测试某个url
|
||||
# @mod.route('/runurltest.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def runurltest():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# result = jsonify({'code': 500, 'msg': 'should be get!'})
|
||||
# return result
|
||||
# else:
|
||||
# log.log().logger.info(request.values)
|
||||
# info = request.values
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# apiUrl=viewutil.getInfoAttribute(info, 'apiUrl')
|
||||
# from app.apinew import run_case
|
||||
# test_case_id,run_result = run_case.test_url_from_admin(id, apiUrl)
|
||||
# if run_result=='1':
|
||||
# result = jsonify({'code': 200,'test_case_id':test_case_id, 'msg': 'success!'})
|
||||
# else:
|
||||
# result = jsonify({'code': 500, 'msg': 'type is not defined!'})
|
||||
# return result
|
||||
#
|
||||
#
|
||||
# #手工测试某个url
|
||||
# @mod.route('/test_api_new_single_test1.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def test_api_single_test1():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# result = jsonify({'code': 500, 'msg': 'should be get!'})
|
||||
# return result
|
||||
# else:
|
||||
# log.log().logger.info(request.values)
|
||||
# info = request.values
|
||||
# url = viewutil.getInfoAttribute(info, 'url')
|
||||
# from app.apinew import util
|
||||
# response, content = util.util().send(url)
|
||||
# log.log().logger.info(response)
|
||||
# log.log().logger.info(content)
|
||||
# result = jsonify({'code': 200, 'rows':[{'response':str(response), 'content': content}]})
|
||||
# return result
|
||||
|
||||
#
|
||||
# @mod.route('/runapinew.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def runapinew():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# result = jsonify({'code': 500, 'msg': 'should be get!'})
|
||||
# return result
|
||||
# else:
|
||||
# log.log().logger.info(request.values)
|
||||
# # log.log().logger.info(request.form)
|
||||
# info = request.values
|
||||
# id = viewutil.getInfoAttribute(info, 'id')
|
||||
# type = viewutil.getInfoAttribute(info, 'type')
|
||||
# runtype = viewutil.getInfoAttribute(info, 'runtype')
|
||||
# if runtype == 'part':
|
||||
# runtype = '1'
|
||||
# else:
|
||||
# runtype = '0'
|
||||
# if type == 'test_batch':
|
||||
# test_api_suit_manage.test_api_suit_manage().update_api_test_batch_url([], id, runtype)
|
||||
# result = jsonify({'code': 200, 'msg': 'success!'})
|
||||
# elif type == 'test_case':
|
||||
# # test_api_suit_manage.test_api_suit_manage().update_api_test_batch_url([],id,runtype)
|
||||
# from app.apinew import run_case
|
||||
# run_case.run_single_test(id)
|
||||
# result = jsonify({'code': 200, 'msg': 'success!'})
|
||||
# else:
|
||||
# result = jsonify({'code': 500, 'msg': 'type is not defined!'})
|
||||
# return result
|
||||
#
|
||||
#
|
||||
#
|
||||
# #刷新前置数据
|
||||
# @mod.route('/test_api_new_refresh_prepose.json', methods=['POST', 'GET'])
|
||||
# @user.authorize
|
||||
# def test_api_refresh_prepose():
|
||||
# log.log().logger.info(request)
|
||||
# if request.method == 'POST':
|
||||
# log.log().logger.info('post')
|
||||
# result = jsonify({'code': 500, 'msg': 'should be get!'})
|
||||
# return result
|
||||
# else:
|
||||
# log.log().logger.info(request.values)
|
||||
# info = request.values
|
||||
# url_id = viewutil.getInfoAttribute(info, 'url_id')
|
||||
# batch_id = viewutil.getInfoAttribute(info, 'batch_id')
|
||||
# apiUrl=viewutil.getInfoAttribute(info, 'url')
|
||||
# # id = viewutil.getInfoAttribute(info, 'id')
|
||||
# from app.apinew import run_case
|
||||
# api_prepose.update_prepose(batch_id=batch_id, current_id=url_id, url=apiUrl)
|
||||
# run_case.test_url_from_admin(url_id, apiUrl)
|
||||
# result = jsonify({'code': 200})
|
||||
# return result
|
24
init.sql
24
init.sql
|
@ -195,3 +195,27 @@ insert into `test_keyword` ( `keyword`, `paraCount`, `template`, `elementTemplat
|
|||
insert into `test_keyword` ( `keyword`, `paraCount`, `template`, `elementTemplate`, `example`, `description`, `status`) values('公共方法','1',' $para1',NULL,'公共方法|游客登录','调用公共方法','1');
|
||||
insert into `test_keyword` ( `keyword`, `paraCount`, `template`, `elementTemplate`, `example`, `description`, `status`) values('填写文件','3','extend.extend().fill_file(driver,[\"$para1\",\"$para2\"],\"$para3\")','driver.element_by_$para1(\"$para2\")','填写文件|id@@input_box@@ghw','在指定元素中输入文件路径,可按 id、css、xpath、class、name、text 等方式定位元素','1');
|
||||
insert into `test_keyword` ( `keyword`, `paraCount`, `template`, `elementTemplate`, `example`, `description`, `status`) values('复制','4','extend.extend().copy_from_another_element(driver,[\"$para1\",\"$para2\"],[\"$para3\",\"$para4\"])','driver.element_by_$para1(\"$para2\")','复制|id@@kw@@id@@su','将后一个元素的内容复制填入到前一个元素中','1');
|
||||
|
||||
|
||||
|
||||
/*Table structure for table `api_new` */
|
||||
|
||||
DROP TABLE IF EXISTS `api_new`;
|
||||
|
||||
CREATE TABLE `api_new` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`product` char(20) NOT NULL DEFAULT 'SDK' COMMENT 'SDK/CG',
|
||||
`module` char(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`name` char(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`url` char(50) NOT NULL,
|
||||
`paras` text NOT NULL,
|
||||
`osign_list` char(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`description` char(50) DEFAULT NULL,
|
||||
`status` tinyint(1) DEFAULT '1' COMMENT '1:正常, 0:已删除',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
|
Loading…
Reference in New Issue