Files
aitsc/config/testing.py

65 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import tempfile
from .base import Config
class TestingConfig(Config):
"""
测试环境配置
"""
DEBUG = False
TESTING = True
# 测试环境数据库配置(使用内存数据库)
SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
# 测试环境日志配置
LOG_LEVEL = 'DEBUG'
LOG_FILE = 'logs/test.log'
# 测试环境缓存配置
CACHE_TYPE = 'simple'
CACHE_DEFAULT_TIMEOUT = 10 # 测试环境缓存时间很短
# 测试环境安全配置
WTF_CSRF_ENABLED = False # 测试环境关闭CSRF保护
WTF_CSRF_TIME_LIMIT = 300
# 测试环境会话配置
SESSION_LIFETIME_HOURS = 1
# 测试环境文件上传配置
MAX_CONTENT_LENGTH = 1 * 1024 * 1024 # 1MB
UPLOAD_FOLDER = tempfile.mkdtemp()
# 测试环境跨域配置
CORS_ORIGINS = ['*']
# 测试环境API配置使用测试密钥
LLM_API_KEY = 'test-api-key'
WX_APPID = 'test-wx-appid'
WX_SECRET = 'test-wx-secret'
# 测试环境性能配置
SQLALCHEMY_ENGINE_OPTIONS = {
'pool_pre_ping': False, # 测试环境关闭连接池检查
'pool_recycle': -1,
}
@staticmethod
def init_app(app):
Config.init_app(app)
# 测试环境特定初始化
import logging
app.logger.setLevel(logging.DEBUG)
# 测试环境控制台输出
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s'
))
app.logger.addHandler(console_handler)
app.logger.info('测试环境启动')