Coverage for tests/test_empty_router.py: 100%
22 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-01-13 13:38 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-01-13 13:38 +0000
1import pytest 1abcde
2from fastapi import APIRouter, FastAPI 1abcde
3from fastapi.exceptions import FastAPIError 1abcde
4from fastapi.testclient import TestClient 1abcde
6app = FastAPI() 1abcde
8router = APIRouter() 1abcde
11@router.get("") 1abcde
12def get_empty(): 1abcde
13 return ["OK"] 1fghij
16app.include_router(router, prefix="/prefix") 1abcde
19client = TestClient(app) 1abcde
22def test_use_empty(): 1abcde
23 with client: 1fghij
24 response = client.get("/prefix") 1fghij
25 assert response.status_code == 200, response.text 1fghij
26 assert response.json() == ["OK"] 1fghij
28 response = client.get("/prefix/") 1fghij
29 assert response.status_code == 200, response.text 1fghij
30 assert response.json() == ["OK"] 1fghij
33def test_include_empty(): 1abcde
34 # if both include and router.path are empty - it should raise exception
35 with pytest.raises(FastAPIError): 1klmno
36 app.include_router(router) 1klmno