示例#1
0
 def send_request(self, method, url, data=None, is_json=False, **kwargs):
     method = method.upper()
     if isinstance(data, str):
         try:
             data = json.loads(data)
         except Exception as e:
             do_logger.error("将json转为Python中的数据类型时, 出现异常: {}".format(e))
             data = eval(data)
     if method == 'GET':
         res = self.one_session.request(method=method,
                                        url=url,
                                        params=data,
                                        **kwargs)
     elif method == 'POST':
         if is_json:
             res = self.one_session.request(method=method,
                                            url=url,
                                            json=data,
                                            **kwargs)
         else:
             res = self.one_session.request(method=method,
                                            url=url,
                                            data=data,
                                            **kwargs)
     else:
         res = None
         do_logger.error("不支持【{}】方法请求".format(method))
     return res
 def test_register(self, case_list):
     self.my_HandleExcel = HandleExcel(file, 'register')
     request_result = do_request.send_request(
         case_list['method'],
         do_config.get_value('request', 'default_address') +
         case_list['url_path'], case_list['data'])
     actual_text = request_result.text
     actual_value = json.loads(actual_text)['code']
     actual = 'code: "{}",'.format(actual_value)
     result = case_list['expected']
     msg = case_list['title']
     try:
         self.assertEqual(result, actual, msg)
         print('{},执行结果为:{}'.format(msg, true_result))
         self.my_HandleExcel.write_result(case_list['case_id'] + 1, actual,
                                          true_result)
         do_logger.error("{}, 执行结果为: {}".format(msg, true_result))
     except AssertionError as e:
         print('具体异常为{}'.format(e))
         self.my_HandleExcel.write_result(case_list['case_id'] + 1, actual,
                                          fail_result)
         do_logger.error("{}, 执行结果为: {},具体异常为{}".format(
             msg, fail_result, e))
         raise e