数据库创建

This commit is contained in:
2025-06-22 19:26:23 +08:00
parent 6094d8219e
commit f6825b670f
31 changed files with 1494 additions and 270 deletions

9
tests/conftest.py Normal file
View File

@@ -0,0 +1,9 @@
"""
Pytest配置文件
"""
import pytest
import os
import sys
# 添加项目根目录到Python路径确保可以导入项目模块
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

8
tests/test_database.py Normal file
View File

@@ -0,0 +1,8 @@
from models import database
import pytest
@pytest.mark.asyncio
async def test_initialize_db():
"""Fixture to initialize the database before tests."""
await database.init_db()

23
tests/test_main.py Normal file
View File

@@ -0,0 +1,23 @@
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_read_main():
from pkg.conf.appmeta import BackendVersion
import uuid
response = client.get("/api/site/ping")
json_response = response.json()
assert response.status_code == 200
assert json_response['code'] == 0
assert json_response['data'] == BackendVersion
assert json_response['msg'] is None
assert 'instance_id' in json_response
try:
uuid.UUID(json_response['instance_id'], version=4)
except (ValueError, TypeError):
assert False, f"instance_id is not a valid UUID4: {json_response['instance_id']}"