def test_headers_are_preserved_except_request_id(self): """ `headers` are passed through as is, with an `x-otter-request-id` added. If the header `x-otter-request-id` is supplied in the existing headers, it is replaced. """ headers = {'header1': ['val1'], 'header2': ['val2'], 'x-otter-almost-it': ['unchanged'], 'x-otter-request-id': ['different-value']} new_headers = headers.copy() new_headers['x-otter-request-id'] = ['uuid'] logging_treq.request('get', self.url, headers=headers, log=self.log, clock=self.clock) self.treq.request.assert_called_once_with( method='get', url=self.url, headers=new_headers)
def test_url_params(self): """`params` is logged as `url_params`.""" params = {'key': 'val'} d = logging_treq.request('get', self.url, data='', log=self.log, params=params, clock=self.clock) self.clock.advance(5) self.treq.request.return_value.callback(self.response) self.treq.request.assert_called_once_with( method='get', url=self.url, headers={'x-otter-request-id': ['uuid']}, data='', params=params) self.assertIs(self.successResultOf(d), self.response) self._assert_success_logging('get', 204, 5, url_params=params)
def test_request_timeout(self): """ A request times out after 45 seconds, and the failure is logged """ d = logging_treq.request('patch', self.url, headers={}, data='', log=self.log, clock=self.clock) self.treq.request.assert_called_once_with( method='patch', url=self.url, headers={}, data='') self.assertNoResult(d) self.clock.advance(45) self.failureResultOf(d, TimedOutError) self._assert_failure_logging('patch', TimedOutError, 45)
def test_request_timeout(self): """ A request times out after 45 seconds, and the failure is logged """ d = logging_treq.request('patch', self.url, data='', headers=None, log=self.log, clock=self.clock) self.treq.request.assert_called_once_with( method='patch', url=self.url, headers={'x-otter-request-id': ['uuid']}, data='') self.assertNoResult(d) self.clock.advance(45) self.failureResultOf(d, TimedOutError) self._assert_failure_logging('patch', TimedOutError, 45)
def test_request_failure(self): """ On failed call to request, failure is returned and request logged """ d = logging_treq.request('patch', self.url, headers={}, data='', log=self.log, clock=self.clock) self.treq.request.assert_called_once_with( method='patch', url=self.url, headers={}, data='') self.assertNoResult(d) self.clock.advance(5) self.treq.request.return_value.errback(Failure(DummyException('e'))) self.failureResultOf(d, DummyException) self._assert_failure_logging('patch', DummyException, 5)
def test_request(self): """ On successful call to request, response is returned and request logged """ d = logging_treq.request('patch', self.url, headers={}, data='', log=self.log, clock=self.clock) self.treq.request.assert_called_once_with( method='patch', url=self.url, headers={}, data='') self.assertNoResult(d) self.clock.advance(5) self.treq.request.return_value.callback(self.response) self.assertIs(self.successResultOf(d), self.response) self._assert_success_logging('patch', 204, 5)
def test_request(self): """ On successful call to request, response is returned and request logged """ d = logging_treq.request('patch', self.url, headers={}, data='', log=self.log, clock=self.clock) self.treq.request.assert_called_once_with( method='patch', url=self.url, headers={'x-otter-request-id': ['uuid']}, data='') self.assertNoResult(d) self.clock.advance(5) self.treq.request.return_value.callback(self.response) self.assertIs(self.successResultOf(d), self.response) self._assert_success_logging('patch', 204, 5)
def test_request_failure(self): """ On failed call to request, failure is returned and request logged """ d = logging_treq.request('patch', self.url, data='', log=self.log, clock=self.clock) self.treq.request.assert_called_once_with( method='patch', url=self.url, headers={'x-otter-request-id': ['uuid']}, data='') self.assertNoResult(d) self.clock.advance(5) self.treq.request.return_value.errback(Failure(DummyException('e'))) self.failureResultOf(d, DummyException) self._assert_failure_logging('patch', DummyException, 5)