def test_update(self,case): url = conf.get('env','url') + case["url"] method =case['method'] data = eval(replace_data(case["data"])) headers =eval(conf.get('env','headers')) headers["Authorization"] = getattr(Case_Data, "token_value") expected = eval(case['expected']) row = case['case_id'] + 1 response = self.request.send_requests_sc(url=url, method=method, json=data, headers=headers) res = response.json() # 断言比对预期结果和实际结果 try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) except AssertionError as e: self.excel.write_excel(row=row, column=8, value='未通过') log.error('用例:{},执行'.format(case['title']) + color.white_red('未通过')) raise e else: self.excel.write_excel(row=row, column=8, value='通过') log.info('用例:{},执行'.format(case['title']) + color.white_green('通过'))
def test_login(self, case): # 准备用例数据 url = conf.get("env", "url") + case["url"] method = case['method'] data = eval(case["data"]) headers = eval(conf.get('env', 'headers')) # 预期结果 expected = eval(case['expected']) row = case['case_id'] + 1 # 发送请求获取结果 response = self.request.send_requests_sc(url=url, method=method, json=data, headers=headers) res = response.json() # 断言比对预期结果和实际结果 try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) except AssertionError as e: self.excel.write_excel(row=row, column=8, value='未通过') log.error('用例:{},执行'.format(case['title']) + color.white_red('未通过')) raise e else: self.excel.write_excel(row=row, column=8, value='通过') log.info('用例:{},执行'.format(case['title']) + color.white_green('通过'))
def test_add(self, case): # 准备数据 url = conf.get("env", "url") + case["url"] headers = eval(conf.get("env", "headers")) headers["Authorization"] = getattr(Case_Data, "admin_token_value") data = eval(replace_data(case["data"])) expected = eval(case["expected"]) method = case["method"] row = case["case_id"] + 1 # 发送请求 response = self.request.send_requests_sc(url=url, method=method, json=data, headers=headers) res = response.json() # 断言结果 try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) except AssertionError as e: self.excel.write_excel(row=row, column=8, value='未通过') log.error('用例:{},执行'.format(case['title']) + color.white_red('未通过')) raise e else: self.excel.write_excel(row=row, column=8, value='通过') log.info('用例:{},执行'.format(case['title']) + color.white_green('通过')) pass
def test_recharge(self, case): # 准备用例数据 url = conf.get("env", "url") + case["url"] method = case['method'] # 替换用户id case["data"] = replace_data(case["data"]) data = eval(case["data"]) headers = eval(conf.get('env', 'headers')) headers["Authorization"] = getattr(Case_Data, "token_value") # 预期结果 expected = eval(case['expected']) row = case['case_id'] + 1 # 发送请求前获取用户 if case["check_sql"]: sql = 'SELECT leave_amount FROM futureloan.member where mobile_phone={}'.format( conf.get('test_data', 'phone')) start_money = self.db.find_one(sql)['leave_amount'] # 发送请求获取结果 response = self.request.send_requests_sc(url=url, method=method, json=data, headers=headers) res = response.json() # 发送请求后获取用户 if case["check_sql"]: sql = 'SELECT leave_amount FROM futureloan.member where mobile_phone={}'.format( conf.get('test_data', 'phone')) end_money = self.db.find_one(sql)['leave_amount'] # 断言比对预期结果和实际结果 try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) # 判断是否需要进行判断 if case['check_sql']: self.assertEqual(end_money - start_money, Decimal(str(data['amount']))) except AssertionError as e: self.excel.write_excel(row=row, column=8, value='未通过') log.error('用例:{},执行'.format(case['title']) + color.white_red('未通过')) raise e else: self.excel.write_excel(row=row, column=8, value='通过') log.info('用例:{},执行'.format(case['title']) + color.white_green('通过'))
def test_invest(self, case): # 准备用例数据 url = conf.get("env", "url") + case["url"] method = case['method'] case["data"] = replace_data(case["data"]) data = eval(case["data"]) headers = eval(conf.get('env', 'headers')) # 判断当前接口是不是登录,加token if case["interface"] != "login": headers["Authorization"] = getattr(Case_Data,"token_value") # 预期结果 expected = eval(case['expected']) row = case['case_id'] + 1 # 发送请求获取结果 response = self.request.send_requests_sc(url=url, method=method, json=data, headers=headers) res = response.json() # 判断发送请求之后,判断是不是登录,提取token if case["interface"].lower() == "login": Case_Data.member_id = str(jsonpath.jsonpath(res, '$..id')[0]) token = jsonpath.jsonpath(res, '$..token')[0] token_type = jsonpath.jsonpath(res, '$..token_type')[0] # 提取token保存类属性 Case_Data.token_value = token_type + " " + token # 判断是否是加标的用例,就加标id if case["interface"] == "add": Case_Data.loan_id = str(jsonpath.jsonpath(res,"$..id")[0]) # 断言比对预期结果和实际结果 try: self.assertEqual(expected['code'], res['code']) self.assertIn(expected["msg"],res["msg"]) except AssertionError as e: self.excel.write_excel(row=row, column=8, value='未通过') log.error('用例:{},执行'.format(case['title']) + color.white_red('未通过')) raise e else: self.excel.write_excel(row=row, column=8, value='通过') log.info('用例:{},执行'.format(case['title']) + color.white_green('通过'))
def test_register(self, case): # 准备用例数据 url = conf.get("env", "url") + case['url'] method = case['method'] # 替换手机号码 phone = self.iphone() case['data'] = case['data'].replace('#phone#', phone) data = eval(case["data"]) headers = eval(conf.get('env', 'headers')) # 预期结果 expected = eval(case['expected']) row = case['case_id'] + 1 # 发送请求获取结果 response = self.request.send_requests_sc(url=url, method=method, json=data, headers=headers) res = response.json() # 注册后,进行数据库校验 if case["check_sql"]: sql = 'select * from futureloan.member where mobile_phone = {}'.format( data['mobile_phone']) count = self.db.find_count(sql) self.assertEqual(1, count) # 断言比对预期结果和实际结果 try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) except AssertionError as e: self.excel.write_excel(row=row, column=8, value='未通过') log.error('用例:{},执行'.format(case['title']) + color.white_red('未通过')) raise e else: self.excel.write_excel(row=row, column=8, value='通过') log.info('用例:{},执行'.format(case['title']) + color.white_green('通过'))
def test_loans(self, case): url = conf.get("env", "url") + case["url"] method = case["method"] data = replace_data(case['data']) headers = eval(conf.get("env", "headers")) expected = eval(case['expected']) row = case['case_id'] + 1 response = self.request.send_requests_sc(url=url,method=method,params=data,headers=headers) res = response.json() try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) except AssertionError as e: self.excel.write_excel(row=row, column=8, value='未通过') log.error('用例:{},执行'.format(case['title']) + color.white_red('未通过')) raise e else: self.excel.write_excel(row=row, column=8, value='通过') log.info('用例:{},执行'.format(case['title']) + color.white_green('通过'))