Ejemplo n.º 1
0
class TestLogin(unittest.TestCase):
    oe = operation_excel.OperationExcel(EXCEL_DIR, sheet_name="login")
    test_data = oe.get_data()
    do_context = OperationContext()

    @classmethod
    def setUpClass(cls) -> None:
        log.info("{:-^50}".format("登录模块测试用例开始执行"))

    @classmethod
    def tearDownClass(cls) -> None:
        log.info("{:-^50}".format("登录模块测试用例结束执行"))

    @data(*test_data)
    def test_login(self, data):
        url = do_conifg.get_value(section="API", option="url")+data["url"]
        expect = data["expected"]
        form_data = self.do_context.login_parameterization(data["data"])
        log.info(form_data)
        actual = do_request.send_request(method=data["method"], url=url,
                                      data=form_data).text
        log.info(f"请求地址:{url}\n请求参数:{form_data}\n逾期结果:{expect}\n实际结果:{actual}")
        try:
            self.assertEqual(expect, actual)
            log.info("用例执行通过\n")
            self.oe.write_data(row=data["case_id"]+1, actual=actual, result="PASS")
        except Exception as e:
            log.error(f"用例执行失败{e}\n")
            self.oe.write_data(row=data["case_id"]+1, actual=actual, result="FAIL")
            raise e
Ejemplo n.º 2
0
class Register(unittest.TestCase):
    oe = operation_excel.OperationExcel(EXCEL_DIR, sheet_name="register")
    test_data = oe.get_data()
    do_context = OperationContext()
    @staticmethod
    def register(data):
        url = "https://www.jb51.net/article/164055.htm"
        res = do_request.send_request(method="post", url=url, data=data)
        # if res.status_code == 200:
        # if json.loads(res.text["code"]) == "10001" and json.loads(res.text["status"] == 1):
        #     return "注册成功"
        # elif json.loads(res.text["code"]) == "20110" and json.loads(res.text["status"] == 0):
        #     return "手机号码已被注册"
        return res

    def pay(self, data):
        res = self.register(data)
        if json.loads(res)["code"] == "10001" and json.loads(res)["status"] == 1:
            return "注册成功"
        elif json.loads(res.text["code"]) == "20110" and json.loads(res.text["status"] == 0):
            return "手机号码已被注册"


    @data(*test_data)
    def test_register(self, data):
        re = Register()
        form_data = self.do_context.register_parameterization(data["data"])
        status = re.pay(form_data)
        re.register = Mock(return_value='{"status":1,"code":"10001","data":null,"msg":"注册成功"}')

        self.assertEqual(status, "注册成功")
Ejemplo n.º 3
0
class TestRecharge(unittest.TestCase):
    oe = operation_excel.OperationExcel(EXCEL_DIR, sheet_name="recharge")
    test_data = oe.get_data()
    do_context = OperationContext()
    do_sql = OperationMysql()

    @classmethod
    def setUpClass(cls) -> None:
        log.info("{:-^50}".format("充值模块测试用例开始执行"))

    @classmethod
    def tearDownClass(cls) -> None:
        log.info("{:-^50}".format("充值模块测试用例结束执行"))

    @data(*test_data)
    def test_recharge(self, data):
        url = do_conifg.get_value(section="API", option="url") + data["url"]
        expect = data["expected"]
        check_sql = data["check_sql"]
        if check_sql:
            check_sql = self.do_context.recharge_parameterization(check_sql)
            mysql_data = self.do_sql.get_value(sql=check_sql)
            amount_before = round(float(mysql_data["LeaveAmount"]), 2)
        form_data = self.do_context.recharge_parameterization(data["data"])
        res = do_request.send_request(method=data["method"],
                                      url=url,
                                      data=form_data)
        if res.status_code == 200:
            actual = int(res.json()["code"])
            log.info(
                f"请求地址:{url}\n请求参数:{form_data}\n预期结果:{expect}\n实际结果:{actual}")
            try:
                self.assertEqual(expect, actual)
                if check_sql:
                    mysql_data = self.do_sql.get_value(sql=check_sql)
                    amount_after = round(float(mysql_data["LeaveAmount"]), 2)
                    recharge_amount = json.loads(data["data"])["amount"]
                    expect_amount = amount_before + recharge_amount
                    self.assertEqual(expect_amount,
                                     amount_after,
                                     msg="充值金额不一致")
                    log.info(f"预期金额:{expect_amount}实际金额:{amount_after}")
                log.info("用例执行通过\n")
                self.oe.write_data(row=data["case_id"] + 1,
                                   actual=actual,
                                   result="PASS")
            except Exception as e:
                log.error(f"用例执行失败{e}\n")
                self.oe.write_data(row=data["case_id"] + 1,
                                   actual=actual,
                                   result="FAIL")
                raise e
Ejemplo n.º 4
0
class TestRegister(unittest.TestCase):
    oe = operation_excel.OperationExcel(EXCEL_DIR, sheet_name="userRegister")
    test_data = oe.get_data()
    do_context = OperationContext()
    do_sql = OperationMysql()

    @classmethod
    def setUpClass(cls) -> None:
        log.info("{:-^50}".format("注册模块测试用例开始执行"))

    @classmethod
    def tearDownClass(cls) -> None:
        log.info("{:-^50}".format("注册模块测试用例结束执行"))

    @data(*test_data)
    def test_register(self, data):
        url = do_conifg.get_value(section="API", option="url1") + data["url"]
        expect = data["expected"]

        data = json.dumps(data)
        form_data = self.do_context.register_parameterization(data)
        data = json.loads(form_data)
        check_sql = data["check_sql"]
        form_data = json.loads(form_data)
        actual = do_request.send_request(url=url,
                                         method=data["method"],
                                         data=json.loads(form_data["data"]))
        actual = dict(actual)
        actual = str(actual["retInfo"])
        if check_sql:
            # OperationContext.mobile = str(form_data["mobile"])
            # check_sql = self.do_context.register_parameterization(check_sql)
            mysql_data = self.do_sql.get_value(sql=check_sql)
            OperationContext.verify_code = str(mysql_data["fverify_code"])
            OperationContext.send_code_phone = json.loads(
                form_data["data"])["mobile"]
            print(json.loads(form_data["data"])["mobile"])

        log.info(f"请求地址:{url}\n请求参数:{data}\n逾期结果:{expect}\n实际结果:{actual}")
        try:
            self.assertEqual(expect, actual)
            log.info("用例执行通过\n")
            self.oe.write_data(row=data["case_id"] + 1,
                               actual=actual,
                               result="PASS")
        except Exception as e:
            log.error(f"用例执行失败{e}\n")
            self.oe.write_data(row=data["case_id"] + 1,
                               actual=actual,
                               result="FAIL")
            raise e
Ejemplo n.º 5
0
class TestInvest(unittest.TestCase):
    oe = operation_excel.OperationExcel(EXCEL_DIR, sheet_name="invest")
    test_data = oe.get_data()
    do_context = OperationContext()
    do_sql = OperationMysql()

    @classmethod
    def setUpClass(cls) -> None:
        log.info("{:-^50}".format("投资接口测试用例开始执行"))

    @classmethod
    def tearDownClass(cls) -> None:
        log.info("{:-^50}".format("投资接口测试用例结束执行"))

    @data(*test_data)
    def test_recharge(self, data):
        url = do_conifg.get_value(section="API", option="url")+data["url"]
        expect = data["expected"]
        check_sql = data["check_sql"]
        form_data = self.do_context.invest_parameterization(data["data"])
        res = do_request.send_request(method=data["method"], url=url,
                                      data=form_data)
        if check_sql:
            if "加标成功" in res.text:
                check_sql = self.do_context.invest_parameterization(check_sql)
                mysql_data = self.do_sql.get_value(sql=check_sql)
                OperationContext.loan_id = str(mysql_data["Id"])
            else:
                pass
        log.info(res.text)
        if res.status_code == 200:
            actual = int(res.json()["code"])
            log.info(f"请求地址:{url}\n请求参数:{form_data}\n预期结果:{expect}\n实际结果:{actual}")
            try:
                self.assertEqual(expect, actual)
                log.info("用例执行通过\n")
                self.oe.write_data(row=data["case_id"]+1, actual=actual, result="PASS")
            except Exception as e:
                log.error(f"用例执行失败{e}\n")
                self.oe.write_data(row=data["case_id"]+1, actual=actual, result="FAIL")
                raise e