feat: setup FastAPI main app with routers and test fixtures
- Main FastAPI app with all routers included - CORS middleware for frontend - Test fixtures with in-memory SQLite database - Placeholder routers for future tasks
This commit is contained in:
+23
-2
@@ -1,7 +1,8 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from contextlib import asynccontextmanager
|
||||
from app.database import engine, Base
|
||||
from app.routers import sources, jobs
|
||||
from app.routers import sources, jobs, executions, backups, settings, dashboard
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
@@ -9,7 +10,27 @@ async def lifespan(app: FastAPI):
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
yield
|
||||
|
||||
app = FastAPI(title="Backup Tool API", lifespan=lifespan)
|
||||
app = FastAPI(
|
||||
title="Backup Tool API",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:3000"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(sources.router)
|
||||
app.include_router(jobs.router)
|
||||
app.include_router(executions.router)
|
||||
app.include_router(backups.router)
|
||||
app.include_router(settings.router)
|
||||
app.include_router(dashboard.router)
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health_check():
|
||||
return {"status": "healthy"}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(prefix="/api/backups", tags=["backups"])
|
||||
# Will be implemented in later tasks
|
||||
@@ -0,0 +1,4 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(prefix="/api/dashboard", tags=["dashboard"])
|
||||
# Will be implemented in later tasks
|
||||
@@ -0,0 +1,4 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(prefix="/api/executions", tags=["executions"])
|
||||
# Will be implemented in later tasks
|
||||
@@ -0,0 +1,4 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(prefix="/api/settings", tags=["settings"])
|
||||
# Will be implemented in later tasks
|
||||
@@ -0,0 +1,32 @@
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
||||
from app.database import Base, get_db
|
||||
from app.main import app
|
||||
from httpx import AsyncClient
|
||||
|
||||
TEST_DATABASE_URL = "sqlite+aiosqlite:///./test.db"
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def db():
|
||||
engine = create_async_engine(TEST_DATABASE_URL, echo=False)
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||
async with async_session() as session:
|
||||
yield session
|
||||
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.drop_all)
|
||||
await engine.dispose()
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def client(db):
|
||||
async def override_get_db():
|
||||
yield db
|
||||
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
async with AsyncClient(app=app, base_url="http://test") as ac:
|
||||
yield ac
|
||||
app.dependency_overrides.clear()
|
||||
Reference in New Issue
Block a user