def test_审核项目配置(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            caseData = caseInfo["data"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName

        ids = {"id": self.config_number,
               "riskStrategy": confParam("riskStrategy"),
               "riskStrategyName": confParam("riskStrategyName"),
               }

        #  用例中值替换为变量
        data = eval(findAndReplace(str(caseData), ids))

        # 发送请求
        response = requests.post(self.url, headers=self.headers, data=json.dumps(data))

        # 接口返回信息
        text = response.text

        self.log.info("#" * 100 + "开始测试" + "#" * 100)
        self.log.info("用例名字:{}".format(caseName))
        self.log.info("请求参数:{}".format(data))
        self.log.info("-" * 200)
        self.log.info("期望结果:{}, 实际结果:{}".format(check, text))
        self.log.info("#" * 100 + "测试结束" + "#" * 100)

        # 断言
        self.assertIn(check, text)
Ejemplo n.º 2
0
    def setUpClass(cls):

        # log 实例化
        cls.log = Log()

        # 获取创建项目名字
        projectName = "审核拒绝项目测试"
        url = confParam("hostName") + "/api/assets/v2/project-config"
        cls.asset_headers = {
            "Content-Type": "application/json;charset=UTF-8",
            "Authorization": read_token()["assertToken"]
        }
        data = {
            "assetKind": "CREDIT",
            "projectName": projectName,
            "projectType": "PRO_CONSUMPTION"
        }
        response = requests.post(url,
                                 headers=cls.asset_headers,
                                 data=json.dumps(data))

        # 数据库实例化
        db = dataBase()

        cls.config_number = db.configId("id", "loan_project_config",
                                        "project_name", projectName)
        cls.url = confParam(
            "hostName") + "/api/center/v2/project-config/_audit-failure"
        cls.headers = {
            "Content-Type": "application/json;charset=UTF-8",
            "Authorization": read_token()["centerToken"]
        }
Ejemplo n.º 3
0
    def setUpClass(cls):

        # 拼接接口地址
        cls.url = confParam("hostName") + cls.uri
        cls.client = sendRequest()

        dbName = confParam("车辆管理")
        db = dataBase(dbName)
        cls.car_model_id = db.getId("car_model_id", "t_info_car_model", "brand_name", "比亚迪OFO")

        # 请求信息头
        cls.headers = {"Cookie": read_token()["cookie"], "Content-Type": "application/json;charset=UTF-8"}
Ejemplo n.º 4
0
 def __init__(self):
     self.host = confParam("host")
     self.user = confParam("user")
     self.password = confParam("password")
     self.db = confParam("db")
     self.con = pymysql.connect(host=self.host,
                                user=self.user,
                                password=self.password,
                                db=self.db,
                                port=3306,
                                charset="utf8")
     self.cur = self.con.cursor()
    def setUpClass(cls):

        # log 实例化
        cls.log = Log()

        # 获取创建项目名字
        projectName = confParam("projectName")

        # 数据库实例化
        db = dataBase()

        cls.config_number = db.configId("id", "loan_project_config", "project_name", projectName)
        cls.url = confParam("hostName") + "/api/center/v2/project-config/_audit-success"
        cls.headers = {"Content-Type": "application/json;charset=UTF-8", "Authorization": read_token()["centerToken"]}
Ejemplo n.º 6
0
    def setUpClass(cls):

        # log 实例化
        cls.log = Log()

        cls.url = confParam("hostName") + "/api/assets/v2/project-config"
        cls.headers = {"Content-Type": "application/json;charset=UTF-8", "Authorization": read_token()["assertToken"]}
Ejemplo n.º 7
0
    def test_创建项目配置(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            caseData = caseInfo["data"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName

        config_dict = {"projectName": confParam("projectName")}

        #  用例中值替换为变量
        data = eval(findAndReplace(str(caseData), config_dict))

        # 发送请求
        response = requests.post(self.url, headers=self.headers, data=json.dumps(data))
        text = response.text  # 接口返回信息

        self.log.info("#" * 100 + "开始测试" + "#" * 100)
        self.log.info("用例名字:{}".format(caseName))
        self.log.info("请求参数:{}".format(data))
        self.log.info("-" * 200)
        self.log.info("期望结果:{}, 实际结果:{}".format(check, text))
        self.log.info("#" * 100 + "测试结束" + "#" * 100)

        # 断言
        self.assertIn(check, text)
Ejemplo n.º 8
0
    def test_登录(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            account = caseInfo["account"]
            password = caseInfo["password"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName

        driver = self.driver
        url = confParam("url")
        login_Page = LoginPage(driver, url)

        # 打开首页
        login_Page.open_home_page()
        # 输入账号
        login_Page.input_userName(account)
        # 输入密码
        login_Page.input_passwd(password)

        # 点击登录
        login_Page.click_login_btn()

        # 断言
        time.sleep(1)
        getScreen(self.driver, caseName, "login")
        self.assertIn(check, self.driver.page_source)
        # 写日志文件
        case_info = {
            "用例名字: ": caseName,
            "登录账号:": account,
            "密码: ": password,
            "断言:": check
        }
        writeLog(case_info)
    def setUpClass(cls):

        cls.url = confParam("hostName") + cls.uri
        cls.client = sendRequest()
        cls.headers = {
            "Cookie": read_token()["cookie"],
            "Content-Type": "application/json;charset=UTF-8"
        }
class test_登录(unittest.TestCase):
    yaml_path = os.path.join(root_dir, "yamlCase", "登录", "1登录_5719正常登录.yaml")
    oper_yaml = operYaml(yaml_path)
    case_list = oper_yaml.caseList()

    method = case_list[0]["method"]
    uri = case_list[1]["uri"]

    # 跳过说明
    reason = confParam("skip_reason")

    @classmethod
    def setUpClass(cls):

        # 声明dict变量存储token
        cls.token_dict = {}

        # 拼接接口地址
        cls.url = confParam("hostName") + cls.uri
        cls.client = sendRequest()

        # 请求信息头
        cls.headers = {"Content-Type": "application/json;charset=UTF-8"}

    # case_list传进去做数据驱动
    @data(*case_list[2:])
    def test_登录(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            data = caseInfo["data"]
            check = caseInfo["check"]
            self.__dict__['_testMethodDoc'] = caseName

        # 发送请求
        response = self.client.sendRequest(self.method, self.url, self.headers, data)

        # 接口返回文本信息
        text = response.text

        # 把文本信息转化为字典格式
        text_dict = json.loads(text)

        # 判断接口响应code是否为200,获取cookie
        if text_dict["code"] == 200:
            self.token_dict["cookie"] = response.headers['Set-Cookie'].split(";")[0]

        # 写日志
        writeLog(caseName, self.url, data, check, text)

        # 断言
        Check().check(check, text_dict)

    @classmethod
    def tearDownClass(cls):

        # 把cookie写入文件
        write_file(json.dumps(cls.token_dict))
Ejemplo n.º 11
0
class test_修改车型(unittest.TestCase):
    yaml_path = os.path.join(root_dir, "yamlCase", "车辆管理", "3修改车型_6383修改车型.yaml")
    oper_yaml = operYaml(yaml_path)
    case_list = oper_yaml.caseList()

    method = case_list[0]["method"]
    uri = case_list[1]["uri"]

    # 跳过说明
    reason = confParam("skip_reason")

    @classmethod
    def setUpClass(cls):

        # 拼接接口地址
        cls.url = confParam("hostName") + cls.uri
        cls.client = sendRequest()

        dbName = confParam("车辆管理")
        db = dataBase(dbName)
        cls.car_model_id = db.getId("car_model_id", "t_info_car_model", "brand_name", "比亚迪OFO")

        # 请求信息头
        cls.headers = {"Cookie": read_token()["cookie"], "Content-Type": "application/json;charset=UTF-8"}

    # case_list传进去做数据驱动
    @data(*case_list[2:])
    def test_修改车型(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            data = caseInfo["data"]
            check = caseInfo["check"]
            self.__dict__['_testMethodDoc'] = caseName

        ids = {"carModelId": self.car_model_id}

        #  用例中值替换为变量
        data = eval(findAndReplace(str(data), ids))

        # 发送请求
        response = self.client.sendRequest(self.method, self.url, self.headers, data)

        # 接口返回文本信息
        text = response.text

        # 把文本信息转化为字典格式
        text_dict = json.loads(text)

        # 写日志
        writeLog(caseName, self.url, data, check, text_dict)

        # 断言
        Check().check(check, text_dict)

    @classmethod
    def tearDownClass(cls):
        pass
Ejemplo n.º 12
0
class test_新增车型(unittest.TestCase):
    yaml_path = os.path.join(root_dir, "yamlCase", "车辆管理",
                             "1新增车型_6387新增车型.yaml")
    oper_yaml = operYaml(yaml_path)
    case_list = oper_yaml.caseList()

    method = case_list[0]["method"]
    uri = case_list[1]["uri"]

    # 跳过说明
    reason = confParam("skip_reason")

    @classmethod
    def setUpClass(cls):

        # 拼接接口地址
        cls.url = confParam("hostName") + cls.uri
        cls.client = sendRequest()

        # 请求信息头
        cls.headers = {
            "Cookie": read_token()["cookie"],
            "Content-Type": "application/json;charset=UTF-8"
        }

    # case_list传进去做数据驱动
    @data(*case_list[2:])
    def test_新增车型(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            data = caseInfo["data"]
            check = caseInfo["check"]
            self.__dict__['_testMethodDoc'] = caseName

        # 发送请求
        response = self.client.sendRequest(self.method, self.url, self.headers,
                                           data)

        # 接口返回文本信息
        text = response.text

        # 把文本信息转化为字典格式
        text_dict = json.loads(text)

        # 写日志
        writeLog(caseName, self.url, data, check, text_dict)

        # 断言
        Check().check(check, text_dict)

    @classmethod
    def tearDownClass(cls):
        pass
    def setUpClass(cls):

        # 声明dict变量存储token
        cls.token_dict = {}

        # 拼接接口地址
        cls.url = confParam("hostName") + cls.uri
        cls.client = sendRequest()

        # 请求信息头
        cls.headers = {"Content-Type": "application/json;charset=UTF-8"}
class test_创建项目配置(unittest.TestCase):
    yaml_path = os.path.join(root_dir, "yamlCase", "创建项目配置.yaml")
    oper_yaml = operYaml(yaml_path)
    case_list = oper_yaml.caseList()

    # 跳过说明
    reason = confParam("skip_reason")

    @classmethod
    def setUpClass(cls):

        # log 实例化
        cls.log = Log()

        cls.url = confParam("hostName") + "/api/assets/v2/project-config"
        cls.headers = {
            "Content-Type": "application/json;charset=UTF-8",
            "Authorization": read_token()["assertToken"]
        }

    # case_list传进去做数据驱动
    @ddt.data(*case_list)
    def test_创建项目配置(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            caseData = caseInfo["data"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName

        config_dict = {"projectName": confParam("projectName")}

        #  用例中值替换为变量
        data = eval(findAndReplace(str(caseData), config_dict))

        # 发送请求
        response = requests.post(self.url,
                                 headers=self.headers,
                                 data=json.dumps(data))
        text = response.text  # 接口返回信息

        self.log.info("#" * 100 + "开始测试" + "#" * 100)
        self.log.info("用例名字:{}".format(caseName))
        self.log.info("请求参数:{}".format(data))
        self.log.info("-" * 200)
        self.log.info("期望结果:{}, 实际结果:{}".format(check, text))
        self.log.info("#" * 100 + "测试结束" + "#" * 100)

        # 断言
        self.assertIn(check, text)

    @classmethod
    def tearDownClass(cls):
        pass
    def test_审核项目配置(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            caseData = caseInfo["data"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName

        ids = {
            "id": self.config_number,
            "riskStrategy": confParam("riskStrategy"),
            "riskStrategyName": confParam("riskStrategyName"),
            "riskStrategyVersion": confParam("riskStrategyVersion"),
            "riskStrategyVersionName": confParam("riskStrategyVersionName")
        }

        data = caseData

        # 用例中值替换为变量
        for key in data.keys():
            if data[key] in list(ids.keys()):
                data[key] = ids[data[key]]

        # 发送请求
        response = requests.post(self.url,
                                 headers=self.headers,
                                 data=json.dumps(data))

        # 接口返回信息
        text = response.text

        self.log.info("#" * 100 + "开始测试" + "#" * 100)
        self.log.info("用例名字:{}".format(caseName))
        self.log.info("请求参数:{}".format(data))
        self.log.info("-" * 200)
        self.log.info("期望结果:{}, 实际结果:{}".format(check, text))
        self.log.info("#" * 100 + "测试结束" + "#" * 100)

        # 断言
        self.assertIn(check, text)
Ejemplo n.º 16
0
    def setUpClass(cls):

        # log实例化
        cls.log = Log()

        # 声明dict变量存储token
        cls.token_dict = {}

        # 拼接接口地址
        cls.url = confParam("loginUrl") + "/gateway/foundation-user/login/email"

        # 请求信息头
        cls.headers = {"Content-Type": "application/json;charset=UTF-8"}
Ejemplo n.º 17
0
class test_提款(unittest.TestCase):
    yamlPath = ['提款', '提款.yaml']
    yaml_path = os.path.join(root_dir, "yamlCase")
    for dir in yamlPath:
        yaml_path = os.path.join(yaml_path, dir)
    oper_yaml = operYaml(yaml_path)
    case_list, method, uri = oper_yaml.caseList()

    # 跳过说明
    reason = confParam("skip_reason")

    @classmethod
    def setUpClass(cls):

        # 拼接接口地址
        cls.url = confParam("hostName") + cls.uri
        cls.client = sendRequest()

        # 请求信息头
        # cls.headers = {"Cookie": read_token()["cookie"], "Content-Type": "application/json;charset=UTF-8"}

    # case_list传进去做数据驱动
    @data(*case_list)
    def test_提款(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            data = caseInfo["data"]
            check = caseInfo["check"]
            self.__dict__['_testMethodDoc'] = caseName

        # 发送请求
        response = self.client.sendRequest(self.method, self.url, data)

        # 接口返回文本信息
        text = response.text

        # 把文本信息字符串格式转化为字典格式
        text_dict = json.loads(text)

        # 写日志
        writeLog(caseName, self.url, data, check, text_dict)

        # 断言
        Check().check(check, text_dict)

    @classmethod
    def tearDownClass(cls):
        pass
Ejemplo n.º 18
0
def login(driver,
          url=confParam("url"),
          account=confParam("account"),
          password=confParam("password")):
    # 打开登录页
    driver.get(url)

    # 获取账户输入框
    account_input = ele.getElement(driver, 'login', 'account')

    # 获取密码输入框
    passwd_input = ele.getElement(driver, 'login', 'password')

    # 获取登录按钮
    login_button = ele.getElement(driver, 'login', 'loginButton')

    # 输入用户名
    account_input.send_keys(account)

    # 输入密码
    passwd_input.send_keys(password)

    # 点击登录
    login_button.click()
Ejemplo n.º 19
0
    def test_login(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            email = caseInfo["email"]
            passwd = caseInfo["password"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName
            if "token" in caseInfo.keys():
                token = caseInfo["token"]

        # 拼装请求参数
        loginData = {
            "email": email,
            "password": passwd,
            "appId": confParam("appId")
        }

        # 发送请求
        response = requests.post(self.url,
                                 headers=self.headers,
                                 data=json.dumps(loginData))

        # 接口返回文本信息
        text = response.text

        # 把文本信息转化为字典格式
        text_dict = json.loads(text)

        # 判断接口响应code是否为200,获取token
        if text_dict["code"] == str(200):
            self.token_dict[token] = text_dict["body"]["token"]

        self.log.info("#" * 100 + "开始测试" + "#" * 100)
        self.log.info("用例名字:{}".format(caseName))
        self.log.info("请求参数:{}".format(loginData))
        self.log.info("-" * 200)
        self.log.info("期望结果:{}, 实际结果:{}".format(check, text))
        self.log.info("#" * 100 + "测试结束" + "#" * 100)

        # 断言
        self.assertIn(check, text)
Ejemplo n.º 20
0
def run():
    test_dir = os.path.join(root_dir, "cases")
    reportPath = os.path.join(root_dir, "report")

    dbName = confParam('db')
    db = dataBase(dbName)
    db.update_power("t_user_power", 12805)
    db.update_money("t_user_money", 12805)
    db.delete_money_list("t_user_status", 12805)
    db.closeDb()

    discover = unittest.defaultTestLoader.discover(test_dir, pattern='test_*.py', top_level_dir=None)
    print(discover)
    now = time.strftime("%Y-%m-%d_%H_%M_%S")
    reportName = now + '测试报告.html'
    description = "python接口自动化测试报告"
    BeautifulReport(discover).report(filename=reportName, description=description, report_dir=reportPath)
    print(discover)


    # 发送邮件(用脚本发邮件,已改成jenkins构建自动发邮件)
    #sendEmail.email(report)

    # tomcat目录从.jenkins目录获取测试报告(windows下拉取测试报告,linux直接用命令拉取)
    #getNewReport.getReport()

    # 读测试报告中的参数,写入邮件模板中
    report = os.path.join(reportPath, reportName)
    writeFile = os.path.join(root_dir, "my_props.properties")
    readReport.writeResult(report, writeFile)

    # 发送企业微信提醒
    corpid='wx8d3e67cf49434a0f'
    corpsecret='g4b6P5-QsZAdov-R4Ha7fv1RX26QSLnFEKjMCp4R3HM'
    alert = WechatAlert(corpid,corpsecret)
    alert.send_msg("接口自动化测试已完成,本次报告详情请查看:http://10.0.0.239:8080/examples/report/report.html")
Ejemplo n.º 21
0
class test_审核项目配置(unittest.TestCase):
    yaml_path = os.path.join(root_dir, "yamlCase", "审核拒绝项目配置.yaml")
    oper_yaml = operYaml(yaml_path)
    case_list = oper_yaml.caseList()

    # 跳过说明
    reason = confParam("skip_reason")

    @classmethod
    def setUpClass(cls):

        # log 实例化
        cls.log = Log()

        # 获取创建项目名字
        projectName = "审核拒绝项目测试"
        url = confParam("hostName") + "/api/assets/v2/project-config"
        cls.asset_headers = {
            "Content-Type": "application/json;charset=UTF-8",
            "Authorization": read_token()["assertToken"]
        }
        data = {
            "assetKind": "CREDIT",
            "projectName": projectName,
            "projectType": "PRO_CONSUMPTION"
        }
        response = requests.post(url,
                                 headers=cls.asset_headers,
                                 data=json.dumps(data))

        # 数据库实例化
        db = dataBase()

        cls.config_number = db.configId("id", "loan_project_config",
                                        "project_name", projectName)
        cls.url = confParam(
            "hostName") + "/api/center/v2/project-config/_audit-failure"
        cls.headers = {
            "Content-Type": "application/json;charset=UTF-8",
            "Authorization": read_token()["centerToken"]
        }

    # case_list传进去做数据驱动
    @ddt.data(*case_list)
    def test_审核拒绝项目配置(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            caseData = caseInfo["data"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName

        ids = {"id": self.config_number}

        #  用例中值替换为变量
        data = eval(findAndReplace(str(caseData), ids))

        # 发送请求
        response = requests.post(self.url,
                                 headers=self.headers,
                                 data=json.dumps(data))

        # 接口返回信息
        text = response.text

        self.log.info("#" * 100 + "开始测试" + "#" * 100)
        self.log.info("用例名字:{}".format(caseName))
        self.log.info("请求参数:{}".format(data))
        self.log.info("-" * 200)
        self.log.info("期望结果:{}, 实际结果:{}".format(check, text))
        self.log.info("#" * 100 + "测试结束" + "#" * 100)

        # 断言
        self.assertIn(check, text)

    @classmethod
    def tearDownClass(cls):
        # 删除项目配置
        url = confParam(
            "hostName"
        ) + "/api/assets/v2/project-config/%s" % cls.config_number
        response = requests.delete(url, headers=cls.asset_headers)
Ejemplo n.º 22
0
    def open_home_page(self):
        # 进入home页
        login(self.driver)

        time.sleep(2)
        # 刷新页面
        self.driver.refresh()

        # 定位展开侧边元素
        expand_sidebar = self.ele.getElement(self.driver, 'home', 'expandSidebar')

        # 点击展开侧边
        expand_sidebar.click()

        # 获取价格设置
        self.price_manger_btn = self.ele.getElement(self.driver, 'home', 'priceManger')

    def click_price_manger_btn(self):
        # 点击价格设置
        self.click(self.price_manger_btn)


if __name__ == "__main__":
    driver = webdriver.Chrome()
    url = confParam("url")
    login_Page = homePage(driver, url)
    login_Page.open_home_page()
    login_Page.click_price_manger_btn()


Ejemplo n.º 23
0
 def setUpClass(cls):
     cls.driver = webdriver.Chrome()
     cls.url = confParam("url")
     cls.home_Page = homePage(cls.driver, cls.url)
     cls.home_Page.open_home_page()
Ejemplo n.º 24
0
                res = requests.put(url)
            return res

        elif method.lower() == "delete":
            '''
                    封装delete方法,uri是访问路由,params是delete请求需要传递的参数,如果没有参数这里为空
                    :param uri: 访问路由
                    :param params: 传递参数,string类型,默认为None
                    :return: 此次访问的response
                    '''
            if params is not None:
                # 如果有参数,那么通过put方式访问对应的url,并将参数赋值给requests.put默认参数data
                # 返回request的Response结果,类型为requests的Response类型
                res = requests.delete(url, hearders=headers, data=params)
            else:
                # 如果无参数,访问方式如下
                # 返回request的Response结果,类型为requests的Response类型
                res = requests.put(url, hearders=headers)
            return res
        else:
            print("无效的请求方式,get/post/put/delete,请查找原因!!!")


if __name__ == "__main__":
    url = confParam("hostName") + "/travel/admin/authenticate/login"
    client = sendRequest()
    headers = {"Content-Type": "application/json;charset=UTF-8"}
    params = {"account": "18042477732", "userPwd": "admin123!@#$"}
    response = client.sendRequest("post", url, headers, params)
    print(response.text)
Ejemplo n.º 25
0
class test_登录(unittest.TestCase):
    yaml_path = os.path.join(root_dir, "yamlCase", "登录.yaml")
    oper_yaml = operYaml(yaml_path)
    case_list = oper_yaml.caseList()

    # 跳过说明
    reason = confParam("skip_reason")

    @classmethod
    def setUpClass(cls):

        # log实例化
        cls.log = Log()

        # 声明dict变量存储token
        cls.token_dict = {}

        # 拼接接口地址
        cls.url = confParam("loginUrl") + "/gateway/foundation-user/login/email"

        # 请求信息头
        cls.headers = {"Content-Type": "application/json;charset=UTF-8"}

    # case_list传进去做数据驱动
    @data(*case_list)
    def test_登录(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            email = caseInfo["email"]
            passwd = caseInfo["password"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName
            if "token" in caseInfo.keys():
                token = caseInfo["token"]

        # 拼装请求参数
        loginData = {"email": email, "password": passwd, "appId": confParam("appId")}

        # 发送请求
        response = requests.post(self.url, headers=self.headers, data=json.dumps(loginData))

        # 接口返回文本信息
        text = response.text

        # 把文本信息转化为字典格式
        text_dict = json.loads(text)

        # 判断接口响应code是否为200,获取token
        if text_dict["code"] == str(200):
            self.token_dict[token] = text_dict["body"]["token"]

        self.log.info("#"*100 + "开始测试" + "#"*100)
        self.log.info("用例名字:{}".format(caseName))
        self.log.info("请求参数:{}".format(loginData))
        self.log.info("-" * 200)
        self.log.info("期望结果:{}, 实际结果:{}".format(check, text))
        self.log.info("#"*100 + "测试结束" + "#"*100)

        # 断言
        self.assertIn(check, text)

    @classmethod
    def tearDownClass(cls):

        # 把token写入文件
        write_file(json.dumps(cls.token_dict))
class test_审核项目配置(unittest.TestCase):
    yaml_path = os.path.join(root_dir, "yaml", "审核项目配置.yaml")
    oper_yaml = operYaml(yaml_path)
    case_list = oper_yaml.caseList()

    # 跳过说明
    reason = confParam("skip_reason")

    @classmethod
    def setUpClass(cls):

        # log 实例化
        cls.log = Log()

        # 获取创建项目名字
        projectName = confParam("projectName")

        # 数据库实例化
        db = dataBase()

        cls.config_number = db.configId("id", "loan_project_config",
                                        "project_name", projectName)
        cls.url = confParam(
            "hostName") + "/api/center/v2/project-config/_audit-success"
        cls.headers = {
            "Content-Type": "application/json;charset=UTF-8",
            "Authorization": read_token()["centerToken"]
        }

    # case_list传进去做数据驱动
    @ddt.data(*case_list)
    def test_审核项目配置(self, cases):

        for caseName, caseInfo in cases.items():
            caseName = caseName
            caseData = caseInfo["data"]
            check = caseInfo["assert"]
            self.__dict__['_testMethodDoc'] = caseName

        ids = {
            "id": self.config_number,
            "riskStrategy": confParam("riskStrategy"),
            "riskStrategyName": confParam("riskStrategyName"),
            "riskStrategyVersion": confParam("riskStrategyVersion"),
            "riskStrategyVersionName": confParam("riskStrategyVersionName")
        }

        data = caseData

        # 用例中值替换为变量
        for key in data.keys():
            if data[key] in list(ids.keys()):
                data[key] = ids[data[key]]

        # 发送请求
        response = requests.post(self.url,
                                 headers=self.headers,
                                 data=json.dumps(data))

        # 接口返回信息
        text = response.text

        self.log.info("#" * 100 + "开始测试" + "#" * 100)
        self.log.info("用例名字:{}".format(caseName))
        self.log.info("请求参数:{}".format(data))
        self.log.info("-" * 200)
        self.log.info("期望结果:{}, 实际结果:{}".format(check, text))
        self.log.info("#" * 100 + "测试结束" + "#" * 100)

        # 断言
        self.assertIn(check, text)

    @classmethod
    def tearDownClass(cls):
        pass
Ejemplo n.º 27
0
 def tearDownClass(cls):
     # 删除项目配置
     url = confParam(
         "hostName"
     ) + "/api/assets/v2/project-config/%s" % cls.config_number
     response = requests.delete(url, headers=cls.asset_headers)
Ejemplo n.º 28
0
                                                      key)
        self.cur.execute(sql)
        self.con.commit()

    def delete_role_id(self, role_name):
        role_id = self.getId("role_id", "t_auth_role", "role_name", role_name)
        self.delete("t_auth_data_auth_role", "role_id", role_id)
        self.delete("t_auth_permission_role", "role_id", role_id)
        self.delete("t_auth_role", "role_id", role_id)

    def delete_carModel_carId(self):
        self.delete("t_info_car_model", "brand_name", "比亚迪OFO")
        self.delete("t_info_car_brand", "brand_name", "比亚迪OFO")
        self.delete("t_info_car_basic", "car_no", "豫G123G67G")

    def delete_user(self, user_name):
        self.delete("t_basic_sys_user", "user_name", user_name)

    def getSumAmount(self, sql):
        self.cur.execute(sql)
        return self.cur.fetchall()[0][0]

    def closeDb(self):
        self.cur.close()
        self.con.close()


if __name__ == "__main__":
    dbName = confParam("车辆管理")
    db = dataBase(dbName)
Ejemplo n.º 29
0
    def setUpClass(cls):

        # 拼接接口地址
        cls.url = confParam("hostName") + cls.uri
        cls.client = sendRequest()
Ejemplo n.º 30
0
    # def delete_role_id(self, role_name):
    #     role_id = self.getId("role_id", "t_auth_role", "role_name", role_name)
    #     self.delete("t_auth_data_auth_role", "role_id", role_id)
    #     self.delete("t_auth_permission_role", "role_id", role_id)
    #     self.delete("t_auth_role", "role_id", role_id)
    #
    # def delete_carModel_carId(self):
    #     self.delete("t_info_car_model", "brand_name", "比亚迪OFO")
    #     self.delete("t_info_car_brand", "brand_name", "比亚迪OFO")
    #     self.delete("t_info_car_basic", "car_no", "豫G123G67G")
    #
    # def delete_user(self, user_name):
    #     self.delete("t_basic_sys_user", "user_name", user_name)
    #
    # def getSumAmount(self, sql):
    #     self.cur.execute(sql)
    #     return self.cur.fetchall()[0][0]

    def closeDb(self):
        self.cur.close()
        self.con.close()


if __name__ == "__main__":
    dbName = confParam('db')
    db = dataBase(dbName)
    db.update_power("t_user_power", 12805)
    db.update_money("t_user_money", 12805)
    db.delete_money_list("t_user_status", 12805)
    db.closeDb()