Beispiel #1
0
 def read_yaml(self, **kwargs):
     try:
         with open(self.abs_path, encoding='UTF-8') as f:
             content = yaml.safe_load(f)
         return content
     except Exception as f:
         logger.exception('读取yaml文件报错如下:{}'.format(f))
    def send_get(self,url,data=None,header=None,cookie=None):
        try:
            logger.info('调用get接口')
            return self.session.get(url=self.api_root_url+url,params=data,headers=header,cookies=cookie)

        except Exception as e:
            logger.exception('get接口调用失败,信息如下:'.format(e))
Beispiel #3
0
 def get_value(self, keyword, **kwargs):
     try:
         content = self.read_yaml()
         value = content[keyword]
         logger.info('获取value数据')
         return value
     except Exception as f:
         logger.exception('读取yaml文件报错如下:{}'.format(f))
Beispiel #4
0
 def get_url(self, **kwargs):
     try:
         content = self.read_yaml()
         url = content["url"]
         logger.info('获取url数据')
         return url
     except Exception as f:
         logger.exception('读取yaml文件报错如下:{}'.format(f))
Beispiel #5
0
 def get_data(self, **kwargs):
     try:
         content = self.read_yaml()
         data = content["data"]
         logger.info('获取data数据')
         return data
     except Exception as f:
         logger.exception('读取yaml文件报错如下:{}'.format(f))
Beispiel #6
0
 def get_headers(self, **kwargs):
     try:
         content = self.read_yaml()
         headers = content["headers"]
         logger.info('获取headers数据')
         return headers
     except Exception as f:
         logger.exception('读取yaml文件报错如下:{}'.format(f))
Beispiel #7
0
 def get_querystring(self, **kwargs):
     try:
         content = self.read_yaml()
         querystring = content["querystring"]
         logger.info('获取querystring数据')
         return querystring
     except Exception as f:
         logger.exception('读取yaml文件报错如下:{}'.format(f))
Beispiel #8
0
 def get_value(self, key, node=None):
     if node == None:
         node = 'pre'
     try:
         value = self.cf.get(node, key)
         logger.info('获取配置文件的值,node:{},key:{}, data:{}'.format(
             node, key, value))
     except Exception:
         logger.exception('没有获取到对应的值,node:{},key:{}'.format(node, key))
         value = None
     return value
 def run_main(self, method, url, data, header, cookie=None,params=None):
     try:
         if method.upper() == 'GET':
             result = self.send_get(url, data, header, cookie)
             logger.info('get请求')
             return result
         elif method.upper() == 'POST':
             result = self.send_post(url, data, header, cookie, params)
             logger.info('post请求')
             return result
         elif method.upper() == 'DELETE':
             result = self.send_delete(url, data, header, cookie, params)
             logger.info('delete请求')
             return result
     except Exception as e:
         logger.exception('请求主函数调用失败:{}'.format(e))
Beispiel #10
0
 def send_delete(self,url,data,header=None,cookie=None,param=None):
     try:
         logger.info('调用delete接口')
         return self.session.delete(url=self.api_root_url+url,json=data,headers=header,cookies=cookie,params=param)
     except Exception as e:
         logger.exception('删除接口调用失败,信息如下:'.format(e))