File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44class Settings (BaseSettings ):
55 app_name : str = "Awesome API"
6- admin_email : str
6+ admin_email : str = "admin@example.com"
77 items_per_user : int = 50
Original file line number Diff line number Diff line change 11from fastapi .testclient import TestClient
22
3- from . import config , main
3+ from .config import Settings
4+ from .main import app , get_settings
45
5- client = TestClient (main . app )
6+ client = TestClient (app )
67
78
89def get_settings_override ():
9- return config . Settings (admin_email = "testing_admin @example.com" )
10+ return Settings (admin_email = "another_admin @example.com" )
1011
1112
12- main . app .dependency_overrides [main . get_settings ] = get_settings_override
13+ app .dependency_overrides [get_settings ] = get_settings_override
1314
1415
1516def test_app ():
16-
1717 response = client .get ("/info" )
18- data = response .json ()
19- assert data == {
18+ assert response .json () == {
2019 "app_name" : "Awesome API" ,
21- "admin_email" : "testing_admin @example.com" ,
20+ "admin_email" : "another_admin @example.com" ,
2221 "items_per_user" : 50 ,
2322 }
Original file line number Diff line number Diff line change @@ -44,3 +44,10 @@ def test_disable_openapi(monkeypatch):
4444 assert response .status_code == 404 , response .text
4545 response = client .get ("/redoc" )
4646 assert response .status_code == 404 , response .text
47+
48+
49+ def test_root ():
50+ client = TestClient (tutorial001 .app )
51+ response = client .get ("/" )
52+ assert response .status_code == 200
53+ assert response .json () == {"message" : "Hello World" }
Original file line number Diff line number Diff line change 11from fastapi .testclient import TestClient
22
3- from docs_src .settings .app02 import main , test_main
3+ from docs_src .settings .app02 . main import app
44
5- client = TestClient (main .app )
65
6+ def test_settings ():
7+ client = TestClient (app )
8+ response = client .get ("/info" )
9+ assert response .json () == {
10+ "app_name" : "Awesome API" ,
11+ "admin_email" : "admin@example.com" ,
12+ "items_per_user" : 50 ,
13+ }
714
8- def test_setting_override ():
9- test_main .test_app ()
15+
16+ def test_override_settings ():
17+ from docs_src .settings .app02 .test_main import test_app
18+
19+ test_app ()
Original file line number Diff line number Diff line change 1- from docs_src .app_testing .test_main_b import test_create_existing_item # noqa: F401
2- from docs_src .app_testing .test_main_b import test_create_item # noqa: F401
3- from docs_src .app_testing .test_main_b import test_create_item_bad_token # noqa: F401
4- from docs_src .app_testing .test_main_b import test_read_inexistent_item # noqa: F401
5- from docs_src .app_testing .test_main_b import test_read_item # noqa: F401
6- from docs_src .app_testing .test_main_b import test_read_item_bad_token # noqa: F401
1+ from docs_src .app_testing .test_main_b import ( # noqa: F401
2+ test_create_existing_item ,
3+ test_create_item ,
4+ test_create_item_bad_token ,
5+ test_read_inexistent_item ,
6+ test_read_item ,
7+ test_read_item_bad_token ,
8+ )
Original file line number Diff line number Diff line change 1- from docs_src .app_testing .tutorial002 import test_read_main , test_websocket
2-
3-
4- def test_main ():
5- test_read_main ()
6-
7-
8- def test_ws ():
9- test_websocket ()
1+ from docs_src .app_testing .tutorial002 import ( # noqa: F401
2+ test_read_main ,
3+ test_websocket ,
4+ )
Original file line number Diff line number Diff line change 1- from docs_src .app_testing .tutorial003 import test_read_items
2-
3-
4- def test_main ():
5- test_read_items ()
1+ from docs_src .app_testing .tutorial003 import test_read_items # noqa: F401
Original file line number Diff line number Diff line change 11from fastapi .testclient import TestClient
22
3- from docs_src .websockets .tutorial003 import app
3+ from docs_src .websockets .tutorial003 import app , html
44
55client = TestClient (app )
66
77
8+ def test_get ():
9+ response = client .get ("/" )
10+ assert response .text == html
11+
12+
813def test_websocket_handle_disconnection ():
914 with client .websocket_connect ("/ws/1234" ) as connection , client .websocket_connect (
1015 "/ws/5678"
You can’t perform that action at this time.
0 commit comments