def get_pay_pwd(args, key, status): """ 获取一条用例不同场景测试数据--支付密码 :param args: 测试数路径 :param key: 测试数据对应的key-->data :param status: :return: """ pay_data = eval(get_test_data(*args).get(key)) # 支付密码为空 if status == 0: pay_data['payPwd'] = '' pay_data['orderNo'] = makeOrder().get_order().json()['result']['applyOrderNo'] return pay_data, '参数错误', '支付密码为空' # 支付密码错误 if status == 1: pay_data['payPwd'] = '111111111' pay_data['orderNo'] = makeOrder().get_order().json()['result']['applyOrderNo'] return pay_data, '参数校验异常', '支付密码错误' # 申请单号为空 if status == 2: pay_data['orderNo'] = '' return pay_data, '参数错误', '申请单号为空' # 申请单号错误 if status == 3: pay_data['orderNo'] = '22222222' return pay_data, '没有待支付的申请单,确认付款方式是否为现付', '申请单号错误' # 正常支付 if status == 4: pay_data['orderNo'] = makeOrder().get_order().json()['result']['applyOrderNo'] return pay_data, 'success', '正常支付'
def setUpClass(cls): cls.log = Log() cls.test_data = get_test_data('/fresh_data.xlsx', 'app', 3) cls.url = cls.test_data.get('route') cls.headers = eval(cls.test_data.get('header')) cls.headers['login-token'] = getAppToken().get_token() cls.method = cls.test_data.get('method')
def get_expect(args, expect_name, expect_key): """ 获取期望值 :param args: 元组:测试文件路径,sheet名称,数字n :param expect_name: 表格头部key :param expect_key: 期望值的key :return: """ expect = get_test_data(*args).get(expect_name) expect_list = [eval(expect).get(expect_key[0]), eval(expect).get(expect_key[1])] return expect_list
def get_token(self): """ 获取app登录token :return:token """ try: test_data = get_test_data('/fresh_data.xlsx', 'app', 0) res = get_response(test_data['route'], test_data['method'], data=test_data['data'], headers=eval(test_data['header'])) return res.json()['response']['token'] except Exception as e: self.log.error('获取token出现异常:{}'.format(str(e)))
def get_token(self): """ 获取PC登录token :return:token """ try: test_data = get_test_data('/fresh_data.xlsx', 'pc', 0) # data_dict = dict(zip(test_data[0], test_data[1][0])) res = get_response(test_data.get('route'), test_data.get('method'), data=test_data.get('data'), headers=eval(test_data.get('header'))) token = res.json()['result']['loginToken'] return token except Exception as e: self.log.error('出现异常:{}'.format(str(e)))
def test_query_quota_list(self, ): """ 测试获取额度维护全部列表 expect: 期望值 :return: """ url = self.test_data.get('route') headers = eval(self.test_data.get('header')) headers['login-token'] = self.token data = self.test_data.get('data') res = get_response(url, self.test_data.get('method'), data=data, headers=headers) print(res.json()) print(get_test_data('/fresh_data.xlsx', 'pc', 1).get('expect'))
def get_key(self): """ 获取key :return:key """ try: test_data = get_test_data('/fresh_data.xlsx', 'app', 1) headers = eval(test_data.get('header')) headers['login-token'] = getAppToken().get_token() res = get_response(url=test_data.get('route'), method=test_data.get('method'), headers=headers) # self.log.info('请求获取key的地址:{}'.format(data_dict.get('route'))) # self.log.info('请求方式:{}'.format(data_dict.get('method'))) # self.log.info('请求头部:{}'.format(headers)) # self.log.info('获取的key:{}'.format(res.json()['result'])) return res.json()['result'] except Exception as e: self.log.error('出现异常:{}'.format(str(e)))
def setUp(self): self.log = Log() self.token = getPcToken().get_token() self.test_data = get_test_data('/fresh_data.xlsx', 'pc', 1)
def __init__(self): self.log = Log() # 初始化日志 self.token = getAppToken().get_token() # 获取token self.key = getKey().get_key() # 获取key self.test_data = get_test_data('/fresh_data.xlsx', 'app', 2) # 初始化测试数据
def __init__(self, file_path, sheet_name, n): self.log = Log() # 初始化日志 self.token = getAppToken().get_token() # 获取token self.key = getKey().get_key() # 获取key self.test_data = get_test_data(file_path, sheet_name, n) # 初始化测试数据