fixed unit tests
This commit is contained in:
parent
c39ddd00d3
commit
d1a8e8b042
|
@ -59,7 +59,9 @@ class SanicTestClient:
|
||||||
@self.app.exception(MethodNotSupported)
|
@self.app.exception(MethodNotSupported)
|
||||||
async def error_handler(request, exception):
|
async def error_handler(request, exception):
|
||||||
if request.method in ['HEAD', 'PATCH', 'PUT', 'DELETE']:
|
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:
|
else:
|
||||||
return self.app.error_handler.default(request, exception)
|
return self.app.error_handler.default(request, exception)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ class ReuseableTCPConnector(TCPConnector):
|
||||||
super(ReuseableTCPConnector, self).__init__(*args, **kwargs)
|
super(ReuseableTCPConnector, self).__init__(*args, **kwargs)
|
||||||
self.old_proto = None
|
self.old_proto = None
|
||||||
|
|
||||||
|
if aiohttp.__version__ >= '3.0':
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def connect(self, req, traces=None):
|
def connect(self, req, traces=None):
|
||||||
new_conn = yield from super(ReuseableTCPConnector, self)\
|
new_conn = yield from super(ReuseableTCPConnector, self)\
|
||||||
|
@ -26,6 +27,18 @@ class ReuseableTCPConnector(TCPConnector):
|
||||||
print(new_conn.__dict__)
|
print(new_conn.__dict__)
|
||||||
self.old_proto = new_conn._protocol
|
self.old_proto = new_conn._protocol
|
||||||
return new_conn
|
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):
|
class ReuseableSanicTestClient(SanicTestClient):
|
||||||
|
|
|
@ -80,6 +80,7 @@ class DelayableTCPConnector(TCPConnector):
|
||||||
self._post_connect_delay = _post_connect_delay
|
self._post_connect_delay = _post_connect_delay
|
||||||
self._pre_request_delay = _pre_request_delay
|
self._pre_request_delay = _pre_request_delay
|
||||||
|
|
||||||
|
if aiohttp.__version__ >= '3.0':
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def connect(self, req, traces=None):
|
def connect(self, req, traces=None):
|
||||||
d_req = DelayableTCPConnector.\
|
d_req = DelayableTCPConnector.\
|
||||||
|
@ -92,6 +93,19 @@ class DelayableTCPConnector(TCPConnector):
|
||||||
t = req.loop.time()
|
t = req.loop.time()
|
||||||
print("Connected at {}".format(t), flush=True)
|
print("Connected at {}".format(t), flush=True)
|
||||||
return conn
|
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):
|
class DelayableSanicTestClient(SanicTestClient):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user