Esempio n. 1
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="通过")
Esempio n. 2
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="通过")
Esempio n. 3
0
    def test_register(self, case):
        headers = eval(conf.get("env", "headers"))
        url = case["url"]
        if "#phone#" in case["data"]:
            phone = self.random_phone()
            case["data"] = case["data"].replace("#phone#", phone)
        data = eval(case["data"])
        log.debug("注册用例更新手机号码的数据={}".format(data))
        expected = eval(case["expected"])
        row = case["case_id"] + 1
        res_count = 0  # sql影响行数,打印日志使用

        response = requests.post(url=url, json=data, headers=headers)
        response = response.json()
        print("预期结果:", expected)
        print("实际结果:", response)
        try:
            self.assertEqual(response["code"], expected["code"])
            self.assertEqual(response["msg"], expected["msg"])
            if case["check_sql"]:
                sql = case["check_sql"].replace("#phone#",
                                                data["mobile_phone"])
                res_count = db.find_count(sql)
                self.assertEqual(1, res_count)
        except AssertionError as e:
            log.error("用例-{}-未通过".format(case["title"]))
            log.error("预期结果-{}".format(case["expected"]))
            log.error("实际结果-{}".format(response))
            log.error("sql影响行数={}".format(res_count))
            self.excel_register.write_data(row=row, column=8, value="未通过")
            raise e
        else:
            self.excel_register.write_data(row=row, column=8, value="通过")
            log.info("用例-{}-通过".format(case["title"]))
    def login(self, mobile_phone=conf.get("test_data", "phone"), pwd=conf.get("test_data", "pwd")) -> list:
        """
        登录
        :param username: 用户名
        :param password: 密码
        :return: 用户ID和token
        """

        url = conf.get("env", "url") + "/member/login"
        data = {
            "mobile_phone": mobile_phone,
            "pwd": pwd
        }
        headers = eval(conf.get("env", "headers"))
        response = requests.post(url=url, json=data, headers=headers)
        res = response.json()
        log.debug("res={}".format(res))
        member_id = str(common_util.get_json_one(res, "$..id"))
        token = "Bearer" + " " + common_util.get_json_one(res, "$..token")

        return member_id, token
Esempio n. 5
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="通过")
Esempio n. 6
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="通过")
Esempio n. 7
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="通过")