committed by
Sebastián Ramírez
2 changed files with 39 additions and 1 deletions
@ -0,0 +1,33 @@ |
|||||
|
import pytest |
||||
|
from fastapi import APIRouter, FastAPI |
||||
|
from starlette.testclient import TestClient |
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
router = APIRouter() |
||||
|
|
||||
|
|
||||
|
@router.get("") |
||||
|
def get_empty(): |
||||
|
return ["OK"] |
||||
|
|
||||
|
|
||||
|
app.include_router(router, prefix="/prefix") |
||||
|
|
||||
|
|
||||
|
client = TestClient(app) |
||||
|
|
||||
|
|
||||
|
def test_use_empty(): |
||||
|
with client: |
||||
|
response = client.get("/prefix") |
||||
|
assert response.json() == ["OK"] |
||||
|
|
||||
|
response = client.get("/prefix/") |
||||
|
assert response.status_code == 404 |
||||
|
|
||||
|
|
||||
|
def test_include_empty(): |
||||
|
# if both include and router.path are empty - it should raise exception |
||||
|
with pytest.raises(Exception): |
||||
|
app.include_router(router) |
Loading…
Reference in new issue