mirror of https://github.com/tiangolo/fastapi.git
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
This commit is contained in:
parent
4f418eefe0
commit
220190fb38
|
|
@ -1226,8 +1226,8 @@ class FastAPI(Starlette):
|
|||
"""
|
||||
A list of tags to be applied to this WebSocket.
|
||||
"""
|
||||
)
|
||||
] = None
|
||||
),
|
||||
] = None,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
"""
|
||||
Decorate a WebSocket function.
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ from fastapi import (
|
|||
from fastapi.middleware import Middleware
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
router = APIRouter(tags=['base'])
|
||||
prefix_router = APIRouter(tags=['prefix'])
|
||||
native_prefix_router = APIRouter(prefix="/native", tags=['native'])
|
||||
router = APIRouter(tags=["base"])
|
||||
prefix_router = APIRouter(tags=["prefix"])
|
||||
native_prefix_router = APIRouter(prefix="/native", tags=["native"])
|
||||
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"])
|
||||
|
||||
@router.websocket("/test_tags/", name="test-router-tags", tags=["test-router-tags"])
|
||||
async def router_ws_test_tags(websocket: WebSocket):
|
||||
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):
|
||||
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):
|
||||
pass # pragma: no cover
|
||||
|
||||
|
|
@ -287,12 +293,18 @@ def test_depend_err_handler():
|
|||
assert "foo" in e.value.reason
|
||||
|
||||
|
||||
@pytest.mark.parametrize("route_name,route_tags", [
|
||||
("test-app-tags", ["test-app-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"]),
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"route_name,route_tags",
|
||||
[
|
||||
("test-app-tags", ["test-app-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):
|
||||
"""
|
||||
Verify that it is possible to add tags to websocket routes
|
||||
|
|
|
|||
Loading…
Reference in New Issue