forked from iti-framework/iTi-Flask
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.4 KiB
Python
92 lines
2.4 KiB
Python
"""
|
|
配置测试
|
|
"""
|
|
import pytest
|
|
from iti.applications import create_app
|
|
from config import DevConfig, TestConfig, ProdConfig, get_config
|
|
|
|
|
|
class TestConfig2:
|
|
"""配置测试类"""
|
|
|
|
def test_dev_config(self):
|
|
"""测试开发环境配置"""
|
|
app = create_app('dev')
|
|
|
|
assert app.config['DEBUG'] is True
|
|
assert app.config['TESTING'] is False
|
|
assert 'sqlite' in app.config['SQLALCHEMY_DATABASE_URI'].lower()
|
|
|
|
def test_test_config(self):
|
|
"""测试测试环境配置"""
|
|
app = create_app('test')
|
|
|
|
assert app.config['DEBUG'] is False
|
|
assert app.config['TESTING'] is True
|
|
assert ':memory:' in app.config['SQLALCHEMY_DATABASE_URI']
|
|
assert app.config['RATELIMIT_ENABLED'] is False
|
|
|
|
def test_prod_config(self):
|
|
"""测试生产环境配置"""
|
|
app = create_app('prod')
|
|
|
|
assert app.config['DEBUG'] is False
|
|
assert app.config['TESTING'] is False
|
|
|
|
def test_config_classes(self):
|
|
"""测试配置类"""
|
|
dev_config = DevConfig()
|
|
test_config = TestConfig()
|
|
prod_config = ProdConfig()
|
|
|
|
# 开发环境
|
|
assert dev_config.DEBUG is True
|
|
assert dev_config.SQLALCHEMY_ECHO is True
|
|
|
|
# 测试环境
|
|
assert test_config.TESTING is True
|
|
assert test_config.RATELIMIT_ENABLED is False
|
|
|
|
# 生产环境
|
|
assert prod_config.DEBUG is False
|
|
|
|
def test_get_config(self):
|
|
"""测试配置获取函数"""
|
|
dev_config = get_config('dev')
|
|
assert dev_config == DevConfig
|
|
|
|
test_config = get_config('test')
|
|
assert test_config == TestConfig
|
|
|
|
prod_config = get_config('prod')
|
|
assert prod_config == ProdConfig
|
|
|
|
# 测试默认配置
|
|
default_config = get_config('unknown')
|
|
assert default_config == DevConfig
|
|
|
|
|
|
@pytest.fixture
|
|
def app():
|
|
"""创建测试应用"""
|
|
return create_app('test')
|
|
|
|
|
|
@pytest.fixture
|
|
def client(app):
|
|
"""创建测试客户端"""
|
|
return app.test_client()
|
|
|
|
|
|
def test_app_creation(app):
|
|
"""测试应用创建"""
|
|
assert app is not None
|
|
assert app.config['TESTING'] is True
|
|
|
|
|
|
def test_app_context(app):
|
|
"""测试应用上下文"""
|
|
with app.app_context():
|
|
assert app.config['TESTING'] is True
|
|
|