示例#1
0
 def request_wrapper(self, *args, **kwargs):
     log_level = logging.INFO
     request_error = ''
     response_status = None
     response_body = ''
     try:
         response = func(self, *args, **kwargs)
         response_status = response.status_code
         response_body = response.content
     except Exception as err:
         log_level = logging.ERROR
         request_error = str(err)
         if getattr(err, 'response', None) is not None:
             response_status = err.response.status_code
             response_body = pformat_json(err.response.text)
         raise
     else:
         return response
     finally:
         # args will be Requests method, url, and optionally params, data or json.
         # kwargs may include Requests method kwargs and raise_for_status.
         kwargs.pop('raise_for_status', None)
         RequestLog.log(log_level, self.domain_name, self.payload_id,
                        request_error, response_status, response_body,
                        *args, **kwargs)
示例#2
0
 def request_wrapper(self, *args, **kwargs):
     log_level = logging.INFO
     request_error = ''
     response_status = None
     response_body = ''
     try:
         response = func(self, *args, **kwargs)
         response_status = response.status_code
         response_body = response.content
     except Exception as err:
         log_level = logging.ERROR
         request_error = str(err)
         if getattr(err, 'response', None) is not None:
             response_status = err.response.status_code
             response_body = pformat_json(err.response.content)
         raise
     else:
         return response
     finally:
         # args will be Requests method, url, and optionally params, data or json.
         # kwargs may include Requests method kwargs and raise_for_status.
         kwargs.pop('raise_for_status', None)
         RequestLog.log(log_level, self.domain_name, request_error, response_status, response_body,
                        *args, **kwargs)
示例#3
0
 def log_request(self, log_level, log_entry):
     log = RequestLog.log(log_level, log_entry)
     self.status = IncrementalExportStatus.from_log_entry(log_entry)
     self.request_log = log
     self.save()
示例#4
0
 def test_request_body_none(self):
     entry = self.get_entry(request_body=None)
     request_log = RequestLog.log(level=logging.DEBUG, log_entry=entry)
     template_value = pp_json(request_log.request_body)
     self.assertEqual(template_value, '')
示例#5
0
 def test_request_body_unserializable(self):
     entry = self.get_entry(request_body={'hello': Decimal('1.0')})
     request_log = RequestLog.log(level=logging.DEBUG, log_entry=entry)
     template_value = pp_json(request_log.request_body)
     self.assertEqual(template_value, "{'hello': Decimal('1.0')}")
示例#6
0
 def test_request_body_str(self):
     entry = self.get_entry(request_body='hello, world!')
     request_log = RequestLog.log(level=logging.DEBUG, log_entry=entry)
     template_value = pp_json(request_log.request_body)
     self.assertEqual(template_value, 'hello, world!')
示例#7
0
 def test_request_body_dict(self):
     entry = self.get_entry(request_body={'hello': 'world!'})
     request_log = RequestLog.log(level=logging.DEBUG, log_entry=entry)
     template_value = pp_json(request_log.request_body)
     self.assertEqual(template_value, '{\n  "hello": "world!"\n}')