def test_case(self, info, **kwargs): '''{info}''' try: if kwargs["sql_cheack"]: # 存在sql校验,获取投资的金额 sql = "select leave_amount from futureloan.member where id=%s" leaveamount_b = mysql.sql_read(sql, self.member_id)["leave_amount"] # 保留投资前的余额 sql = "select count(*) from futureloan.financelog where pay_member_id=%s" count_b = mysql.sql_read(sql, self.member_id)["count(*)"] # 保留投资前的条目数 respone = com_request(TestInvest, self.Worksheet_name, **kwargs, token=self.token) if respone["code"] == 0: # 当投资成功时减去已投资,不论预期是否成功 TestInvest.amount -= int(self.params["amount"]) com_assertEqual(self, respone, eval(kwargs["expect"])) if kwargs["sql_cheack"]: # 存在sql校验,获取投资的金额 sql = "select amount from futureloan.invest where id=%s" res = mysql.sql_read(sql, jsonpath(respone, "$..id")) self.assertEqual(decimal.Decimal(res["amount"]), decimal.Decimal(self.params["amount"])) # 校验投资金额与预期 sql = "select leave_amount from futureloan.member where id=%s" leaveamount_e = mysql.sql_read(sql, self.member_id)["leave_amount"] # 保留投资后的余额 self.assertEqual(leaveamount_b-leaveamount_e, decimal.Decimal(self.params["amount"])) # 校验投资后条目数与预期 sql = "select count(*) from futureloan.financelog where pay_member_id=%s" count_e = mysql.sql_read(sql, self.member_id)["count(*)"] # 保留投资后的条目数 self.assertEqual(count_e-count_b, 1) # 校验条目数 except AssertionError as e: log.error(f"用例--{info}--执行失败", exc_info=True) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "失败") raise e else: log.info(f"用例--{info}--执行成功", exc_info=False) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "成功")
def params_get(params, cls, type_mode=0): '''处理带*参数''' try: if "*" in params: while re.search(r"\*(.+?\s.+?.*?)\*", str(params)): res_value = re.search(r"\*(.+?\s.+?.*?)\*", str(params)) # 获取带*参数 res_str = res_value.group() res_list = res_value.group(1).split(" ") # 切割带*参数 if res_list[0] == "username": res = username_get(res_list, cls) elif "name" in res_list[0]: res = name_get(res_list, cls) elif res_list[0] == "email": res = email_get(res_list, cls) elif res_list[0] == "projects" or res_list[0] == "interfaces": res = projects_interfaces_get(res_list, cls) elif res_list[0] == "params": res = expect_params_get(res_list, cls) params = params.replace(res_str, str(res)) mysql.con.commit() except Exception: # 获取失败报判定错误 log.error("带*参数解析失败", exc_info=True) raise AssertionError else: if type_mode == 0: return eval(params) else: return params
def test_case(self, info, **kwargs): '''{info}''' try: respone = com_request(TestAudit, self.Worksheet_name, **kwargs, token=self.admin_token) com_assertEqual(self, respone, eval(kwargs["expect"])) if kwargs["sql_cheack"]: # 存在sql校验,获取审核项目状态 res = mysql.sql_read(kwargs["sql_cheack"], self.loan_id) if self.params["approved_or_not"]: statue = 2 else: statue = 5 print("实际项目状态:", res["status"]) print("预期项目状态:", statue) self.assertEqual(res["status"], statue) # 校验更新后的状态与预期 TestAudit.loan_id_pass = jsonpath(self.params, "$..loan_id")[0] except AssertionError as e: log.error(f"用例--{info}--执行失败", exc_info=True) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "失败") raise e else: log.info(f"用例--{info}--执行成功", exc_info=False) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "成功")
def params_get(params, cls, type_mode=0): '''处理带*参数''' try: if "*" in params: while re.search(r"\*(.+?\s.+?)\b", str(params)): res_value = re.search(r"\*(.+?\s.+?)\b", str(params)) # 获取带*参数 res_str = res_value.group() res_list = res_value.group(1).split(" ") # 切割带*参数 if res_list[0] == "mobile_phone": res = phone_create(res_list) elif res_list[0] == "member_id": res = member_id_get(res_list, cls) elif res_list[0] == "amount": res = leaveamount_get(res_list, cls) elif res_list[0] == "loan_id": res = loan_id_get(res_list, cls) elif res_list[0] == "audit_loan": res = audit_loan_get(res_list, cls) params = params.replace(res_str, str(res)) mysql.con.commit() except Exception: # 获取失败报判定错误 log.error("带*参数解析失败", exc_info=True) raise AssertionError else: if type_mode == 0: return eval(params) else: return params
def test_case(self, info, **kwargs): '''{info}''' try: if kwargs["sql_cheack"]: # 存在sql校验,获取初期余额 res = mysql.sql_read(kwargs["sql_cheack"], self.member_id) amount_prime = res["leave_amount"] respone = com_request(TestRecharge, self.Worksheet_name, **kwargs, token=self.token) if kwargs["sql_cheack"]: # 存在sql校验,获取充值后余额 res = mysql.sql_read(kwargs["sql_cheack"], self.member_id) amount_new = res["leave_amount"] amount = amount_new - amount_prime print("实际充值:", float(amount)) print("预期充值:", float(self.params["amount"])) self.assertEqual(float(amount), float(self.params["amount"])) # 校验充值的余额实际与预期 com_assertEqual(self, respone, eval(kwargs["expect"])) except AssertionError as e: log.error(f"用例--{info}--执行失败", exc_info=True) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "失败") raise e else: log.info(f"用例--{info}--执行成功", exc_info=False) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "成功")
def env_params_init(): '''预置账号写入''' # 预置账号信息写入conf.ini文件 try: env_params_regist() env_projects_create() env_testcases_create() except Exception as e: log.error("测试环境数据初始化失败", exc_info=True) raise ValueError("测试环境数据初始化失败")
def test_case(self, info, **kwargs): '''{info}''' try: respone = com_request(TestLogin, self.Worksheet_name, **kwargs) com_assertEqual(self, respone, eval(kwargs["expect"])) except AssertionError as e: log.error(f"用例--{info}--执行失败", exc_info=True) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "失败") raise e else: log.info(f"用例--{info}--执行成功", exc_info=False) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "成功")
def env_params_init(): '''预置账号写入''' # 新增一个项目项目借款金额10000000 # 将账号信息写入conf.ini文件 try: env_params_regist() env_params_add_audit() env_params_recharge(config.getint("PRESET", "preset_recharge_amount"), config.getint("PRESET", "preset_recharge_times")) except Exception as e: print(e) log.error("测试环境数据初始化失败", exc_info=True) raise ValueError("测试环境数据初始化失败")
def env_params_regist(): '''生成一组借款人/投资人/管理员账号,将账号信息写入conf.ini文件''' try: type_dic = {"loan_params": 1, "admin_params": 0, "invest_params": 1} for type_key, type_value in type_dic.items(): params = { "mobile_phone": int(phone_create("new")), "pwd": "334498sun", "type": type_value } respone = com_request(env_params_regist, "register", params=params) if respone["msg"] == "OK": params.pop("type") config_write("PRESET", type_key, str(params)) else: raise ValueError except Exception as e: log.error("测试环境数据初始化失败", exc_info=True) raise ValueError("测试环境数据初始化失败")
def test_case(self, info, **kwargs): '''{info}''' try: respone = com_request(TestRegister, self.Worksheet_name, **kwargs) com_assertEqual(self, respone, eval(kwargs["expect"])) if kwargs["sql_cheack"]: # 存在sql校验,获取新增注册名称 res = mysql.sql_read( kwargs["sql_cheack"], jsonpath(respone.json(), "$..username")[0]) print("实际项目名称:", res["username"]) print("预期项目名称:", self.params["username"]) self.assertEqual(res["username"], self.params["username"]) # 校验更新后的昵称与预期 except AssertionError as e: log.error(f"用例--{info}--执行失败", exc_info=True) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "失败") raise e else: log.info(f"用例--{info}--执行成功", exc_info=False) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "成功")
def test_case(self, info, **kwargs): '''{info}''' try: respone = com_request(TestUpdate, self.Worksheet_name, **kwargs, token=self.token) if kwargs["sql_cheack"]: # 存在sql校验,获取更新后昵称 res = mysql.sql_read(kwargs["sql_cheack"], self.member_id) print("实际昵称:", res["reg_name"]) print("预期昵称:", self.params["reg_name"]) self.assertEqual(res["reg_name"], self.params["reg_name"]) # 校验更新后的昵称与预期 com_assertEqual(self, respone, eval(kwargs["expect"])) except AssertionError as e: log.error(f"用例--{info}--执行失败", exc_info=True) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "失败") raise e else: log.info(f"用例--{info}--执行成功", exc_info=False) self.excel.excel_write(self.Worksheet_name, kwargs["id"], "成功")