first commit

This commit is contained in:
rjb
2025-12-21 00:20:27 +08:00
commit 6fb3c6c23d
42 changed files with 2265 additions and 0 deletions

4
tests/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
"""
测试模块
"""

34
tests/conftest.py Normal file
View File

@@ -0,0 +1,34 @@
"""
pytest配置文件
定义测试fixtures
"""
import pytest
from src.your_app import create_app, db
from config import TestingConfig
@pytest.fixture
def app():
"""
创建测试应用实例
"""
app = create_app(TestingConfig)
with app.app_context():
db.create_all()
yield app
db.drop_all()
@pytest.fixture
def client(app):
"""
创建测试客户端
"""
return app.test_client()
@pytest.fixture
def runner(app):
"""
创建CLI测试运行器
"""
return app.test_cli_runner()

39
tests/test_example.py Normal file
View File

@@ -0,0 +1,39 @@
"""
示例测试文件
展示如何编写测试
"""
import pytest
from src.your_app import db
from src.your_app.models.example import Example
def test_index(client):
"""
测试首页路由
"""
response = client.get('/')
assert response.status_code == 200
data = response.get_json()
assert data['status'] == 'ok'
def test_health(client):
"""
测试健康检查路由
"""
response = client.get('/health')
assert response.status_code == 200
data = response.get_json()
assert data['status'] == 'healthy'
def test_example_model(app):
"""
测试示例模型
"""
with app.app_context():
example = Example(name='Test', description='Test description')
db.session.add(example)
db.session.commit()
assert example.id is not None
assert example.name == 'Test'
assert example.description == 'Test description'