25 changed files with 13 additions and 108 deletions
@ -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="[email protected]") |
|
||||
|
|
||||
|
|
||||
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": "[email protected]", |
|
||||
"items_per_user": 50, |
|
||||
} |
|
||||
@ -1,9 +0,0 @@ |
|||||
from pydantic_settings import BaseSettings, SettingsConfigDict |
|
||||
|
|
||||
|
|
||||
class Settings(BaseSettings): |
|
||||
app_name: str = "Awesome API" |
|
||||
admin_email: str |
|
||||
items_per_user: int = 50 |
|
||||
|
|
||||
model_config = SettingsConfigDict(env_file=".env") |
|
||||
@ -1,10 +0,0 @@ |
|||||
from pydantic import BaseSettings |
|
||||
|
|
||||
|
|
||||
class Settings(BaseSettings): |
|
||||
app_name: str = "Awesome API" |
|
||||
admin_email: str |
|
||||
items_per_user: int = 50 |
|
||||
|
|
||||
class Config: |
|
||||
env_file = ".env" |
|
||||
@ -1,22 +0,0 @@ |
|||||
from functools import lru_cache |
|
||||
|
|
||||
from fastapi import Depends, FastAPI |
|
||||
from typing_extensions import Annotated |
|
||||
|
|
||||
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, |
|
||||
} |
|
||||
Loading…
Reference in new issue