Files
novalon-manage-system/test-suite/tests/integration/test_config.py
T
张翔 1e3dc11d59 refactor(test): 重构测试套件结构并优化测试配置
feat(test-suite): 新增测试套件模块,包含API测试客户端和测试配置
fix(api): 修复数据库实体和仓库的删除操作返回值
style(api): 统一数据库表名和字段命名
perf(api): 添加缓存注解提升配置查询性能
test(api): 添加H2测试数据库配置支持
chore: 清理旧的测试文件和脚本
2026-04-01 20:57:24 +08:00

106 lines
3.3 KiB
Python

"""
系统配置测试用例
"""
import pytest
import time
from api.config_api import SysConfigAPI
@pytest.mark.config
@pytest.mark.regression
class TestSysConfig:
"""系统参数配置测试类"""
@pytest.mark.asyncio
async def test_create_config_success(self, authenticated_client):
"""测试创建系统配置成功"""
api = SysConfigAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"configName": f"测试配置_{timestamp}",
"configKey": f"test.config.key.{timestamp}",
"configValue": "test_value",
"configType": "N"
}
response = await api.create(data)
assert response.status_code == 201
result = response.json()
assert result["configName"] == data["configName"]
assert result["configKey"] == data["configKey"]
@pytest.mark.asyncio
async def test_get_all_configs(self, authenticated_client):
"""测试获取所有配置"""
api = SysConfigAPI(authenticated_client)
response = await api.get_all()
assert response.status_code == 200
assert isinstance(response.json(), list)
@pytest.mark.asyncio
async def test_get_config_by_key(self, authenticated_client):
"""测试根据key获取配置"""
api = SysConfigAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"configName": f"测试配置_{timestamp}",
"configKey": f"test.config.key.{timestamp}",
"configValue": "test_value",
"configType": "N"
}
create_response = await api.create(data)
config_key = data["configKey"]
response = await api.get_config_by_key(config_key)
assert response.status_code == 200
result = response.json()
assert result["configKey"] == config_key
@pytest.mark.asyncio
async def test_update_config(self, authenticated_client):
"""测试更新配置"""
api = SysConfigAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"configName": f"测试配置_{timestamp}",
"configKey": f"test.config.key.{timestamp}",
"configValue": "old_value",
"configType": "N"
}
create_response = await api.create(data)
config_id = create_response.json()["id"]
update_data = {
"configName": f"更新后_{timestamp}",
"configKey": f"test.config.key.{timestamp}",
"configValue": "new_value",
"configType": "N"
}
response = await api.update(config_id, update_data)
assert response.status_code == 200
assert response.json()["configValue"] == "new_value"
@pytest.mark.asyncio
async def test_delete_config(self, authenticated_client):
"""测试删除配置"""
api = SysConfigAPI(authenticated_client)
timestamp = int(time.time() * 1000)
data = {
"configName": f"测试配置_{timestamp}",
"configKey": f"test.config.key.{timestamp}",
"configValue": "test_value",
"configType": "N"
}
create_response = await api.create(data)
config_id = create_response.json()["id"]
response = await api.delete(config_id)
assert response.status_code == 204