Пример #1
0
    def test_loans(self, case):
        url = conf.get("env", "url") + case["url"]
        data = eval(case["data"])
        headers = eval(conf.get("env", "headers"))
        headers["Authorization"] = self.user_token
        expected = eval(case["expected"])
        row = case["case_id"] + 1

        # 发送接口请求
        response = requests.get(url=url, json=data, headers=headers)
        res = response.json()
        print("预期结果:", expected)
        print("实际结果:", res)
        # 获取充值后的金额
        # 第三步:断言预期结果和实际结果
        try:
            self.assertEqual(expected["code"], res["code"])
            self.assertEqual(expected["msg"], res["msg"])

        except AssertionError as e:
            # 结果回写excel中
            log.error("用例--{}--执行未通过".format(case["title"]))
            log.debug("预期结果:{}".format(expected))
            log.debug("实际结果:{}".format(res))
            log.exception(e)
            self.excel.write_data(row=row, column=8, value="未通过")
            raise e
        else:
            # 结果回写excel中
            log.info("用例--{}--执行通过".format(case["title"]))
            self.excel.write_data(row=row, column=8, value="通过")
Пример #2
0
    def test_audit(self, case):

        url = conf.get("env", "url") + case["url"]
        data = eval(case["data"].replace("#loan_id#", str(self.load_id)))
        headers = eval(conf.get("env", "headers"))
        headers["Authorization"] = self.admin_token
        expected = eval(case["expected"])
        row = case["case_id"] + 1
        response = requests.patch(url=url, json=data, headers=headers)
        res = response.json()
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected["code"], res["code"])
            self.assertEqual(expected["msg"], res["msg"])
        except AssertionError as e:
            # 结果回写excel中
            log.error("用例--{}--执行未通过".format(case["title"]))
            log.debug("预期结果:{}".format(expected))
            log.debug("实际结果:{}".format(res))
            log.exception(e)
            self.excel.write_data(row=row, column=8, value="未通过")
            raise e
        else:
            # 结果回写excel中
            log.info("用例--{}--执行通过".format(case["title"]))
            self.excel.write_data(row=row, column=8, value="通过")
Пример #3
0
 def test_recharge(self, case):
     url = conf.get("env", "url") + case["url"]
     case["data"] = case["data"].replace("#member_id#", self.member_id)
     data = eval(case["data"])
     headers = eval(conf.get("env", "headers"))
     headers["Authorization"] = self.token
     expected = eval(case["expected"])
     row = case["case_id"] + 1
     if case["check_sql"]:
         sql = case["check_sql"].format(self.member_id)
         start_money = self.db.find_one(sql)["leave_amount"]
         log.debug("充值之前的金额:{}".format(start_money))
     # 发送接口请求
     response = requests.post(url=url, json=data, headers=headers)
     res = response.json()
     print("预期结果:", expected)
     print("实际结果:", res)
     # 获取充值后的金额
     if case["check_sql"]:
         sql = case["check_sql"].format(self.member_id)
         end_money = self.db.find_one(sql)["leave_amount"]
         log.debug("充值之后的金额:{}".format(end_money))
         # 第三步:断言预期结果和实际结果
         try:
             self.assertEqual(expected["code"], res["code"])
             self.assertEqual(expected["msg"], res["msg"])
             # 判断是否需要进行sql校验
             if case["check_sql"]:
                 # 将充值金额转换为decimal类型(因为数据库中的金额是decimal类型的)
                 recharge_money = decimal.Decimal(str(data["amount"]))
                 self.assertEqual(recharge_money, end_money - start_money)
         except AssertionError as e:
             # 结果回写excel中
             log.error("用例--{}--执行未通过".format(case["title"]))
             log.debug("预期结果:{}".format(expected))
             log.debug("实际结果:{}".format(res))
             log.exception(e)
             self.excel.write_data(row=row, column=8, value="未通过")
             raise e
         else:
             # 结果回写excel中
             log.info("用例--{}--执行通过".format(case["title"]))
             self.excel.write_data(row=row, column=8, value="通过")
Пример #4
0
 def test_update(self, case):
     url = conf.get("env", "url") + case["url"]
     print(url)
     # data = eval(replace_data(case["data"]))
     data = eval(case["data"].replace("#member_id#", self.member_id))
     headers = eval(conf.get("env", "headers"))
     headers["Authorization"] = self.token
     expected = eval(case["expected"])
     row = case["case_id"] + 1
     if case["check_sql"]:
         sql = case["check_sql"].replace("#member_id#", self.member_id)
         # reg_name = self.db.find_one(sql)
         # log.debug("修改之前的name:{}".format(reg_name))
     # 发送接口请求
     response = requests.patch(url=url, json=data, headers=headers)
     res = response.json()
     print("预期结果:", expected)
     print("实际结果:", res)
     # 获取充值后的金额
     # 第三步:断言预期结果和实际结果
     try:
         self.assertEqual(expected["code"], res["code"])
         self.assertEqual(expected["msg"], res["msg"])
         # 判断是否需要进行sql校验
         if case["check_sql"]:
             sql = case["check_sql"].replace("#member_id#", self.member_id)
             reg_name = self.db.find_one(sql)
             self.assertEqual(data["reg_name"], reg_name["reg_name"])
     except AssertionError as e:
         # 结果回写excel中
         log.error("用例--{}--执行未通过".format(case["title"]))
         log.debug("预期结果:{}".format(expected))
         log.debug("实际结果:{}".format(res))
         log.exception(e)
         self.excel.write_data(row=row, column=8, value="未通过")
         raise e
     else:
         # 结果回写excel中
         log.info("用例--{}--执行通过".format(case["title"]))
         self.excel.write_data(row=row, column=8, value="通过")
Пример #5
0
    def test_add(self, case):
        url = conf.get("env", "url") + case["url"]
        case["data"] = case["data"].replace("#member_id#", self.member_id)
        data = eval(case["data"])
        headers = eval(conf.get("env", "headers"))
        headers["Authorization"] = self.token
        expected = eval(case["expected"])
        row = case["case_id"] + 1
        if case["check_sql"]:
            sql = case["check_sql"].replace("#member_id#", self.member_id)
            start_count = self.db.find_count(sql)

        response = requests.post(url=url, json=data, headers=headers)
        res = response.json()
        print("预期结果:", expected)
        print("实际结果:", res)
        # 断言
        try:
            self.assertEqual(expected["code"], res["code"])
            self.assertEqual(expected["msg"], res["msg"])
            if case["check_sql"]:
                # 加标之后
                sql = case["check_sql"].replace("#member_id#", self.member_id)
                end_count = self.db.find_count(sql)
                self.assertEqual(1, end_count - start_count)
        except AssertionError as e:
            # 结果回写excel中
            log.error("用例--{}--执行未通过".format(case["title"]))
            log.debug("预期结果:{}".format(expected))
            log.debug("实际结果:{}".format(res))
            log.exception(e)
            self.excel.write_data(row=row, column=8, value="未通过")
            raise e
        else:
            # 结果回写excel中
            log.info("用例--{}--执行通过".format(case["title"]))
            self.excel.write_data(row=row, column=8, value="通过")