Sync fastapi docs from 50fa3f7c on 2026-01-11
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
app_name: str = "Awesome API"
|
||||
admin_email: str
|
||||
items_per_user: int = 50
|
||||
@@ -1,22 +0,0 @@
|
||||
from functools import lru_cache
|
||||
|
||||
from fastapi import Depends, FastAPI
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from .config import Settings
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings():
|
||||
return Settings()
|
||||
|
||||
|
||||
@app.get("/info")
|
||||
async def info(settings: Annotated[Settings, Depends(get_settings)]):
|
||||
return {
|
||||
"app_name": settings.app_name,
|
||||
"admin_email": settings.admin_email,
|
||||
"items_per_user": settings.items_per_user,
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
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,
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
from functools import lru_cache
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import Depends, FastAPI
|
||||
|
||||
from . import config
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings():
|
||||
return config.Settings()
|
||||
|
||||
|
||||
@app.get("/info")
|
||||
async def info(settings: Annotated[config.Settings, Depends(get_settings)]):
|
||||
return {
|
||||
"app_name": settings.app_name,
|
||||
"admin_email": settings.admin_email,
|
||||
"items_per_user": settings.items_per_user,
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
@@ -6,5 +6,4 @@ class Settings(BaseSettings):
|
||||
admin_email: str
|
||||
items_per_user: int = 50
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
model_config = SettingsConfigDict(env_file=".env")
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
from pydantic import BaseSettings
|
||||
from pydantic.v1 import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
@@ -1,7 +1,7 @@
|
||||
from functools import lru_cache
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import Depends, FastAPI
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from . import config
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from pydantic.v1 import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
@@ -1,5 +1,5 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseSettings
|
||||
from pydantic.v1 import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
Reference in New Issue
Block a user