コード例 #1
0
 def test_api(self,data_test):
     api = TestApi(url=data_test['url'], key=data_test['key'], connent=data_test['coneent'], fangshi=data_test['fangshi'])
     LOG.info('输入参数:url:%s,key:%s,参数:%s,请求方式:%s'%(data_test['url'],data_test['key'],data_test['coneent'],        LOG.info('输入参数:url:%s,key:%s,参数:%s,请求方式:%s'%(data_test['url'],data_test['key'],data_test['coneent'],data_test['fangshi']))))
     apijson = api.getJson()
     LOG.info('返回结果:%s'%apijson)
     qingwang=assertre(asserqingwang=data_test['qiwang'])
     self.assertNotEqual(dict(qingwang),dict(apijson),msg='预期和返回不一致')
コード例 #2
0
def datacel(filrpath):
    try:
        file = xlrd.open_workbook(filrpath)
        me = file.sheets()[0]
        nrows = me.nrows
        list_id = []
        list_dec = []
        list_param = []
        list_url = []
        list_method = []
        list_expect = []
        listrelut = []
        list_name = []

        for i in range(1, nrows):
            list_id.append(me.cell(i, 0).value)
            list_dec.append(me.cell(i, 2).value)
            list_param.append(me.cell(i, 3).value)
            list_url.append(me.cell(i, 4).value)
            list_name.append(me.cell(i, 1).value)
            list_method.append((me.cell(i, 5).value))
            list_expect.append((me.cell(i, 6).value))
        return list_id, list_dec, list_param, list_url, list_method, list_expect, list_name
    except Exception as e:
        LOG.info('打开测试用例失败,原因是:%s' % e)
        return
コード例 #3
0
def datacel(filrpath):
    try:
        file = xlrd.open_workbook(filrpath)
        me = file.sheets()[0]
        nrows = me.nrows
        listid = []
        listconeent = []
        listurl = []
        listfangshi = []
        listqiwang = []
        listrelut = []
        listname = []
        for i in range(1, nrows):
            listid.append(me.cell(i, 0).value)

            listconeent.append(me.cell(i, 3).value)
            listurl.append(me.cell(i, 4).value)
            listname.append(me.cell(i, 1).value)
            listfangshi.append(me.cell(i, 5).value)
            listqiwang.append(me.cell(i, 6).value)
        return listid, listconeent, listurl, listfangshi, listqiwang, listname
    except Exception as e:
        LOG.info('打开测试用例失败,原因是:%s' % e)
        return


# if __name__ == '__main__':
#     datacel('../test_case_data/case.xlsx')
コード例 #4
0
ファイル: get_excel.py プロジェクト: lykion/TestApi
def datacel(filrpath):
    try:
        workbook = xlrd.open_workbook(filrpath)
        sheet = workbook.sheets()[0]
        nrows = sheet.nrows
        list_id = []
        list_is_header = []
        list_header = []
        list_url = []
        list_fangshi = []
        list_qiwang = []
        # listrelut = []
        list_name = []
        list_data = []
        for i in range(1, nrows):
            list_id.append(int(sheet.cell(i, cf.CASE_ID-1).value))
            list_name.append(sheet.cell(i, cf.CASE_NAME-1).value)
            list_is_header.append(sheet.cell(i, cf.CASE_IS_HEADER-1).value)
            list_header.append(sheet.cell(i, cf.CASE_HEADER-1).value)
            list_url.append(sheet.cell(i, cf.CASE_URL-1).value)
            list_data.append(sheet.cell(i, cf.CASE_DATA-1).value)
            list_fangshi.append(sheet.cell(i, cf.CASE_METHOD-1).value)
            list_qiwang.append(sheet.cell(i, cf.CASE_EXPECT-1).value)
            # list_qiwang.append((sheet.cell(i, cf.CASE_EXPECT-1).value))
        return list_id, list_name, list_is_header, list_header, list_data, list_url, list_fangshi, list_qiwang
    except Exception as e:
        LOG.info('打开测试用例失败,原因是:%s' % e)
        return
コード例 #5
0
ファイル: create_html.py プロジェクト: eastcn/zy
def createHtml(filepath, titles, starttime, endtime, passge, fail, id, name, key, coneent, url, meth, yuqi, json,
               relusts, exceptions, weizhi):
    LOG.info('创建HTML报告')
    texts = relust(titles, starttime, endtime, passge, fail, id, name, key, coneent, url, meth, yuqi, json, relusts,
                   exceptions, weizhi)
    with open(filepath, 'wb') as f:
        f.write(texts.encode())
コード例 #6
0
def read(filrpath):
    try:
        file = xlrd.open_workbook(filrpath)
        me = file.sheets()[0]
        nrows = me.nrows
        ID = []
        listkey = []
        listconeent = []
        listurl = []
        listfangshi = []
        listqiwang = []
        listrelut = []
        listname = []
        for i in range(1, nrows):
            ID.append(me.cell(i, test_id).value)
            listname.append(me.cell(i, test_name).value)
            listkey.append(me.cell(i, test_key).value)
            listconeent.append(me.cell(i, test_coneent).value)
            listurl.append(me.cell(i, test_url).value)
            listfangshi.append((me.cell(i, test_fangshi).value))
            listqiwang.append((me.cell(i, test_qiwang).value))
        return ID, listkey, listconeent, listurl, listfangshi, listqiwang, listname
    except Exception as e:
        LOG.info('打开测试用例失败,原因是:%s' % e)
        return
コード例 #7
0
ファイル: get_excel.py プロジェクト: blackboylikeme/HW_Study
def datacel(filrpath):
    try:
        file=xlrd.open_workbook(filrpath)
        me=file.sheets()[0] #获取第一个表格对象
        nrows=me.nrows #获取行数
        listid=[]
        listkey=[]
        listconeent=[]
        listurl=[]
        listfangshi=[]
        listqiwang=[]
        listrelut=[]
        listname=[]
        for i in range(1,nrows):
            listid.append(me.cell(i,0).value)#append用例ID-用例id列表
            listkey.append(me.cell(i,2).value)#获取key
            listconeent.append(me.cell(i,3).value)#获取参数
            listurl.append(me.cell(i,4).value)#获取URL
            listname.append(me.cell(i,1).value)#获取用例名
            listfangshi.append((me.cell(i,5).value))#请求方式 POST or Get
            listqiwang.append((me.cell(i,6).value))#期望值
        return listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname  #返回列值列表
    except Exception as e:
        LOG.info('打开测试用例失败,原因是:%s'%e)
        return
コード例 #8
0
def save_result(testtime,toial,passnum,fail):
    try:
        f=open('result.txt','a') #保存成txt格式
        f.write("%s=%s=%s=%s \n"%(testtime,toial,passnum,fail))
        f.close()
    except:
        LOG.info('保存测试结果出错,原因:%s'%Exception)
コード例 #9
0
def testinterface():
    list_pass = 0
    list_fail = 0
    list_json = []
    listrelust=[]
    list_weizhi=0
    list_exption=0
    for i in range(len(listurl)):
        api=TestApi(url=listurl[i],key=listkey[i],connent=listconeent[i],fangshi=listfangshi[i])
        apijson=api.getJson()
        if apijson['code']==0:
            LOG.info('inputdata> 参数:%s, url:%s ,返回:%s,预期:%s'%(listconeent[i],listurl[i],apijson,listqiwang[i]))
            assert_re=assert_in(asserqiwang=listqiwang[i],fanhuijson=apijson)
            if assert_re['code']==0:
                list_json.append(apijson['result'])
                listrelust.append('pass')
                list_pass += 1
            elif assert_re['code']==1:
                list_fail+=1
                listrelust.append('fail')
                list_json.append(apijson['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(apijson['result'])
            continue
    return  listrelust,list_fail,list_pass,list_json,list_exption,list_weizhi
コード例 #10
0
def assert_in(asserqiwang, fanhuijson):
    if len(asserqiwang.split('=')) > 1:
        data = asserqiwang.split('&')
        result = dict([(item.split('=')) for item in data])
        value1 = [value for value in result.keys()]
        # return_result = [k for k,v in [v for k,v in fanhuijson.items()][1].items()]

        return_result = [v for k, v in fanhuijson.items()][1]
        for k, v in result.items():
            if k in return_result.keys():
                if str(v) == str(return_result[k]):
                    print("通过检查")
                    return {'code': 0, "result": 'pass'}
                else:
                    print("Keys 检查通过,但 Value 检查未过")
                    return {'code': 1, 'result': 'fail'}
            else:
                print("检查未过")
                return {'code': 1, 'result': 'fail'}

        # 废弃代码
        # if set(value1).issubset(set(return_result)):
        #     print("通过检查")
        # else:
        #     print("检查未过")
        # if set(value1).issubset(set(return_result)):
        #     return  { 'code':0,"result":'pass'}
        # else:
        #     return {'code':1,'result':'fail'}
    else:
        LOG.info('填写测试预期值')
        return {"code": 2, 'result': '填写测试预期值'}
コード例 #11
0
ファイル: get_excel.py プロジェクト: liwanlei/jiekou-python3
def datacel(filepath):
    try:
        file = xlrd.open_workbook(filepath)
        print(file)
        rslut = file.sheets()[0]
        nrows = rslut.nrows
        listid = []
        listkey = []
        listconeent = []
        listurl = []
        listmethod = []
        listassert = []
        listname = []
        for i in range(1, nrows):
            listid.append(rslut.cell(i, 0).value)
            listkey.append(rslut.cell(i, 2).value)
            listconeent.append(rslut.cell(i, 3).value)
            listurl.append(rslut.cell(i, 4).value)
            listname.append(rslut.cell(i, 1).value)
            listmethod.append((rslut.cell(i, 5).value))
            listassert.append((rslut.cell(i, 6).value))
        return listid, listkey, listconeent, listurl, listmethod, listassert, listname
    except Exception as e:
        print(e)
        LOG.info('打开测试用例失败,原因是:%s' % e)
        return
コード例 #12
0
def dataParsing(filrpath):
    try:
        file = xlrd.open_workbook(filrpath)  #打开xlsx工作簿
        file.encoding = 'utf8'
        me = file.sheets()[0]
        nrows = me.nrows
        listid = []  #用例编号id
        listname = []  # 用例名称
        list_method = []  # 请求方式,POST、GET
        listurl = []  # 测试url
        listkey = []  #请求key值,暂不使用
        list_params = []  #请求参数
        list_anticipate = []  #预期
        listrelut = []  #结果,暂不使用

        for i in range(1, nrows):
            listid.append(me.cell(i, 0).value)  #“用例编号”追加到列表,读取excel第一列
            listname.append(me.cell(i, 1).value)  #“用例标题”追加到列表,读取excel第二列
            list_method.append((me.cell(i, 2).value))  # “用例请求方法”追加到列表,读取第六列
            listkey.append(me.cell(i, 3).value)  # “用例key值”追加到列表,读取excel第三列
            listurl.append(me.cell(i, 4).value)  # “用例请求url(自定义部分)追加到列表”,读取第五列
            list_params.append(me.cell(i, 5).value)  #“用例请求参数”追加到列表,读取excel第四列
            list_anticipate.append((me.cell(i, 6).value))  #“用例预期结果”追加到列表,读取第七列
        #返回读取列表
        return listid, listname, list_method, listurl, listkey, list_params, list_anticipate,
    except Exception as e:
        LOG.info('打开测试用例失败,原因是:%s' % e)
コード例 #13
0
def datacel():
    try:
        filepath = '.\\test_case\\case.xlsx'
        file = xlrd.open_workbook(filepath)
        me = file.sheets()[0]
        nrows = me.nrows
        listid = []
        listkey = []
        listconeent = []
        listurl = []
        listfangshi = []
        listqiwang = []
        listrelut = []
        listname = []
        for i in range(1, nrows):
            listid.append(me.cell(i, 0).value)
            listkey.append(me.cell(i, 2).value)
            listconeent.append(me.cell(i, 3).value)
            listurl.append(me.cell(i, 4).value)
            listname.append(me.cell(i, 1).value)
            listfangshi.append((me.cell(i, 5).value))
            listqiwang.append((me.cell(i, 6).value))
        return listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname
    except:
        LOG.info('打开测试用例失败,原因是:%s' % Exception)
    print()
コード例 #14
0
def datacel(filrpath):
    try:
        file = xlrd.open_workbook(filrpath)
        me = file.sheets()[0]
        nrows = me.nrows
        listid = []
        listtoken = []
        listconeent = []
        listurl = []
        listfangshi = []
        listqiwang = []
        listrelut = []
        listname = []
        listbingxing = []
        for i in range(1, nrows):
            listid.append(me.cell(i, 0).value)
            listtoken.append(me.cell(i, 2).value)
            listconeent.append(me.cell(i, 3).value)
            listurl.append(me.cell(i, 4).value)
            listname.append(me.cell(i, 1).value)
            listfangshi.append((me.cell(i, 5).value))
            listqiwang.append((me.cell(i, 6).value))
            listbingxing.append((me.cell(i, 7).value))
        return listid, listtoken, listconeent, listurl, listfangshi, listqiwang, listname, listbingxing
    except Exception as e:
        LOG.info('打开测试用例失败,原因是:%s' % e)
        return
コード例 #15
0
 def delfile(self,url,params):#删除的请求
     try:
         del_word = requests.delete(url,params = params,headers = self.headers)
         json_response = json.loads(del_word.text)
         return {'code': 0, 'result': json_response}
     except Exception as e:
         LOG.info('del请求出错,出错原因:%s' % e)
         return {'code': 1, 'result': 'del请求出错,出错原因:%s' % e}
コード例 #16
0
ファイル: panduan.py プロジェクト: wangqing0713/Autotest
def assertre(asserqingwang):
    if len(asserqingwang.split('=')) > 1:
        data = asserqingwang.split('&')
        result = dict([(item.split('=')) for item in data])
        return result
    else:
        LOG.info('填写测试预期值')
        raise {"code": 1, 'result': '填写测试预期值'}
コード例 #17
0
 def delfile(self,url,params):#删除的请求
     try:
         del_word=requests.delete(url,params=params,headers=self.headers)
         json_response=json.loads(del_word.text)
         return {'code': 0, 'result': json_response}
     except Exception as e:
         LOG.info('del请求出错,出错原因:%s' % e)
         return {'code': 1, 'result': 'del请求出错,出错原因:%s' % e}
コード例 #18
0
def assertre(anticipate):
    if len(anticipate.split('=')) > 1:
        data = anticipate.split('&')
        result = dict([(item.split('=')) for item in data])
        return result
    else:
        LOG.info('断言,填写测试预期值')
        raise {"code": 1, 'result': '断言,填写测试预期值'}
コード例 #19
0
 def post(self, url, params):  # post消息
     try:
         P = requests.post(url, params=params, headers=self.headers)
         P.encoding = 'UTF-8'
         json_response = json.loads(P.text)
         return {'code': 0, 'result': json_response}
     except Exception as e:
         LOG.info('post请求出错,出错原因:%s' % e)
         return {'code': 1, 'result': 'post请求出错,出错原因:%s' % e}
コード例 #20
0
 def delfile(self,url,params):
     # 删除的请求
     try:
         del_word=requests.delete(url,params=params,headers=self.headers)
         json_response=json.loads(del_word.text)
         return {"code": 0, "result": json_response}
     except Exception as e:
         LOG.info("del请求出错,出错原因:%s" % e)
         return {"code": 1, "result": "del请求出错,出错原因:%s" % e}
コード例 #21
0
 def putfile(self, url, params):  #put请求
     try:
         data = json.dumps(params)
         me = requests.put(url, data)
         json_response = json.loads(me.text)
         return {'code': 0, 'result': json_response}
     except Exception as e:
         LOG.info('put请求出错,出错原因:%s' % e)
         return {'code': 1, 'result': 'put请求出错,出错原因:%s' % e}
コード例 #22
0
 def post(self, url, params):  #post消息
     data = json.dumps(params)
     try:
         r = requests.post(url, params=data, headers=self.headers)
         json_response = json.loads(r.text)
         return {'code': 0, 'result': json_response}
     except Exception as e:
         LOG.info('post请求出错,出错原因:%s' % e)
         return {'code': 1, 'result': 'post请求出错,出错原因:%s' % e}
コード例 #23
0
 def get(self, url, params):  #get消息
     try:
         r = requests.get(url, params=params, headers=self.headers)
         r.encoding = 'UTF-8'
         json_response = json.loads(r.text)
         return {'code': 0, 'result': json_response}
     except Exception as e:
         LOG.info('get请求出错,出错原因:%s' % e)
         return {'code': 1, 'result': 'get请求出错,出错原因:%s' % e}
コード例 #24
0
ファイル: creatreport_excel.py プロジェクト: eastcn/zy
def create(filename,list_pass,list_fail,listids,listnames,listkeys,listcontent,listurls,listmethods,listexpects,list_json,listresult):
    LOG.info('创建EXCEL报告')
    filepath=open(r'.\config\config.yaml',encoding='utf-8')
    file_config=yaml.load(filepath)
    file=Workbook(filename)
    table=file.add_sheet('测试报告',cell_overwrite_ok=True)
    #sheet2
    table2=file.add_sheet('测试一下sheet2')
    table2.write_merge(0,0,0,8,'测试报告')

    #参数md5转换
    md5_params=[]
    for m in range(0,len(listcontent)):
        md5_params.append(set_md5(listcontent[m]))

    style_1=style1()
    for i in  range(0,8):
        table.col(i).width=380*20
    style_2=style2()
    table.write_merge(0,0,0,8,'测试报告',style=style_1)
    table.write_merge(1,2,0,8,'测试概述',style=style_2)
    table.write(3,0,'项目名称',style=style_2)
    table.write(3,1,(file_config['projectname']),style=style_2)
    table.write(3, 2, '测试人', style=style_2)
    table.write(3,3,(file_config['test_person']),style=style_2)
    table.write(3,4,'通过',style=style_2)
    table.write(3,5, list_pass, style=style_2)
    table.write(4,0,'测试时间',style=style_2)
    table.write(4,1, (file_config['test_time']), style=style_2)
    table.write(4,2,'提测时间',style=style_2)
    table.write(4,3, (file_config['gettest_time']), style=style_2)
    table.write(4,4, '失败', style=style_2)
    table.write(4,5, list_fail, style=style_2)
    table.write_merge(5,5,0,8,'测试详情',style=style_2)
    table.write(6,0,'用例ID',style=style3())
    table.write(6,1,'用例名字',style=style3())
    table.write(6,2, 'key', style=style3())
    table.write(6, 3, '参数', style=style3())
    table.write(6,4,'url',style=style3())
    table.write(6, 5, '请求方式', style=style3())
    table.write(6, 6, '预期结果', style=style3())
    table.write(6,7, '实际结果', style=style3())
    table.write(6, 8, '最终结果', style=style3())
    for i in range(len(listids)):
        table.write(i+7,0,listids[i],style=style3())
        table.write(i+7,1,listnames[i],style=style3())
        table.write(i+7,2,listkeys[i],style=style3())
        table.write(i+7,3,md5_params[i],style=style3())
        table.write(i+7,4,listurls[i],style=style3())
        table.write(i+7,5,listmethods[i],style=style3())
        table.write(i+7,6,listexpects[i],style=style3())
        table.write(i+7,7,str(list_json[i]),style=style3())
        if listresult[i]=='fail':
            table.write(i+7,8,listresult[i],style=style5())
        else:
            table.write(i+7,8,listresult[i],style=style6())
    file.save(filename)
コード例 #25
0
ファイル: test_requests.py プロジェクト: lykion/TestApi
 def get(url, param):  # get消息
     try:
         r = requests.get(url, param)
         r.encoding = 'UTF-8'
         json_response = json.loads(r.text)
         return {'code': '200', 'result': json_response}
     except Exception as e:
         LOG.info('get请求出错,出错原因:%s' % e)
         return {'code': '1', 'result': 'get请求出错,出错原因:%s' % e}
コード例 #26
0
ファイル: test_requests.py プロジェクト: lykion/TestApi
 def post(url, param):  # post消息
     data = json.dumps(param)
     try:
         r = requests.post(url, data)
         json_response = json.loads(r.text)
         return {'code': '200', 'result': json_response}
     except Exception as e:
         LOG.info('post请求出错,出错原因:%s' % e)
         return {'code': '1', 'result': 'post请求出错,出错原因:%s' % e}
コード例 #27
0
 def putfile(self,url,params):
     try:
         data = json.dumps(params)
         me = requests.put(url,data)
         json_response = json.loads(me.text)
         return {'code': 0, 'result': json_response}
     except Exception as e:
         LOG.info('put请求出错,出错原因:%s' % e)
         return {'code': 1, 'result': 'put请求出错,出错原因:%s' % e}
コード例 #28
0
 def post(self, url, params):
     data = json.dumps(params)
     try:
         r = requests.post(url,params = data,headers = self.headers)
         json_response = json.loads(r.text)
         return {'code': 0, 'result': json_response}
     except Exception as e:
         LOG.info('post请求出错,出错原因:%s' % e)
         return {'code': 1, 'result': 'post请求出错,出错原因:%s' % e}
コード例 #29
0
 def get(self, url,params):
     try:
         r = requests.get(url, params = params,headers = self.headers)
         r.encoding = 'UTF-8'
         json_response = json.loads(r.text)
         return {'code':0,'result':json_response}
     except Exception as e:
         LOG.info('get请求出错,出错原因:%s'%e)
         return {'code': 1, 'result': 'get请求出错,出错原因:%s'%e}
コード例 #30
0
 def get(self, url):
     # get消息
     try:
         r = requests.get(url, headers=self.headers)
         r.encoding = "UTF-8"
         json_response = json.loads(r.text)
         return {"code":0,"result":json_response}
     except Exception as e:
         LOG.info("get请求出错,出错原因:%s"%e)
         return {"code": 1, "result": "get请求出错,出错原因:%s"%e}
コード例 #31
0
 def post(self, url, params):
     # post消息
     data = json.loads(params)
     try:
         r =requests.post(url=url, json=data, headers=self.headers)
         json_response = json.loads(r.text)
         return {"code": 0, "result": json_response}
     except Exception as e:
         LOG.info("post请求出错,出错原因:%s" % e)
         return {"code": 1, "result": "post请求出错,出错原因:%s" % e}
コード例 #32
0
 def putfile(self,url,params):
     # put请求
     try:
         data=json.dumps(params)
         me=requests.put(url,data)
         json_response=json.loads(me.text)
         return {"code": 0, "result": json_response}
     except Exception as e:
         LOG.info("put请求出错,出错原因:%s" % e)
         return {"code": 1, "result": "put请求出错,出错原因:%s" % e}
コード例 #33
0
ファイル: dubbo_feng.py プロジェクト: caoruihua/Interface
 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
コード例 #34
0
 def delete(self, url, params):
     """
     :param url: 完整的请求url
     :param params: 完整的请求参数
     :return:返回值 “0” 代表接口可以连接,“1”代表无效接口连接
     """
     # 将传入的接口参数,转换为json格式,可能无需转换,先调试
     params_json = json.dumps(params)
     try:
         '''
         也可以使用这种方式请求
          response = requests.request("DELETE", url, headers=self.headers, params=params)
         '''
         LOG.info("DELETE开始请求接口")
         response = requests.delete(url,
                                    headers=self.headers,
                                    params=params_json)  # post方法请求接口
         LOG.info("DELETE接口请求成功,状态:%s" % response)
         reponse_json = json.loads(response.text)
         LOG.info("接口返回json信息:%s" % reponse_json)
         return {'code': 0, 'return_result_json': reponse_json}
     except Exception as error:
         LOG.info('DELETE请求出错(位置requests的模块第一次封装,请求接口有误),出错原因:%s' % error)
         return {
             'code':
             1,
             'return_result_json':
             'post请出错(位置requests的模块第一次封装,请求接口有误),出错原因:%s' % error
         }