예제 #1
0
def audit_loan_id():
    headers = {
        "X-Lemonban-Media-Type": "lemonban.v2",
        "Content-Type": "application/json",
        "Authorization": Handler().admin_token
    }
    data = {"loan_id": Handler().loan_id, "approved_or_not": True}
    visit(method="patch",
          url=Handler.host + "futureloan/loan/audit",
          json=data,
          headers=headers)
    return data["loan_id"]
예제 #2
0
    def test_login(self, test_info):
        # phone = self.random_phone()
        # phone_yes = self.phone_yes()
        if "#phone#" in test_info["data"]:
            test_info["data"] = test_info["data"].replace(
                "#phone#", self.phone)
        if "#yes_phone#" in test_info["data"]:
            test_info["data"] = test_info["data"].replace(
                "#yes_phone#", self.phone_yes)

        data = json.loads(test_info["data"])
        url = Handler().host + test_info["url"]
        resp = visit(test_info["method"],
                     url=url,
                     json=json.loads(test_info["data"]),
                     headers=json.loads(test_info["headers"]))
        try:
            for k, v in json.loads(test_info["expected"]).items():
                self.assertEqual(resp[k], v)
            if resp[k] == 0:
                db_data = MySqlHandlerWare().query(
                    "select * from member where mobile_phone = {};".format(
                        data["mobile_phone"]))
                self.assertTrue(db_data)
            Handler.excel.write("登录", test_info["case_id"] + 1, 9, "通过")
            logger.info("第{}条测试用例通过".format(test_info["case_id"]))
        except Exception as e:
            logger.info("第{}条测试用例失败".format(test_info["case_id"]))
            print(f"返回的不是jsong格式:{e}")
            Handler.excel.write("登录", test_info["case_id"] + 1, 9, "失败")
            raise e
예제 #3
0
    def test_withdraw(self, test_info):
        if "#token#" in test_info["headers"]:
            test_info["headers"] = test_info["headers"].replace("#token#", self.token)

        if "#member_id#" in test_info["data"]:
            test_info["data"] = test_info["data"].replace("#member_id#", str(self.member_id))

        if "#other_member_id#" in test_info["data"]:
            test_info["data"] = test_info["data"].replace("#other_member_id#", str(self.other_member_id))

        url = Handler.host + test_info["url"]
        sql = "select * from member where id = {};".format(self.member_id)
        before_data = self.db.query(sql)
        before_money = before_data["leave_amount"]

        resp = visit(method=test_info["method"],
                     url=url,
                     json=eval(test_info["data"]),
                     headers=json.loads(test_info["headers"]))
        try:
            for key, value in eval(test_info["expected"]).items():
                self.assertTrue(resp[key] == value)
            if resp["code"] == 0:
                # 查询之后的余额
                sql = "select * from member where id = {};".format(self.member_id)
                after_data = self.db.query(sql)
                after_money = after_data["leave_amount"]
                data = json.loads(test_info["data"])["amount"]
                new_money = before_money - Decimal(str(data))
                # print(new_money)
                self.assertTrue(new_money == after_money)
            logger.info("第{}条测试用例通过".format(test_info["case_id"]))
        except Exception as e:
            raise e
예제 #4
0
 def test_car_register(self, test_info):
     test_info["data"] = replace_data(Handler(), test_info["data"])
     resp = visit(method=test_info["method"],
                  url=Handler.host + test_info["url"],
                  json=json.loads(test_info["data"]))
     expected = json.loads(test_info["expected"])
     self.assertTrue(expected["code"] == resp["code"])
     self.assertTrue(expected["msg"] == resp["msg"])
     logger.info("第{}条测试用例通过".format(test_info["case_id"]))
예제 #5
0
def login(user):
    url = Handler.host + "futureloan/member/login"
    data = user
    headers = {
        "X-Lemonban-Media-Type": "lemonban.v2",
        "Content-Type": "application/json"
    }
    res = visit(url=url, method="post", json=data, headers=headers)
    token_1 = jsonpath(res, "$..token")[0]
    token_type = jsonpath(res, "$..token_type")[0]
    token = " ".join((token_type, token_1))
    member_id = jsonpath(res, "$..id")[0]
    return {"token": token, "member_id": member_id}
예제 #6
0
    def test_getcode(self, test_info):
        url = Handler.host + test_info["url"]

        resp = visit(method=test_info["method"],
                     url=url,
                     json=json.loads(test_info["data"]))

        try:
            expected = json.loads(test_info["expected"])
            self.assertTrue(expected["code"] == resp["code"])
            self.assertTrue(expected["msg"] == resp["msg"])

            logger.info("第{}条测试用例通过".format(test_info["case_id"]))

        except Exception as e:
            # logger.error("请求不是json格式")
            raise e
예제 #7
0
 def test_login(self, test_info):
     expected = json.loads(test_info["expected"])
     url = Handler().host + test_info["url"]
     resp = visit(
         test_info["method"],
         url=url,
         json=json.loads(test_info["data"]),
     )
     try:
         self.assertEqual(expected["code"], resp["code"])
         self.assertEqual(expected["msg"], resp["msg"])
         Handler.excel.write("登录", test_info["case_id"] + 1, 9, "通过")
         logger.info("第{}条测试用例通过".format(test_info["case_id"]))
     except Exception as e:
         # logger.info("第{}条测试用例失败".format(test_info["case_id"]))
         print(f"返回的不是json格式:{e}")
         Handler.excel.write("登录", test_info["case_id"] + 1, 9, "失败")
         raise e
예제 #8
0
def loan_id():
    item_data = {
        "member_id": Handler().member_id,
        "title": "买车",
        "amount": 50000,
        "loan_rate": 20.0,
        "loan_term": 30,
        "loan_date_type": 2,
        "bidding_days": 10
    }
    headers = {
        "X-Lemonban-Media-Type": "lemonban.v2",
        "Content-Type": "application/json",
        "Authorization": Handler().token
    }
    resp = visit(method="post",
                 url=Handler.host + "futureloan/loan/add",
                 json=item_data,
                 headers=headers)
    return jsonpath(resp, "$..id")[0]
예제 #9
0
    def test_audit(self, test_info):

        test_info["headers"] = replace_data(Handler(), test_info["headers"])

        test_info["data"] = replace_data(Handler(), test_info["data"])

        resp = visit(method=test_info["method"],
                     url=Handler.host + test_info["url"],
                     json=json.loads(test_info["data"]),
                     headers=eval(test_info["headers"]))
        expected = eval(test_info["expected"])
        self.assertTrue(expected["code"] == resp["code"])
        self.assertTrue(expected["msg"] == resp["msg"])

        if resp["code"] == 0:
            # 验证数据库状态
            data = json.loads(test_info["data"])
            loan = MySqlHandlerWare().query(
                "SELECT * FROM loan WHERE id={}".format(data["loan_id"]))
            self.assertEqual(expected["status"], loan["status"])

        logger.info("第{}条测试用例通过".format(test_info["case_id"]))
예제 #10
0
    def test_add_item(self, test_info):
        url = Handler.host + test_info["url"]
        test_info["data"] = replace_data(Handler(), test_info["data"])
        test_info["headers"] = replace_data(Handler(), test_info["headers"])
        resp = visit(method=test_info["method"],
                     url=url,
                     json=json.loads(test_info["data"]),
                     headers=json.loads(test_info["headers"]))
        try:
            expected = json.loads(test_info["expected"])
            self.assertTrue(expected["code"] == resp["code"])
            self.assertTrue(expected["msg"] == resp["msg"])

            if resp["code"] == 0:
                sql = "select * from loan where member_id = {}".format(self.member_id)
                after_loan = self.db.query(sql, one=False)
                self.assertTrue(len(self.before_loan) + 1 == len(after_loan))
            logger.info("第{}条测试用例通过".format(test_info["case_id"]))

        except Exception as e:
            logger.error("请求不是json格式")
            raise e
예제 #11
0
    def test_register(self, test_info):
        if "#phone#" in test_info["data"]:
            test_info["data"] = (test_info["data"]).replace(
                "#phone#", self.phone)

        data = json.loads(test_info["data"])
        url = Handler().host + test_info["url"]
        resp = visit(test_info["method"],
                     url,
                     json=json.loads(test_info["data"]),
                     headers=json.loads(test_info["headers"]))
        try:
            for key, value in json.loads(test_info["expected"]).items():
                self.assertEqual(resp[key], value)
            if resp["code"] == 0:
                sql = "select * from member where mobile_phone = {};".format(
                    data["mobile_phone"])
                phone_data = MySqlHandlerWare().query(sql)
                self.assertTrue(phone_data)
            logger.info("第{}条测试用例通过".format(test_info["case_id"]))

        except Exception as e:
            print(f"返回的数据不是json格式:{e}")
            raise e
예제 #12
0
from middlerware.handler import Handler
예제 #13
0
from middlerware.handler import Handler
예제 #14
0
from middlerware.handler import Handler, replace_data, MySqlHandlerWare
예제 #15
0
from middlerware.handler import Handler, replace_data
예제 #16
0
from middlerware.handler import Handler, replace_data
예제 #17
0
from middlerware.handler import Handler
예제 #18
0
from middlerware.handler import Handler
예제 #19
0
from middlerware.handler import Handler,replace_data
예제 #20
0
from middlerware.handler import Handler
예제 #21
0
from middlerware.handler import Handler, MySqlHandlerWare, replace_data