Coverage for docs_src / tutorial / fastapi / app_testing / tutorial001_py310 / test_extra_coverage.py: 100%
26 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-01-06 21:09 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-01-06 21:09 +0000
1from fastapi.testclient import TestClient 1abcdefgh
2from sqlalchemy import Inspector, inspect 1abcdefgh
3from sqlmodel import Session, create_engine 1abcdefgh
5from . import main as app_mod 1abcdefgh
6from .test_main import client_fixture, session_fixture 1abcdefgh
8assert client_fixture, "This keeps the client fixture used below" 1abcdefgh
9assert session_fixture, "This keeps the session fixture used by client_fixture" 1abcdefgh
12def test_startup(): 1abcdefgh
13 app_mod.engine = create_engine("sqlite://") 1ijklmnop
14 app_mod.on_startup() 1ijklmnop
15 insp: Inspector = inspect(app_mod.engine) 1ijklmnop
16 assert insp.has_table(str(app_mod.Hero.__tablename__)) 1ijklmnop
19def test_get_session(): 1abcdefgh
20 app_mod.engine = create_engine("sqlite://") 1qrstuvwx
21 for session in app_mod.get_session(): 1qrstuvwx
22 assert isinstance(session, Session) 1qrstuvwx
23 assert session.bind == app_mod.engine 1qrstuvwx
26def test_read_hero_not_found(client: TestClient): 1abcdefgh
27 response = client.get("/heroes/9000") 1yzABCDEF
28 assert response.status_code == 404 1yzABCDEF
31def test_update_hero_not_found(client: TestClient): 1abcdefgh
32 response = client.patch("/heroes/9000", json={"name": "Very-Rusty-Man"}) 1GHIJKLMN
33 assert response.status_code == 404 1GHIJKLMN
36def test_delete_hero_not_found(client: TestClient): 1abcdefgh
37 response = client.delete("/heroes/9000") 1OPQRSTUV
38 assert response.status_code == 404 1OPQRSTUV