Merge pull request #2 from channelcat/master

remote-tracking with upstream
This commit is contained in:
7 2017-06-10 11:54:11 -07:00 committed by GitHub
commit 0646baa18d
3 changed files with 33 additions and 1 deletions

View File

@ -351,7 +351,10 @@ class Router:
:param request: Request object :param request: Request object
:return: bool :return: bool
""" """
try:
handler = self.get(request)[0] handler = self.get(request)[0]
except (NotFound, InvalidUsage):
return False
if (hasattr(handler, 'view_class') and if (hasattr(handler, 'view_class') and
hasattr(handler.view_class, request.method.lower())): hasattr(handler.view_class, request.method.lower())):
handler = getattr(handler.view_class, request.method.lower()) handler = getattr(handler.view_class, request.method.lower())

View File

@ -159,6 +159,7 @@ class GunicornWorker(base.Worker):
def handle_quit(self, sig, frame): def handle_quit(self, sig, frame):
self.alive = False self.alive = False
self.app.callable.is_running = False
self.cfg.worker_int(self) self.cfg.worker_int(self)
def handle_abort(self, sig, frame): def handle_abort(self, sig, frame):

View File

@ -163,6 +163,34 @@ def test_request_stream_app():
assert response.text == data assert response.text == data
def test_request_stream_handle_exception():
'''for handling exceptions properly'''
app = Sanic('test_request_stream_exception')
@app.post('/post/<id>', stream=True)
async def post(request, id):
assert isinstance(request.stream, asyncio.Queue)
async def streaming(response):
while True:
body = await request.stream.get()
if body is None:
break
response.write(body.decode('utf-8'))
return stream(streaming)
# 404
request, response = app.test_client.post('/in_valid_post', data=data)
assert response.status == 404
assert response.text == 'Error: Requested URL /in_valid_post not found'
# 405
request, response = app.test_client.get('/post/random_id', data=data)
assert response.status == 405
assert response.text == 'Error: Method GET not allowed for URL /post/random_id'
def test_request_stream_blueprint(): def test_request_stream_blueprint():
'''for self.is_request_stream = True''' '''for self.is_request_stream = True'''