def test_cm(self): cookie = test_login.login() common_url = conf.ReadConfig().getloginConfigValue('url') jsondatas = ['data'] for i in range(int(get.get_nrows('cm')) - 1): #读取jsonpath jsonpathexcel = get.get_jsonpath('cm', i + 1) # 判断是否执行 if int(get.get_data('cm', i + 1, 4)) == 1: login_url = get.get_data('cm', i + 1, 2) url = common_url + login_url data = get.get_formdata('cm', i + 1, jsondatas[-1]) header = { "Content-Type": "application/x-www-form-urlencoded", "Cookie": cookie } global r print url if get.get_data('cm', i + 1, 3) == 'post': r = requests.post(url=url, headers=header, data=data) time_consume = r.elapsed.microseconds if checkall.checkall('cm', i + 1, r.status_code, r.content) == 'pass': set.set_result(2, i + 1, 'pass') elif checkall.checkall('cm', i + 1, r.status_code, r.content) == 'fail': set.set_result(2, i + 1, 'fail') if jsonpathexcel != '': jsondata = getjson.get_rcontent( json.loads(r.content), jsonpathexcel) jsondatas.append(jsondata) set.set_statuscode(2, i + 1, r.status_code) set.set_content(2, i + 1, r.content.decode('UTF-8')) set.set_sql(2, i + 1, checkdb.check('cm', i + 1)[1]) elif get.get_data('cm', i + 1, 3) == 'get': r = requests.get(url=url, headers=header, data=data) if checkall.checkall('cm', i + 1, r.status_code, r.content) == 'pass': set.set_result(2, i + 1, 'pass') elif checkall.checkall('cm', i + 1, r.status_code, r.content) == 'fail': set.set_result(2, i + 1, 'fail') if jsonpathexcel != '': jsondata = getjson.get_rcontent( json.loads(r.content), jsonpathexcel) jsondatas.append(jsondata) set.set_statuscode(2, i + 1, r.status_code) set.set_content(2, i + 1, r.content.decode('UTF-8')) set.set_sql(2, i + 1, checkdb.check('cm', i + 1)[1]) set.set_time(2, i + 1, str(time_consume)) elif int(get.get_data('cm', i + 1, 4)) == 0: print 'not execute' set.set_result(2, i + 1, 'not execute')
def test_pd(self): cookie = test_login.login() common_url = conf.ReadConfig().getloginConfigValue('url') for i in range(int(get.get_nrows('pd')) - 1): # 判断是否执行 if int(get.get_data('pd', i + 1, 4)) == 1: login_url = get.get_data('pd', i + 1, 2) url = common_url + login_url data = get.get_formdata('pd', i + 1) header = { "Content-Type": "application/x-www-form-urlencoded", "Cookie": cookie } global r print url if get.get_data('pd', i + 1, 3) == 'post': r = requests.post(url=url, headers=header, data=data) if checkall.checkall('pd', i + 1, r.status_code, r.content) == 'pass': set.set_result(1, i + 1, 'pass') elif checkall.checkall('pd', i + 1, r.status_code, r.content) == 'fail': set.set_result(1, i + 1, 'fail') set.set_statuscode(1, i + 1, r.status_code) set.set_content(1, i + 1, r.content.decode('UTF-8')) set.set_sql(1, i + 1, checkdb.check('pd', i + 1)[1]) elif get.get_data('pd', i + 1, 3) == 'get': r = requests.get(url=url, headers=header, data=data) if checkall.checkall('pd', i + 1, r.status_code, r.content) == 'pass': set.set_result(1, i + 1, 'pass') elif checkall.checkall('pd', i + 1, r.status_code, r.content) == 'fail': set.set_result(1, i + 1, 'fail') set.set_statuscode(1, i + 1, r.status_code) set.set_content(1, i + 1, r.content.decode('UTF-8')) set.set_sql(1, i + 1, checkdb.check('pd', i + 1)[1]) elif int(get.get_data('pd', i + 1, 4)) == 0: print 'not execute' set.set_result(1, i + 1, 'not execute')
def checkall(sheetname,i,code,content): ''' 检查结果1.status_code 2.db校验 3.content正则匹配 :param self: :param i: 行 :param code: :param content: :return: ''' #判断结果是pass还是fail if int(code) == 200 : if checkdb.check(sheetname,i)[0] == 'pass': print re.search(str(get.get_data(sheetname,i,10)),content)!=None if re.search(str(get.get_data(sheetname,i,10)),content)!=None: return 'pass' elif re.search(get.get_data(sheetname,i,10),content) is None: return 'fail' else: return 'fail' else: return 'fail'