Sync fastapi docs from 50fa3f7c on 2026-01-11
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
app_name: str = "Awesome API"
|
||||
admin_email: str
|
||||
items_per_user: int = 50
|
||||
@@ -0,0 +1,21 @@
|
||||
from functools import lru_cache
|
||||
|
||||
from fastapi import Depends, FastAPI
|
||||
|
||||
from .config import Settings
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings():
|
||||
return Settings()
|
||||
|
||||
|
||||
@app.get("/info")
|
||||
async def info(settings: Settings = Depends(get_settings)):
|
||||
return {
|
||||
"app_name": settings.app_name,
|
||||
"admin_email": settings.admin_email,
|
||||
"items_per_user": settings.items_per_user,
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from .config import Settings
|
||||
from .main import app, get_settings
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def get_settings_override():
|
||||
return Settings(admin_email="testing_admin@example.com")
|
||||
|
||||
|
||||
app.dependency_overrides[get_settings] = get_settings_override
|
||||
|
||||
|
||||
def test_app():
|
||||
response = client.get("/info")
|
||||
data = response.json()
|
||||
assert data == {
|
||||
"app_name": "Awesome API",
|
||||
"admin_email": "testing_admin@example.com",
|
||||
"items_per_user": 50,
|
||||
}
|
||||
Reference in New Issue
Block a user