2026-02-07 17:25:47 +00:00

24 lines
831 B
Python

import pytest
import asyncio
from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncSession
from backend.database import engine, Base, get_db, init_db
from backend import models # 导入模型以注册表
@pytest.mark.asyncio
async def test_database_connection():
"""测试数据库连接是否正常"""
async with engine.begin() as conn:
result = await conn.execute(text("SELECT 1"))
assert result.scalar() == 1
@pytest.mark.asyncio
async def test_tables_created():
"""测试表是否正确创建"""
await init_db()
async with engine.begin() as conn:
result = await conn.execute(text("SELECT name FROM sqlite_master WHERE type='table'"))
tables = [row[0] for row in result.fetchall()]
assert "channels" in tables
assert "notifications" in tables