def test_register(self, case): headers = eval(conf.get("header", "headers")) url = conf.get("address", "url") + case['url'] phone = self.random_phone() if "$phone$" in case['params']: case['params'] = case['params'].replace("$phone$", phone) params = eval(case['params']) expected = eval(case['expected']) methods = case['methods'] rows = case['case_id'] + 1 response = requests.request(url=url, json=params, method=methods, headers=headers) result = response.json() try: self.assertEqual(expected['code'], result['code']) self.assertEqual(expected['msg'], result['msg']) sql = case['mysql_data'] if sql: response = db.find_data(sql.format(params['mobile_phone'])) self.assertTrue(response) except Exception as E: self.excel.write_excel(row=rows, column=7, value="失败") log.error(f"{case['title']}执行失败") log.exception(E) raise E else: self.excel.write_excel(row=rows, column=7, value='通过') log.info(f"{case['title']}执行通过")
def test_invest(self, item): url = conf.get("address", 'url') + item['url'] item['params'] = handle_regular_class.replace_data( item['params'], test_invest_class) params = eval(item['params']) methods = item['methods'] rows = item['case_id'] + 1 headers = eval(conf.get("headerv2", "headers")) headers['Authorization'] = self.token expected = eval(item['expected']) invest_response = requests.request(url=url, json=params, method=methods, headers=headers) invest_result = invest_response.json() print("预期结果为:", expected) print("实际结果为:", invest_result) try: self.assertEqual(expected['code'], invest_result['code']) self.assertEqual(expected['msg'], invest_result['msg']) except AssertionError as e: self.excel.write_excel(row=rows, column=10, value="fail") log.exception(e) raise e else: self.excel.write_excel(row=rows, column=10, value="pass")
def test_withdraw02(self, case): url = conf.get("address", "url") + case['url'] # if "#mobile_phone#" in case['params']: # case['params']=case['params'].replace("#mobile_phone#",conf.get("user","mobile_phone")) # if "#pwd#" in case['params']: # case['params']=case['params'].replace("#pwd#",conf.get("user","pwd")) # if "#member_id#" in case['params']: # case['params']=case['params'].replace("#member_id#",str(self.member_id)) case['params'] = handle_regular_class.replace_data( case['params'], test_withdraw02_class) params = eval(case['params']) # print(params) methods = case['methods'] headers = eval(conf.get("headerv2", "headers")) if case['interface'] == 'withdraw': headers['Authorization'] = self.token expected = eval(case["expected"]) rows = case['case_id'] + 1 sql = case['check_data'] # print(params['amount']) if sql: s_result = db.find_data(sql.format(self.member_id)) s_amount = s_result[0]['leave_amount'] # print(s_amount) response = requests.request(url=url, json=params, headers=headers, method=methods) res = response.json() print("预期结果:", expected) print("实际结果:", res) # print(res) if case['interface'] == "login": test_withdraw02_class.token = "Bearer" + " " + jsonpath( res, "$..token")[0] test_withdraw02_class.member_id = jsonpath(res, "$..id")[0] if sql: e_result = db.find_data(sql.format(self.member_id)) e_amount = e_result[0]['leave_amount'] # print(e_amount) try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) if sql: self.assertEqual(float(s_amount - e_amount), float(params['amount'])) except AssertionError as e: self.excel.write_excel(row=rows, column=8, value='失败') # self.excel.write_excel(row=rows,column=10,value=res['msg']) log.error(f"用例{case['title']}执行失败") log.exception(e) raise e else: self.excel.write_excel(row=rows, column=8, value='通过')
def test_add(self, item): url = conf.get("address", 'url') + item['url'] # if "#member_id#" in item['params']: # print(self.member_id) # item['params']=item['params'].replace("#member_id#",str(self.member_id)) item['params'] = handle_regular_class.replace_data( item['params'], test_add_class) params = eval(item['params']) headers = eval(conf.get("headerv2", "headers")) headers["Authorization"] = self.token methods = item['methods'] expected = eval(item['expected']) rows = item['case_id'] + 1 sql = item['check_data'] if sql: s_res = db.find_data(sql.format(self.member_id)) s_num = s_res[0]['num'] print(s_num) response_add = requests.request(url=url, json=params, method=methods, headers=headers) res_add = response_add.json() if sql: e_res = db.find_data(sql.format(self.member_id)) e_num = e_res[0]['num'] # print(e_num) # print(res_add) print("预期结果:", expected) print("实际结果:", res_add) try: self.assertEqual(expected['code'], res_add['code']) self.assertEqual(expected['msg'], res_add['msg']) if sql: self.assertEqual(int(e_num - s_num), 1) except AssertionError as e: self.excel.write_excel(row=rows, column=8, value="fail") log.exception(e) raise e else: self.excel.write_excel(row=rows, column=8, value="pass")
def test_withdraw(self, case): url = conf.get("address", "url") + case['url'] # print(url) # if "#member_id#" in case['params']: # case['params']=case['params'].replace("#member_id#",str(self.member_id)) # print(self.member_id) case['params'] = handle_regular_class.replace_data( case['params'], test_withdraw_class) params = eval(case['params']) methods = case['methods'] headers = eval(conf.get("headerv2", "headers")) headers['Authorization'] = self.token expected = eval(case["expected"]) rows = case['case_id'] + 1 sql = case['check_data'] # print(params['amount']) if sql: s_result = db.find_data(sql.format(self.member_id)) s_amount = s_result[0]['leave_amount'] # print(s_amount) response = requests.request(url=url, json=params, headers=headers, method=methods) res = response.json() try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) if sql: e_result = db.find_data(sql.format(self.member_id)) e_amount = e_result[0]['leave_amount'] self.assertEqual(float(s_amount - e_amount), params['amount']) except AssertionError as e: self.excel.write_excel(row=rows, column=8, value='失败') self.excel.write_excel(row=rows, column=10, value=res['msg']) log.error(f"用例{case['title']}执行失败") log.exception(e) raise e else: self.excel.write_excel(row=rows, column=8, value='通过')
def test_register(self,case): headers = eval(conf.get("header", "headers")) url=conf.get("address","url")+case['url'] params=eval(case['params']) expected=eval(case['expected']) methods=case['methods'] rows=case['case_id']+1 response=requests.request(url=url,json=params,method=methods,headers=headers) result=response.json() try: self.assertEqual(expected['code'],result['code']) self.assertEqual(expected['msg'],result['msg']) except Exception as E: self.excel.write_excel(row=rows,column=7,value="失败") log.error(f"{case['title']}执行失败") log.exception(E) raise E else: self.excel.write_excel(row=rows,column=7,value='通过') log.info(f"{case['title']}执行通过")
def test_recharge(self, case): base_url = conf.get("address", 'url') url = base_url + case['url'] if "#member_id#" in case['params']: case['params'] = case['params'].replace("#member_id#", str(self.member_id)) params = eval(case['params']) methods = case['methods'] headers = eval(conf.get("headerv2", "headers")) headers['Authorization'] = self.token expected = eval(case['expected']) rows = case['case_id'] + 1 sql = case['check_data'] if sql: s_result = db.find_data(sql.format(self.member_id)) s_amout = s_result[0]["leave_amount"] # print(s_amout) response = requests.request(url=url, json=params, method=methods, headers=headers) res = response.json() print("预期结果:", expected) print("实际结果:", res) try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) if sql: e_result = db.find_data(sql.format(self.member_id)) e_amout = e_result[0]["leave_amount"] self.assertEqual(float(e_amout - s_amout), params['amount']) except AssertionError as e: self.excel.write_excel(row=rows, column=7, value="失败") # self.excel.write_excel(row=rows,column=8,value=str(res['msg'])) log.error(f"测试用例{case['title']}执行失败") log.exception(e) raise e else: self.excel.write_excel(row=rows, column=7, value="通过") log.info(f"测试用例{case['title']}执行通过")
def test_audit(self,item): url = conf.get("address", 'url') + item['url'] item['params']=handle_regular_class.replace_data(item['params'],test_audit_class) params = eval(item['params']) print(params) headers = eval(conf.get("headerv2", "headers")) headers["Authorization"] = self.admin_token methods = item['methods'] expected = eval(item['expected']) rows = item['case_id'] + 1 response_add = requests.request(url=url, json=params, method=methods, headers=headers) res_add = response_add.json() print("预期结果:", expected) print("实际结果:", res_add) sql=item['check_data'] try: self.assertEqual(expected['code'], res_add['code']) self.assertEqual(expected['msg'], res_add['msg']) if sql: search = db.find_data(sql.format(self.loan_id))[0]['status'] self.assertEqual(expected['status'],search) if int(search)==2: test_audit_class.pass_loan_id = params['loan_id'] except AssertionError as e: self.excel.write_excel(row=rows, column=8, value="fail") log.exception(e) raise e else: self.excel.write_excel(row=rows, column=8, value="pass")
class Test_login_class: @pytest.mark.parametrize('case', casedatas.login_data_pass) def test_login_is_pass(self, case, setup_login): login, index = setup_login login.login_click(case['phone'], case['password']) res = index.is_login() try: assert res except AssertionError as e: log.error("用例---{}--执行失败".format(case['title'])) log.exception(e) raise e else: log.info("用例执行成功") index.click_quit()
raise e else: log.info("用例执行成功") index.click_quit() @pytest.mark.parametrize('case', casedatas.login_data_is_none) def test_login_is_none(self, case, setup_login): login, index = setup_login login.reset_login() login.login_click(case['phone'], case['password']) res = login.get_page_error_info() try: assert case['expected'] == res except AssertionError as e: log.error("用例---{}---执行失败".format(case['title'])) log.exception(e) raise e else: log.info("用例执行成功") @pytest.mark.parametrize('case', casedatas.login_toast_is_error) def test_login_toast_error(self, case, setup_login): login, index = setup_login login.reset_login() login.login_click(case['phone'], case['password']) res = login.get_page_toast_info() try: assert case['expected'] == res except AssertionError as e: log.error("用例--{}--执行失败".format(case['title']))