Пример #1
0
 def gettoken(self,corpsecret):
     data = {
         "params":{"corpid":corpid,"corpsecret":corpsecret},
         }
     r = self.send(method=config_read(section="wwork",option="method"),url=config_read(section="wwork",option="url"),kwargs=data)
     ACCESS_TOKEN = r.json()['access_token']
     logger.debug(f"获取token: {ACCESS_TOKEN}")
     return ACCESS_TOKEN
Пример #2
0
 def test_getmen(self,data):
     #查询成员
     logger.info(f'测试用例名称:{data["case_name"]}----------------------------------------------')
     """
     :param data: 这里传入的数据是原始数据没有经过处理的数据,这里用来传入对应得api
     :return:
     返回接收的r是响应结果
     返回接收的expected_results是用例里面的期望结果
     返回的nrow是用例里面的对应得实际结果的行和执行结果的行,为了方便写入返回数据设置的
     返回的test_data是发送请求的数据,方便断言使用
     """
     with allure.step("将输入传入对应方法中,返回处理的数据"):
         r,expected_results,nrow,test_data = self.base.api_func(kwargs=data)
     with allure.step("获取返回的请求结果的文本信息用作断言"):
         actual_results = r.text
         logger.debug(f"返回的实际结果的文本信息:{actual_results},预期结果:{expected_results}"
                      f"输入的测试数据信息:{test_data}")
     with allure.step("进行断言,这里做了一个异常处理,如果断言出错也不会退出"):
         msg = self.base.assert_func(expected_results, actual_results, path, nrow, sheetname=config_read('case_sheet', 'search_sheet'))
Пример #3
0
    def datafun(self,**kwargs):
        #为simo准备
        #cookies=self.getcookie()
        logger.debug(f"数据处理传入的参数{kwargs}")
        expected_results = kwargs['kwargs']['kwargs']['expected_results']
        nrow = kwargs['kwargs']['kwargs']['nrow']
        method = kwargs['kwargs']['kwargs']['method']
        url = kwargs['kwargs']['kwargs']['url']
        # corpsecret = "OU7KFYJJz4KoIjVH1Df8CHwt50KwGv7fo6uTV3C8oG8"
        corpsecret = kwargs['kwargs']['kwargs']['corpsecret']
        logger.debug(f"查看token生成参数获取{corpsecret}")

        logger.debug(f"提取了预期结果、用例对应行号、url和请求方法")

        data1 = {}
        if method == 'get':
            params={"access_token":self.gettoken(corpsecret)}
            data={}
            p_d = kwargs['kwargs']['kwargs']['params']
            d_d = kwargs['kwargs']['kwargs']['data']
            if p_d is not None:
                try:
                    p_d = json.loads(p_d)
                except BaseException as err_msg:
                    logger.error(f"报错信息: {err_msg},你的测试数据格式有问题啊,快检查一下")
                for key,value in p_d.items():
                    params[key] = value
            data1['params'] = params
            if d_d is not None:
                logger.error(f"这是get请求,没有data参数: {d_d},请检查数据")
                try:
                    d_d = json.loads(d_d)
                except BaseException as err_msg:
                    logger.error(f"报错信息: {err_msg},你的测试数据格式有问题啊,快检查一下")
                for key, value in d_d.items():
                    data[key] = value
            data1['data'] = data
        else:
            data ={
                'json': kwargs['kwargs']['kwargs'],
                'params':{"access_token":self.gettoken(corpsecret)}
            }
            #将传入的参数转换成字典
            logger.debug(f'这里看下传入的数据是否有问题 {data}')
            if not data["json"]["data"] is None:
                try:
                    data1["json"] = json.loads(data["json"]["data"])
                except BaseException as err_msg:
                    logger.error(f"报错信息: {err_msg},你的测试数据格式有问题啊,快检查一下")
            else:
                logger.error("post请求中没有data数据,请检查测试用例")
                data1["json"] = None
            d_p = data["json"]["params"]
            if d_p is not None:
                try:
                    d_p = json.loads(d_p)
                except BaseException as err_msg:
                    logger.error(f"报错信息: {err_msg},你的测试数据格式有问题啊,快检查一下")
                for key,value in d_p.items():
                    data["params"][key] = value
            data1["params"] = data["params"]
        logger.debug(f"请求方法为{method},处理后的数据为{data1}")
        return data1,expected_results,nrow,method,url
Пример #4
0
 def send(self,method,url,kwargs):
     logger.debug(f"发送请求")
     r = requests.request(method,url,**kwargs)
     return r