mirror of https://github.com/tiangolo/fastapi.git
tests: add test for websocket
This commit is contained in:
parent
d11ed8208b
commit
c3b164a1cc
|
|
@ -9,11 +9,11 @@ def test_app_router_with_duplicate_path():
|
|||
|
||||
@app.get("/items/")
|
||||
def read_items():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
@app.get("/items/")
|
||||
def read_items2():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
|
||||
def test_sub_with_duplicate_path():
|
||||
|
|
@ -23,13 +23,13 @@ def test_sub_with_duplicate_path():
|
|||
|
||||
@router.get("/items/")
|
||||
def read_items():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
@router.get("/items/")
|
||||
def read_items2():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
app.include_router(router)
|
||||
app.include_router(router) # pragma: no cover
|
||||
|
||||
|
||||
def test_mix_app_sub_with_duplicate_path():
|
||||
|
|
@ -39,13 +39,13 @@ def test_mix_app_sub_with_duplicate_path():
|
|||
|
||||
@app.get("/items/")
|
||||
def read_items():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
@router.get("/items/")
|
||||
def read_items2():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
app.include_router(router)
|
||||
app.include_router(router) # pragma: no cover
|
||||
|
||||
|
||||
def test_sub_route_direct_duplicate_path():
|
||||
|
|
@ -55,13 +55,13 @@ def test_sub_route_direct_duplicate_path():
|
|||
|
||||
@router.route("/items/")
|
||||
def read_items():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
@router.route("/items/")
|
||||
def read_items2():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
app.include_router(router)
|
||||
app.include_router(router) # pragma: no cover
|
||||
|
||||
|
||||
def test_app_router_with_duplicate_path_different_method():
|
||||
|
|
@ -69,11 +69,11 @@ def test_app_router_with_duplicate_path_different_method():
|
|||
|
||||
@app.get("/items/")
|
||||
def read_items():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
@app.post("/items/")
|
||||
def read_items2():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
|
||||
def test_sub_with_duplicate_path_different_method():
|
||||
|
|
@ -82,13 +82,13 @@ def test_sub_with_duplicate_path_different_method():
|
|||
|
||||
@router.get("/items/")
|
||||
def read_items():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
@router.post("/items/")
|
||||
def read_items2():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
app.include_router(router)
|
||||
app.include_router(router) # pragma: no cover
|
||||
|
||||
|
||||
def test_mix_app_sub_with_duplicate_different_method():
|
||||
|
|
@ -97,13 +97,13 @@ def test_mix_app_sub_with_duplicate_different_method():
|
|||
|
||||
@app.get("/items/")
|
||||
def read_items():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
@router.post("/items/")
|
||||
def read_items2():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
app.include_router(router)
|
||||
app.include_router(router) # pragma: no cover
|
||||
|
||||
|
||||
def test_sub_route_direct_duplicate_path_different_method():
|
||||
|
|
@ -112,10 +112,40 @@ def test_sub_route_direct_duplicate_path_different_method():
|
|||
|
||||
@router.route("/items/")
|
||||
def read_items():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
@router.route("/items/", methods=["POST"])
|
||||
def read_items2():
|
||||
return
|
||||
return # pragma: no cover
|
||||
|
||||
app.include_router(router) # pragma: no cover
|
||||
|
||||
|
||||
def test_app_websocket_route_with_duplicate_path():
|
||||
with pytest.raises(RouteAlreadyExistsError):
|
||||
app = FastAPI()
|
||||
|
||||
@app.websocket("/items/")
|
||||
def read_items():
|
||||
return # pragma: no cover
|
||||
|
||||
@app.websocket("/items/")
|
||||
def read_items2():
|
||||
return # pragma: no cover
|
||||
|
||||
|
||||
def test_sub_with_duplicate_path_with_prefix():
|
||||
with pytest.raises(RouteAlreadyExistsError):
|
||||
app = FastAPI()
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/items/")
|
||||
def read_items():
|
||||
return # pragma: no cover
|
||||
|
||||
@router.get("/items/")
|
||||
def read_items2():
|
||||
return # pragma: no cover
|
||||
|
||||
app.include_router(router, prefix="/prefix") # pragma: no cover
|
||||
|
||||
app.include_router(router)
|
||||
|
|
|
|||
Loading…
Reference in New Issue