websocket routes in blueprints

This commit is contained in:
Miguel Grinberg
2017-02-20 22:41:53 -08:00
parent 3bf79898d9
commit f90288f5dc
2 changed files with 48 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
import asyncio
import inspect
from sanic import Sanic
@@ -236,6 +237,7 @@ def test_bp_static():
def test_bp_shorthand():
app = Sanic('test_shorhand_routes')
blueprint = Blueprint('test_shorhand_routes')
ev = asyncio.Event()
@blueprint.get('/get')
def handler(request):
@@ -265,6 +267,10 @@ def test_bp_shorthand():
def handler(request):
return text('OK')
@blueprint.websocket('/ws')
async def handler(request, ws):
ev.set()
app.blueprint(blueprint)
request, response = app.test_client.get('/get')
@@ -308,3 +314,11 @@ def test_bp_shorthand():
request, response = app.test_client.get('/delete')
assert response.status == 405
request, response = app.test_client.get('/ws', headers={
'Upgrade': 'websocket',
'Connection': 'upgrade',
'Sec-WebSocket-Key': 'dGhlIHNhbXBsZSBub25jZQ==',
'Sec-WebSocket-Version': '13'})
assert response.status == 101
assert ev.is_set()