Ejemplo n.º 1
0
 def _send_post_restful(self, data):
     self._revise_result_url(data['url'])
     log_message('发送请求').logger.info('发送%s请求' % self.url)
     response = requests.post(url=self.url,
                              json=data['data'],
                              headers=self.header)
     return response
Ejemplo n.º 2
0
 def send_request(self, data=None):
     send_switch = dict(
         zip(sorted(REQUEST_TYPE_TUPLE), self._get_sends_list()))
     print(send_switch)
     #response = self.__dict__[send_switch[self.request_type]](data)
     response = getattr(self, send_switch[self.request_type])(data)
     log_message('响应信息').logger.info(response.text)
     return response
Ejemplo n.º 3
0
 def __enter__(self):
     try:
         pre_condition = self.dependence()
     except Exception as e:
         log_message('前置条件').logger.error('上下文条件发生错误')
         raise PreConditionException()
     else:
         return pre_condition
Ejemplo n.º 4
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     if isinstance(exc_type, Exception):
         log_message('数据渲染').logger.error('中间层错误')
         log_message('数据渲染').logger.error(exc_val)
         log_message('数据渲染').logger.error(exc_tb)
         return False
     return True
Ejemplo n.º 5
0
 def _revise_result_url(self, data):
     '''将restful风格的接口参数数据,填入url'''
     if self.request_type != 'GET_RESTFUL' and self.request_type != 'POST_RESTFUL' and self.request_type != 'PUT_RESTFUL':
         log_message('请求错误').logger.error('请求类型不是restful风格')
         raise AssertionError
     elif not isinstance(data, dict):
         log_message('类型错误').logger.error('传入restful的请求的参数不是字典数据')
         raise TypeError
     elif getSubstrNum(self.url, '%s') != len(data):
         log_message('参数错误').logger.error('传入restful的请求的参数个数不对,需要%d个' %
                                          getSubstrNum(self.url, '%s'))
         raise ValueError
     else:
         self.url = self.url % tuple(data.values())
Ejemplo n.º 6
0
 def _send_put_restful(self, data):
     self._revise_result_url(data)
     log_message('发送请求').logger.info('发送%s请求' % self.url)
     response = requests.put(url=self.url, headers=self.header)
     return response
Ejemplo n.º 7
0
 def _send_get(self, data):
     log_message('发送请求').logger.info('发送%s请求' % self.url)
     response = requests.get(url=self.url, params=data, headers=self.header)
     return response
Ejemplo n.º 8
0
 def _send_post(self, data):
     log_message('发送请求').logger.info('发送%s请求' % self.url)
     response = requests.post(url=self.url, json=data, headers=self.header)
     return response
Ejemplo n.º 9
0
 def get_data(self, test_name, **kwargs):
     template = self.env.get_template(test_name + ".json")
     log_message('数据渲染').logger.info(template.render(**kwargs))
     data = json.loads(template.render(**kwargs))
     log_message('数据渲染').logger.info(data)
     return data