o2o-castad-backend/app/home/tests/test_db.py

35 lines
1.0 KiB
Python

import pytest
from sqlalchemy import text
from app.database.session import AsyncSessionLocal, engine
from app.utils.logger import get_logger
# 로거 설정
logger = get_logger("test_db")
@pytest.mark.asyncio
async def test_database_connection():
"""데이터베이스 연결 테스트"""
async with engine.begin() as connection:
result = await connection.execute(text("SELECT 1"))
assert result.scalar() == 1
@pytest.mark.asyncio
async def test_session_creation():
"""세션 생성 테스트"""
async with AsyncSessionLocal() as session:
result = await session.execute(text("SELECT 1"))
assert result.scalar() == 1
@pytest.mark.asyncio
async def test_database_version():
"""MySQL 버전 확인 테스트"""
async with AsyncSessionLocal() as session:
result = await session.execute(text("SELECT VERSION()"))
version = result.scalar()
assert version is not None
logger.info(f"MySQL Version: {version}")