diff --git a/sanic/testing.py b/sanic/testing.py index bf517f53..a639e16e 100644 --- a/sanic/testing.py +++ b/sanic/testing.py @@ -59,7 +59,9 @@ class SanicTestClient: @self.app.exception(MethodNotSupported) async def error_handler(request, exception): if request.method in ['HEAD', 'PATCH', 'PUT', 'DELETE']: - return text('', exception.status_code, headers=exception.headers) + return text( + '', exception.status_code, headers=exception.headers + ) else: return self.app.error_handler.default(request, exception) diff --git a/tests/test_keep_alive_timeout.py b/tests/test_keep_alive_timeout.py index 4a3a8d1e..be2c6f0d 100644 --- a/tests/test_keep_alive_timeout.py +++ b/tests/test_keep_alive_timeout.py @@ -15,17 +15,30 @@ class ReuseableTCPConnector(TCPConnector): super(ReuseableTCPConnector, self).__init__(*args, **kwargs) self.old_proto = None - @asyncio.coroutine - def connect(self, req, traces=None): - new_conn = yield from super(ReuseableTCPConnector, self)\ - .connect(req, traces=traces) - if self.old_proto is not None: - if self.old_proto != new_conn._protocol: - raise RuntimeError( - "We got a new connection, wanted the same one!") - print(new_conn.__dict__) - self.old_proto = new_conn._protocol - return new_conn + if aiohttp.__version__ >= '3.0': + @asyncio.coroutine + def connect(self, req, traces=None): + new_conn = yield from super(ReuseableTCPConnector, self)\ + .connect(req, traces=traces) + if self.old_proto is not None: + if self.old_proto != new_conn._protocol: + raise RuntimeError( + "We got a new connection, wanted the same one!") + print(new_conn.__dict__) + self.old_proto = new_conn._protocol + return new_conn + else: + @asyncio.coroutine + def connect(self, req): + new_conn = yield from super(ReuseableTCPConnector, self)\ + .connect(req) + if self.old_proto is not None: + if self.old_proto != new_conn._protocol: + raise RuntimeError( + "We got a new connection, wanted the same one!") + print(new_conn.__dict__) + self.old_proto = new_conn._protocol + return new_conn class ReuseableSanicTestClient(SanicTestClient): diff --git a/tests/test_request_timeout.py b/tests/test_request_timeout.py index 2a540404..d667d0a4 100644 --- a/tests/test_request_timeout.py +++ b/tests/test_request_timeout.py @@ -80,18 +80,32 @@ class DelayableTCPConnector(TCPConnector): self._post_connect_delay = _post_connect_delay self._pre_request_delay = _pre_request_delay - @asyncio.coroutine - def connect(self, req, traces=None): - d_req = DelayableTCPConnector.\ - RequestContextManager(req, self._pre_request_delay) - conn = yield from super(DelayableTCPConnector, self).connect(req, traces=traces) - if self._post_connect_delay and self._post_connect_delay > 0: - _ = yield from asyncio.sleep(self._post_connect_delay, - loop=self._loop) - req.send = d_req.send - t = req.loop.time() - print("Connected at {}".format(t), flush=True) - return conn + if aiohttp.__version__ >= '3.0': + @asyncio.coroutine + def connect(self, req, traces=None): + d_req = DelayableTCPConnector.\ + RequestContextManager(req, self._pre_request_delay) + conn = yield from super(DelayableTCPConnector, self).connect(req, traces=traces) + if self._post_connect_delay and self._post_connect_delay > 0: + _ = yield from asyncio.sleep(self._post_connect_delay, + loop=self._loop) + req.send = d_req.send + t = req.loop.time() + print("Connected at {}".format(t), flush=True) + return conn + else: + @asyncio.coroutine + def connect(self, req): + d_req = DelayableTCPConnector.\ + RequestContextManager(req, self._pre_request_delay) + conn = yield from super(DelayableTCPConnector, self).connect(req) + if self._post_connect_delay and self._post_connect_delay > 0: + _ = yield from asyncio.sleep(self._post_connect_delay, + loop=self._loop) + req.send = d_req.send + t = req.loop.time() + print("Connected at {}".format(t), flush=True) + return conn class DelayableSanicTestClient(SanicTestClient):