增加对dubbo接口的支持
This commit is contained in:
26
Interface/dubbo_feng.py
Normal file
26
Interface/dubbo_feng.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
@author: lileilei
|
||||
@file: dubbo_feng.py
|
||||
@time: 2018/3/29 12:26
|
||||
"""
|
||||
from pyhessian.client import HessianProxy
|
||||
from pyhessian import protocol
|
||||
from Public.log import LOG,logger
|
||||
@logger('dubbo接口')
|
||||
class DubboInterface:
|
||||
def __init__(self,url,interface,method,param,**kwargs):
|
||||
self.url=url
|
||||
self.interface=interface
|
||||
self.method=method
|
||||
self.param=param
|
||||
self.interfaceparam=protocol.object_factory(self.param,**kwargs)
|
||||
def getresult(self):
|
||||
try:
|
||||
result=HessianProxy(self.url+self.interface)
|
||||
return_result=getattr(result,self.method)(self.interfaceparam)
|
||||
LOG.info('测试返回结果:%s'%return_result)
|
||||
res={'code':0,'result':return_result}
|
||||
except Exception as e:
|
||||
LOG.info('测试失败,原因:%s'%e)
|
||||
res={'code':1,'result':e}
|
||||
return res
|
||||
@@ -14,11 +14,11 @@ class TestApi(object):
|
||||
def testapi(self):
|
||||
if self.fangshi=='POST':
|
||||
self.parem = {'key': self.key, 'info': self.connent}
|
||||
response=reques.post(self.url,self.parem)
|
||||
self.response=reques.post(self.url,self.parem)
|
||||
elif self.fangshi=="GET":
|
||||
self.parem = {'key': self.key, 'info': self.connent}
|
||||
response = reques.get(url=self.url,params=self.parem)
|
||||
return response
|
||||
self.response = reques.get(url=self.url,params=self.parem)
|
||||
return self.response
|
||||
def getJson(self):
|
||||
json_data = self.testapi()
|
||||
return json_data
|
||||
@@ -6,10 +6,9 @@
|
||||
import xlrd
|
||||
from Public.log import LOG,logger
|
||||
@logger('解析测试用例文件')
|
||||
def datacel():
|
||||
def datacel(filrpath):
|
||||
try:
|
||||
filepath='.\\test_case\\case.xlsx'
|
||||
file=xlrd.open_workbook(filepath)
|
||||
file=xlrd.open_workbook(filrpath)
|
||||
me=file.sheets()[0]
|
||||
nrows=me.nrows
|
||||
listid=[]
|
||||
@@ -32,7 +31,9 @@ def datacel():
|
||||
except:LOG.info('打开测试用例失败,原因是:%s'%Exception)
|
||||
@logger('生成数据驱动所用数据')
|
||||
def makedata():
|
||||
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname=datacel()
|
||||
import os
|
||||
path = os.getcwd() + '\\test_case\\case.xlsx'
|
||||
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname=datacel(path)
|
||||
make_data=[]
|
||||
for i in range(len(listid)):
|
||||
make_data.append({'url':listurl[i],'key':listkey[i],'coneent':listconeent[i],'fangshi':listfangshi[i],'qiwang':listqiwang[i]})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# 接口测试框架(基于json格式、http请求,python3,不兼容python2.x版本)
|
||||
# 支持对dubbo接口测试的相关内容,暂时存放在dubbo分支。
|
||||
## 注:现在基于Excel文件管理测试用例基本实现,)
|
||||
# 2018-3-13版本修改
|
||||
### 原来的测试报告更加详细的展示错误类型,对部分代码进行了优化,断言结果返回更加详细,更快的定位测试问题
|
||||
|
||||
56
log/jiekou-2018-03-29-13.log
Normal file
56
log/jiekou-2018-03-29-13.log
Normal file
@@ -0,0 +1,56 @@
|
||||
[2018-03-29 13:00:14.587058] INFO: jiekou: 当前模块 解析测试用例文件
|
||||
[2018-03-29 13:00:14.601059] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:00:14.601059] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:00:14.707065] INFO: jiekou: 当前模块 解析测试用例文件
|
||||
[2018-03-29 13:00:14.707065] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:00:14.708065] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:00:14.711065] INFO: jiekou: 当前模块 dubbo接口测试
|
||||
[2018-03-29 13:00:14.711065] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:00:14.712065] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:00:53.118262] INFO: jiekou: 当前模块 解析测试用例文件
|
||||
[2018-03-29 13:00:53.118262] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:00:53.119262] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:00:53.127262] INFO: jiekou: 当前模块 解析测试用例文件
|
||||
[2018-03-29 13:00:53.127262] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:00:53.127262] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:00:53.131263] INFO: jiekou: 当前模块 dubbo接口测试
|
||||
[2018-03-29 13:00:53.131263] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:00:53.131263] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:07:03.557450] INFO: jiekou: 当前模块 requests封装
|
||||
[2018-03-29 13:07:03.558450] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:07:03.558450] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:07:03.575451] INFO: jiekou: 当前模块 解析测试用例文件
|
||||
[2018-03-29 13:07:03.575451] INFO: jiekou: 全部args参数参数信息 , ('C:\\Users\\Administrator\\Desktop\\jiekou-python3\\test_case\\case.xlsx',)
|
||||
[2018-03-29 13:07:03.575451] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:07:03.620453] INFO: jiekou: 当前模块 解析测试用例文件
|
||||
[2018-03-29 13:07:03.621453] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:07:03.621453] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:07:44.560795] INFO: jiekou: 当前模块 requests封装
|
||||
[2018-03-29 13:07:44.560795] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:07:44.561795] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:07:44.571796] INFO: jiekou: 当前模块 解析测试用例文件
|
||||
[2018-03-29 13:07:44.571796] INFO: jiekou: 全部args参数参数信息 , ('C:\\Users\\Administrator\\Desktop\\jiekou-python3\\test_case\\case.xlsx',)
|
||||
[2018-03-29 13:07:44.571796] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:07:44.581796] INFO: jiekou: 当前模块 解析测试用例文件
|
||||
[2018-03-29 13:07:44.582796] INFO: jiekou: 全部args参数参数信息 , ('C:\\Users\\Administrator\\Desktop\\jiekou-python3\\test_case\\case.xlsx',)
|
||||
[2018-03-29 13:07:44.582796] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:07:44.586797] INFO: jiekou: 当前模块 测试
|
||||
[2018-03-29 13:07:44.586797] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:07:44.586797] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
[2018-03-29 13:07:44.663801] INFO: jiekou: inputdata> 参数:{'password':'1222'}, url:http://www.tuling123.com/openapi/api ,返回:{'code': 0, 'result': {'code': 40007, 'text': '您的请求内容为空。'}},预期:code=40001
|
||||
[2018-03-29 13:07:44.663801] INFO: jiekou: 当前模块 断言测试结果
|
||||
[2018-03-29 13:07:44.664801] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:07:44.664801] INFO: jiekou: 全部kwargs参数信息 , {'asserqiwang': 'code=40001', 'fanhuijson': {'code': 0, 'result': {'code': 40007, 'text': '您的请求内容为空。'}}}
|
||||
[2018-03-29 13:07:44.688802] INFO: jiekou: inputdata> 参数:{'password':'1222'}, url:http://www.tuling123.com/openapi/api
|
||||
,返回:{'code': 0, 'result': {'code': 40007, 'text': '您的请求内容为空。'}},预期:code=40002
|
||||
[2018-03-29 13:07:44.688802] INFO: jiekou: 当前模块 断言测试结果
|
||||
[2018-03-29 13:07:44.688802] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:07:44.688802] INFO: jiekou: 全部kwargs参数信息 , {'asserqiwang': 'code=40002', 'fanhuijson': {'code': 0, 'result': {'code': 40007, 'text': '您的请求内容为空。'}}}
|
||||
[2018-03-29 13:07:44.896814] INFO: jiekou: inputdata> 参数:{'password':'1222'}, url:https://api.douban.com/v2/photo/:id ,返回:{'code': 0, 'result': {'msg': 'uri_not_found', 'code': 1001, 'request': 'GET /v2/photo/:id'}},预期:
|
||||
[2018-03-29 13:07:44.896814] INFO: jiekou: 当前模块 断言测试结果
|
||||
[2018-03-29 13:07:44.896814] INFO: jiekou: 全部args参数参数信息 , ()
|
||||
[2018-03-29 13:07:44.897814] INFO: jiekou: 全部kwargs参数信息 , {'asserqiwang': '', 'fanhuijson': {'code': 0, 'result': {'msg': 'uri_not_found', 'code': 1001, 'request': 'GET /v2/photo/:id'}}}
|
||||
[2018-03-29 13:07:44.897814] INFO: jiekou: 填写测试预期值
|
||||
[2018-03-29 13:07:45.329839] INFO: jiekou: 当前模块 保存测试结果
|
||||
[2018-03-29 13:07:45.330839] INFO: jiekou: 全部args参数参数信息 , (datetime.datetime(2018, 3, 29, 13, 7, 44, 581796), 3, 0, 2)
|
||||
[2018-03-29 13:07:45.330839] INFO: jiekou: 全部kwargs参数信息 , {}
|
||||
@@ -11,3 +11,4 @@
|
||||
2018-03-13 13:07:40.708058=3=0=2
|
||||
2018-03-23 15:14:02.485629=3=0=2
|
||||
2018-03-23 15:14:37.729644=3=0=2
|
||||
2018-03-29 13:07:44.581796=3=0=2
|
||||
|
||||
24
run_dubbo_html.py
Normal file
24
run_dubbo_html.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author : leizi
|
||||
import os,datetime,time
|
||||
from testCase.dubbocase import testdubbointerface
|
||||
from Public.py_Html import createHtml
|
||||
from Public.get_excel import datacel
|
||||
from Public.create_report import save_result
|
||||
def stast():
|
||||
starttime=datetime.datetime.now()
|
||||
day= time.strftime("%Y%m%d%H%M", time.localtime(time.time()))
|
||||
basdir=os.path.abspath(os.path.dirname(__file__))
|
||||
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel()
|
||||
listrelust, list_fail, list_pass, list_json,list_exption,list_weizhi = testdubbointerface()
|
||||
filepath =os.path.join(basdir+'\\test_Report\\%s-result.html'%day)
|
||||
if os.path.exists(filepath) is False:
|
||||
os.system(r'touch %s' % filepath)
|
||||
save_result(starttime,len(listrelust),((list_pass)),list_fail)
|
||||
endtime=datetime.datetime.now()
|
||||
createHtml(titles='dubbo接口测试报告',filepath=filepath,starttime=starttime,
|
||||
endtime=endtime,passge=list_pass,fail=list_fail,
|
||||
id=listid,name=listname,key=listkey,coneent=listconeent,url=listurl,meth=listfangshi,
|
||||
yuqi=listqiwang,json=list_json,relusts=listrelust,weizhi=list_weizhi,exceptions=list_exption)
|
||||
if __name__ == '__main__':
|
||||
stast()
|
||||
@@ -5,7 +5,7 @@
|
||||
@time: 2017/6/9 12:45
|
||||
"""
|
||||
from Public.pyreport_excel import create
|
||||
import os,threading,datetime
|
||||
import os,datetime
|
||||
from testCase.case import testinterface
|
||||
from Public.get_excel import datacel
|
||||
from Public.create_report import save_result
|
||||
@@ -13,7 +13,8 @@ def start():
|
||||
starttime=datetime.datetime.now()
|
||||
m=datetime.datetime.now().strftime("%Y%m%d")
|
||||
basdir = os.path.abspath(os.path.dirname(__file__))
|
||||
listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname=datacel()
|
||||
path = os.getcwd() + '\\test_case\\case.xlsx'
|
||||
listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname=datacel(path)
|
||||
listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi =testinterface()
|
||||
filepath = os.path.join(basdir + '\\test_Report\\%s-result.xls'%m)
|
||||
if os.path.exists(filepath) is False:
|
||||
|
||||
@@ -9,7 +9,8 @@ def stast():
|
||||
starttime=datetime.datetime.now()
|
||||
day= time.strftime("%Y%m%d%H%M", time.localtime(time.time()))
|
||||
basdir=os.path.abspath(os.path.dirname(__file__))
|
||||
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel()
|
||||
path = os.getcwd() + '\\test_case\\case.xlsx'
|
||||
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel(path)
|
||||
listrelust, list_fail, list_pass, list_json,list_exption,list_weizhi = testinterface()
|
||||
filepath =os.path.join(basdir+'\\test_Report\\%s-result.html'%day)
|
||||
if os.path.exists(filepath) is False:
|
||||
|
||||
@@ -11,5 +11,5 @@ if __name__=='__main__':
|
||||
file_dir = os.path.join(basedir, 'test_Report')
|
||||
file = os.path.join(file_dir, (now + '.html'))
|
||||
re_open = open(file, 'wb')
|
||||
runner = BSTestRunner.BSTestRunner(stream=re_open, title='接口测试报告', description='测试结果')
|
||||
runner = BSTestRunner.BSTestRunner(stream=re_open, title='http接口测试报告', description='测试结果')
|
||||
m=runner.run(suite)
|
||||
@@ -5,7 +5,9 @@
|
||||
from Interface.testFengzhuang import TestApi
|
||||
from Public.get_excel import datacel
|
||||
from Public.log import LOG,logger
|
||||
listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname=datacel()
|
||||
import os
|
||||
path=os.getcwd()+'\\test_case\\case.xlsx'
|
||||
listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname=datacel(path)
|
||||
from Public.panduan import assert_in
|
||||
@logger('测试')
|
||||
def testinterface():
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
@author: lileilei
|
||||
@file: dubbocase.py
|
||||
@time: 2018/3/29 12:47
|
||||
"""
|
||||
from Interface.testFengzhuang import TestApi
|
||||
from Public.get_excel import makedata
|
||||
from Public.log import LOG
|
||||
|
||||
48
testCase/dubbocase.py
Normal file
48
testCase/dubbocase.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
@author: lileilei
|
||||
@file: dubbocase.py
|
||||
@time: 2018/3/29 12:47
|
||||
"""
|
||||
from Interface.dubbo_feng import DubboInterface
|
||||
from Public.log import LOG,logger
|
||||
from Public.panduan import assert_in
|
||||
from Public.get_excel import datacel
|
||||
import os
|
||||
path=os.getcwd()+'\\test_case\\dubbocase.xlsx'
|
||||
listid,listurl,listinterface,listmeth,listfobject,listparam,listassert=datacel(path)
|
||||
@logger('dubbo接口测试')
|
||||
def testdubbointerface():
|
||||
list_pass = 0
|
||||
list_fail = 0
|
||||
list_json = []
|
||||
listrelust = []
|
||||
list_weizhi = 0
|
||||
list_exption = 0
|
||||
for i in range(len(listid)):
|
||||
dubboapi=DubboInterface(url=listurl,interface=listinterface[i],method=listmeth[i],param=listfobject[i],**(eval(listparam[i])))
|
||||
dubboapireslu=dubboapi.getresult()
|
||||
if dubboapireslu['code'] == 0:
|
||||
LOG.info('inputdata> 参数:%s, url:%s ,返回:%s,预期:%s' % (listparam[i], listurl[i], dubboapireslu, listassert[i]))
|
||||
assert_re = assert_in(asserqiwang=listassert[i], fanhuijson=dubboapireslu)
|
||||
if assert_re['code'] == 0:
|
||||
list_json.append(dubboapireslu['result'])
|
||||
listrelust.append('pass')
|
||||
list_pass += 1
|
||||
elif assert_re['code'] == 1:
|
||||
list_fail += 1
|
||||
listrelust.append('fail')
|
||||
list_json.append(dubboapireslu['result'])
|
||||
elif assert_re['code'] == 2:
|
||||
list_exption += 1
|
||||
listrelust.append('exception')
|
||||
list_json.append(assert_re['result'])
|
||||
else:
|
||||
list_weizhi += 1
|
||||
listrelust.append('未知错误')
|
||||
list_json.append('未知错误')
|
||||
else:
|
||||
list_exption += 1
|
||||
listrelust.append('exception')
|
||||
list_json.append(dubboapireslu['result'])
|
||||
continue
|
||||
return listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
<div style='width: 1170px;margin-left: 15%'>
|
||||
<h1>接口测试的结果</h1>
|
||||
<p><strong>开始时间:</strong> 2018-03-23 15:14:37.729644</p>
|
||||
<p><strong>结束时间:</strong> 2018-03-23 15:14:37.966658</p>
|
||||
<p><strong>耗时:</strong> 0:00:00.237014</p>
|
||||
<p><strong>开始时间:</strong> 2018-03-29 13:07:44.581796</p>
|
||||
<p><strong>结束时间:</strong> 2018-03-29 13:07:45.333839</p>
|
||||
<p><strong>耗时:</strong> 0:00:00.752043</p>
|
||||
<p><strong>结果:</strong>
|
||||
<span >Pass: <strong >0</strong>
|
||||
Fail: <strong >2</strong>
|
||||
BIN
test_case/dubbocase.xlsx
Normal file
BIN
test_case/dubbocase.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user