websocket unit test
This commit is contained in:
parent
1d6e11ca10
commit
3bf79898d9
|
@ -1,3 +1,4 @@
|
||||||
|
import asyncio
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
|
@ -234,6 +235,23 @@ def test_dynamic_route_unhashable():
|
||||||
assert response.status == 404
|
assert response.status == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_websocket_route():
|
||||||
|
app = Sanic('test_websocket_route')
|
||||||
|
ev = asyncio.Event()
|
||||||
|
|
||||||
|
@app.websocket('/ws')
|
||||||
|
async def handler(request, ws):
|
||||||
|
ev.set()
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
def test_route_duplicate():
|
def test_route_duplicate():
|
||||||
app = Sanic('test_route_duplicate')
|
app = Sanic('test_route_duplicate')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user