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 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 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 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 setUp(self): '''新增项目''' expect = {'code': 0, 'msg': 'OK'} # 预期结果转换成字典 params = str({ "member_id": self.member_id, "title": "孙忘_财务自由1", "amount": 1000000000, "loan_rate": 1, "loan_term": 1, "loan_date_type": 1, "bidding_days": 1 }) # 参数处理 respone = com_request(TestAudit, "add", params=params, token=self.token) com_assertEqual(self, respone, expect) TestAudit.loan_id = jsonpath(respone, "$..id")[0]
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"], "成功")