Browse Source

🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

pull/13626/head
pre-commit-ci[bot] 4 months ago
parent
commit
220190fb38
  1. 4
      fastapi/applications.py
  2. 38
      tests/test_ws_router.py

4
fastapi/applications.py

@ -1226,8 +1226,8 @@ class FastAPI(Starlette):
""" """
A list of tags to be applied to this WebSocket. A list of tags to be applied to this WebSocket.
""" """
) ),
] = None ] = None,
) -> Callable[[DecoratedCallable], DecoratedCallable]: ) -> Callable[[DecoratedCallable], DecoratedCallable]:
""" """
Decorate a WebSocket function. Decorate a WebSocket function.

38
tests/test_ws_router.py

@ -13,9 +13,9 @@ from fastapi import (
from fastapi.middleware import Middleware from fastapi.middleware import Middleware
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
router = APIRouter(tags=['base']) router = APIRouter(tags=["base"])
prefix_router = APIRouter(tags=['prefix']) prefix_router = APIRouter(tags=["prefix"])
native_prefix_router = APIRouter(prefix="/native", tags=['native']) native_prefix_router = APIRouter(prefix="/native", tags=["native"])
app = FastAPI() app = FastAPI()
@ -105,17 +105,23 @@ async def router_ws_custom_error(websocket: WebSocket):
@app.websocket("/test_tags", name="test-app-tags", tags=["test-app-tags"]) @app.websocket("/test_tags", name="test-app-tags", tags=["test-app-tags"])
@router.websocket("/test_tags/", name="test-router-tags", tags=["test-router-tags"]) @router.websocket("/test_tags/", name="test-router-tags", tags=["test-router-tags"])
async def router_ws_test_tags(websocket: WebSocket): async def router_ws_test_tags(websocket: WebSocket):
pass # pragma: no cover pass # pragma: no cover
@prefix_router.websocket("/test_tags/", name="test-prefix-router-tags", tags=["test-prefix-router-tags"])
@prefix_router.websocket(
"/test_tags/", name="test-prefix-router-tags", tags=["test-prefix-router-tags"]
)
async def prefix_router_ws_test_tags(websocket: WebSocket): async def prefix_router_ws_test_tags(websocket: WebSocket):
pass # pragma: no cover pass # pragma: no cover
@native_prefix_router.websocket("/test_tags/", name="test-native-prefix-router-tags",
tags=["test-native-prefix-router-tags"]) @native_prefix_router.websocket(
"/test_tags/",
name="test-native-prefix-router-tags",
tags=["test-native-prefix-router-tags"],
)
async def native_prefix_router_ws_test_tags(websocket: WebSocket): async def native_prefix_router_ws_test_tags(websocket: WebSocket):
pass # pragma: no cover pass # pragma: no cover
@ -287,12 +293,18 @@ def test_depend_err_handler():
assert "foo" in e.value.reason assert "foo" in e.value.reason
@pytest.mark.parametrize("route_name,route_tags", [ @pytest.mark.parametrize(
("test-app-tags", ["test-app-tags"]), "route_name,route_tags",
("test-router-tags", ["base", "test-router-tags"]), [
("test-prefix-router-tags", ["prefix", "test-prefix-router-tags"]), ("test-app-tags", ["test-app-tags"]),
("test-native-prefix-router-tags", ["native", "test-native-prefix-router-tags"]), ("test-router-tags", ["base", "test-router-tags"]),
]) ("test-prefix-router-tags", ["prefix", "test-prefix-router-tags"]),
(
"test-native-prefix-router-tags",
["native", "test-native-prefix-router-tags"],
),
],
)
def test_websocket_tags(route_name, route_tags): def test_websocket_tags(route_name, route_tags):
""" """
Verify that it is possible to add tags to websocket routes Verify that it is possible to add tags to websocket routes

Loading…
Cancel
Save