Esempio n. 1
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)
Esempio n. 2
0
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 ('请填写期望值')
def save_result(testtime, toial, passnum, fail):
    try:
        f = open('result.txt', 'a')
        f.write("%s=%s=%s=%s \n" % (testtime, toial, passnum, fail))
        f.close()
    except:
        LOG.info('保存测试结果出错,原因:%s' % Exception)
        print('记录测试结果失败')
Esempio n. 4
0
def assert_in(asserqiwang,fanhuijson):
    if len(asserqiwang.split('=')) > 1:
        data = asserqiwang.split('&')
        #列表生成式
        result = dict([(item.split('=')) for item in data])
        value1=([(str(fanhuijson[key])) for key in result.keys()])
        value2=([(str(value)) for value in result.values()])
        if value1==value2:
            return  'pass'
        else:
            return 'fail'
    else:
        LOG.info('填写测试预期值')
        raise ('请填写期望值')
Esempio n. 5
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='预期和返回不一致')
Esempio n. 6
0
def testinterface():
    list_pass = 0
    list_fail = 0
    list_json = []
    listrelust = []
    for i in range(len(listurl)):
        api = TestApi(url=listurl[i],
                      key=listkey[i],
                      connent=listconeent[i],
                      fangshi=listfangshi[i])
        apijson = api.getJson()
        apicode = apijson['code']
        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 == 'pass':
            list_json.append(apijson)
            listrelust.append('pass')
            list_pass += 1
        else:
            list_fail += 1
            listrelust.append('fail')
            list_json.append(apijson)
    return listrelust, list_fail, list_pass, list_json
# -*- coding: utf-8 -*-
Esempio n. 8
0
 def tearDown(self):
     LOG.info('测试用例执行完毕')
Esempio n. 9
0
 def setUp(self):
     LOG.info('测试用例开始执行')