Skip to content

Commit 5244b0a

Browse files
committed
🎉 Finish >:)
1 parent 42e8e73 commit 5244b0a

8 files changed

Lines changed: 48 additions & 34 deletions

File tree

docs_src/settings/app02/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
class 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
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
from 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

89
def 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

1516
def 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
}

tests/test_tutorial/test_conditional_openapi/test_tutorial001.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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"}
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
from 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()
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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+
)
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
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+
)
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
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

tests/test_tutorial/test_websockets/test_tutorial003.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from fastapi.testclient import TestClient
22

3-
from docs_src.websockets.tutorial003 import app
3+
from docs_src.websockets.tutorial003 import app, html
44

55
client = TestClient(app)
66

77

8+
def test_get():
9+
response = client.get("/")
10+
assert response.text == html
11+
12+
813
def test_websocket_handle_disconnection():
914
with client.websocket_connect("/ws/1234") as connection, client.websocket_connect(
1015
"/ws/5678"

0 commit comments

Comments
 (0)