committed by
GitHub
10 changed files with 60 additions and 18 deletions
@ -1,19 +1,19 @@ |
|||||
from fastapi.testclient import TestClient |
from fastapi.testclient import TestClient |
||||
|
|
||||
from . import config, main |
from .config import Settings |
||||
|
from .main import app, get_settings |
||||
|
|
||||
client = TestClient(main.app) |
client = TestClient(app) |
||||
|
|
||||
|
|
||||
def get_settings_override(): |
def get_settings_override(): |
||||
return config.Settings(admin_email="[email protected]") |
return Settings(admin_email="[email protected]") |
||||
|
|
||||
|
|
||||
main.app.dependency_overrides[main.get_settings] = get_settings_override |
app.dependency_overrides[get_settings] = get_settings_override |
||||
|
|
||||
|
|
||||
def test_app(): |
def test_app(): |
||||
|
|
||||
response = client.get("/info") |
response = client.get("/info") |
||||
data = response.json() |
data = response.json() |
||||
assert data == { |
assert data == { |
||||
|
@ -1,9 +1,17 @@ |
|||||
from fastapi.testclient import TestClient |
from fastapi.testclient import TestClient |
||||
|
from pytest import MonkeyPatch |
||||
|
|
||||
from docs_src.settings.app02 import main, test_main |
from docs_src.settings.app02 import main, test_main |
||||
|
|
||||
client = TestClient(main.app) |
client = TestClient(main.app) |
||||
|
|
||||
|
|
||||
def test_setting_override(): |
def test_settings(monkeypatch: MonkeyPatch): |
||||
|
monkeypatch.setenv("ADMIN_EMAIL", "[email protected]") |
||||
|
settings = main.get_settings() |
||||
|
assert settings.app_name == "Awesome API" |
||||
|
assert settings.items_per_user == 50 |
||||
|
|
||||
|
|
||||
|
def test_override_settings(): |
||||
test_main.test_app() |
test_main.test_app() |
||||
|
@ -0,0 +1,10 @@ |
|||||
|
from docs_src.app_testing import test_main_b |
||||
|
|
||||
|
|
||||
|
def test_app(): |
||||
|
test_main_b.test_create_existing_item() |
||||
|
test_main_b.test_create_item() |
||||
|
test_main_b.test_create_item_bad_token() |
||||
|
test_main_b.test_read_inexistent_item() |
||||
|
test_main_b.test_read_item() |
||||
|
test_main_b.test_read_item_bad_token() |
Loading…
Reference in new issue