Add version parameter to websocket routes (#1760)
* Add version parameter to websockets * Run black and cleanup code
This commit is contained in:
parent
6239fa4f56
commit
6c8e20a859
11
sanic/app.py
11
sanic/app.py
|
@ -462,7 +462,13 @@ class Sanic:
|
|||
|
||||
# Decorator
|
||||
def websocket(
|
||||
self, uri, host=None, strict_slashes=None, subprotocols=None, name=None
|
||||
self,
|
||||
uri,
|
||||
host=None,
|
||||
strict_slashes=None,
|
||||
subprotocols=None,
|
||||
version=None,
|
||||
name=None,
|
||||
):
|
||||
"""
|
||||
Decorate a function to be registered as a websocket route
|
||||
|
@ -536,6 +542,7 @@ class Sanic:
|
|||
methods=frozenset({"GET"}),
|
||||
host=host,
|
||||
strict_slashes=strict_slashes,
|
||||
version=version,
|
||||
name=name,
|
||||
)
|
||||
)
|
||||
|
@ -550,6 +557,7 @@ class Sanic:
|
|||
host=None,
|
||||
strict_slashes=None,
|
||||
subprotocols=None,
|
||||
version=None,
|
||||
name=None,
|
||||
):
|
||||
"""
|
||||
|
@ -577,6 +585,7 @@ class Sanic:
|
|||
host=host,
|
||||
strict_slashes=strict_slashes,
|
||||
subprotocols=subprotocols,
|
||||
version=version,
|
||||
name=name,
|
||||
)(handler)
|
||||
|
||||
|
|
|
@ -531,6 +531,19 @@ def test_add_webscoket_route(app, strict_slashes):
|
|||
assert ev.is_set()
|
||||
|
||||
|
||||
def test_add_webscoket_route_with_version(app):
|
||||
ev = asyncio.Event()
|
||||
|
||||
async def handler(request, ws):
|
||||
assert ws.subprotocol is None
|
||||
ev.set()
|
||||
|
||||
app.add_websocket_route(handler, "/ws", version=1)
|
||||
request, response = app.test_client.websocket("/v1/ws")
|
||||
assert response.opened is True
|
||||
assert ev.is_set()
|
||||
|
||||
|
||||
def test_route_duplicate(app):
|
||||
|
||||
with pytest.raises(RouteExists):
|
||||
|
|
Loading…
Reference in New Issue
Block a user