mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 15:12:08 +01:00
fix(tests): fixed test runtime errors regarding database connection
This commit is contained in:
@@ -28,7 +28,8 @@ from app.services.user_service import SECRET
|
||||
from fastapi import FastAPI
|
||||
import sentry_sdk
|
||||
from fastapi_users.db import SQLAlchemyUserDatabase
|
||||
from app.core.db import async_session_maker
|
||||
from app.core.db import async_session_maker, engine
|
||||
from app.core.base import Base
|
||||
|
||||
sentry_sdk.init(
|
||||
dsn=os.getenv("SENTRY_DSN"),
|
||||
@@ -37,6 +38,14 @@ sentry_sdk.init(
|
||||
|
||||
fastApi = FastAPI()
|
||||
|
||||
@fastApi.on_event("startup")
|
||||
async def on_startup():
|
||||
# Ensure DB schema is created for tests/dev
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
from sqlalchemy import text
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
# CORS for frontend dev server
|
||||
fastApi.add_middleware(
|
||||
CORSMiddleware,
|
||||
|
||||
Reference in New Issue
Block a user