Coverage for docs_src/tutorial/fastapi/app_testing/tutorial001_py39/test_extra_coverage.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-03-24 00:02 +0000

1from fastapi.testclient import TestClient 1abcde

2from sqlalchemy import Inspector, inspect 1abcde

3from sqlmodel import Session, create_engine 1abcde

4 

5from . import main as app_mod 1abcde

6from .test_main import client_fixture, session_fixture 1abcde

7 

8assert client_fixture, "This keeps the client fixture used below" 1abcde

9assert session_fixture, "This keeps the session fixture used by client_fixture" 1abcde

10 

11 

12def test_startup(): 1abcde

13 app_mod.engine = create_engine("sqlite://") 1fghij

14 app_mod.on_startup() 1fghij

15 insp: Inspector = inspect(app_mod.engine) 1fghij

16 assert insp.has_table(str(app_mod.Hero.__tablename__)) 1fghij

17 

18 

19def test_get_session(): 1abcde

20 app_mod.engine = create_engine("sqlite://") 1klmno

21 for session in app_mod.get_session(): 1klmno

22 assert isinstance(session, Session) 1klmno

23 assert session.bind == app_mod.engine 1klmno

24 

25 

26def test_read_hero_not_found(client: TestClient): 1abcde

27 response = client.get("/heroes/9000") 1pqrst

28 assert response.status_code == 404 1pqrst

29 

30 

31def test_update_hero_not_found(client: TestClient): 1abcde

32 response = client.patch("/heroes/9000", json={"name": "Very-Rusty-Man"}) 1uvwxy

33 assert response.status_code == 404 1uvwxy

34 

35 

36def test_delete_hero_not_found(client: TestClient): 1abcde

37 response = client.delete("/heroes/9000") 1zABCD

38 assert response.status_code == 404 1zABCD