def make_request(app, method, path): headers = CIMultiDict() if StrictVersion(aiohttp.__version__) < StrictVersion('0.20.0'): message = aiohttp.RawRequestMessage(method, path, aiohttp.HttpVersion(1, 1), headers, False, False) else: message = aiohttp.RawRequestMessage(method, path, aiohttp.HttpVersion(1, 1), headers, headers, False, False) payload = mock.Mock() transport = mock.Mock() writer = mock.Mock() req = web.Request(app, message, payload, transport, writer, 15) return req
def test_access_logger_atoms(monkeypatch, log_format, expected, extra) -> None: class PatchedDatetime(datetime.datetime): @staticmethod def now(tz): return datetime.datetime(1843, 1, 1, 0, 30, tzinfo=tz) monkeypatch.setattr("datetime.datetime", PatchedDatetime) monkeypatch.setattr("time.timezone", -28800) monkeypatch.setattr("os.getpid", lambda: 42) mock_logger = mock.Mock() access_logger = AccessLogger(mock_logger, log_format) request = mock.Mock( headers={ "H1": "a", "H2": "b" }, method="GET", path_qs="/path", version=aiohttp.HttpVersion(1, 1), remote="127.0.0.2", ) response = mock.Mock(headers={}, body_length=42, status=200) access_logger.log(request, response, 3.1415926) assert not mock_logger.exception.called, mock_logger.exception.call_args mock_logger.info.assert_called_with(expected, extra=extra)
def make_request(self, app, method, path): headers = CIMultiDict() message = aiohttp.RawRequestMessage(method, path, aiohttp.HttpVersion(1, 1), headers, False, False) self.payload = mock.Mock() self.transport = mock.Mock() self.writer = mock.Mock() req = web.Request(app, message, self.payload, self.transport, self.writer, 15) return req