From 3bf79898d9154c6cc96a879efd981ba572de5f6a Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Mon, 20 Feb 2017 15:09:54 -0800 Subject: [PATCH] websocket unit test --- tests/test_routes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_routes.py b/tests/test_routes.py index d9e4532f..632673de 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -1,3 +1,4 @@ +import asyncio import pytest from sanic import Sanic @@ -234,6 +235,23 @@ def test_dynamic_route_unhashable(): 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(): app = Sanic('test_route_duplicate')