refactor(test): 重构测试套件结构并优化测试配置
feat(test-suite): 新增测试套件模块,包含API测试客户端和测试配置 fix(api): 修复数据库实体和仓库的删除操作返回值 style(api): 统一数据库表名和字段命名 perf(api): 添加缓存注解提升配置查询性能 test(api): 添加H2测试数据库配置支持 chore: 清理旧的测试文件和脚本
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
文件管理 API 客户端
|
||||
"""
|
||||
|
||||
from httpx import AsyncClient
|
||||
import io
|
||||
|
||||
|
||||
class FileAPI:
|
||||
"""文件管理 API 客户端"""
|
||||
|
||||
def __init__(self, client: AsyncClient):
|
||||
self.client = client
|
||||
|
||||
async def get_file_list(self):
|
||||
"""获取文件列表"""
|
||||
return await self.client.get('/api/files')
|
||||
|
||||
async def get_file_by_id(self, file_id):
|
||||
"""根据ID获取文件"""
|
||||
return await self.client.get(f'/api/files/{file_id}')
|
||||
|
||||
async def upload(self, file_path, upload_user):
|
||||
"""上传文件"""
|
||||
with open(file_path, 'rb') as f:
|
||||
return await self.client.post('/api/files/upload', json={'file': file_path, 'uploadUser': upload_user})
|
||||
|
||||
async def upload_file(self, file_content, filename, upload_user="test_user"):
|
||||
"""上传文件(内存方式)"""
|
||||
files = {'file': (filename, file_content, 'text/plain')}
|
||||
headers = {'X-Username': upload_user}
|
||||
return await self.client.post('/api/files/upload', files=files, headers=headers)
|
||||
|
||||
async def download(self, file_id):
|
||||
"""下载文件"""
|
||||
return await self.client.get(f'/api/files/{file_id}/download')
|
||||
|
||||
async def delete(self, file_id):
|
||||
"""删除文件"""
|
||||
return await self.client.delete(f'/api/files/{file_id}')
|
||||
|
||||
async def get_file_info(self, file_id):
|
||||
"""获取文件信息(别名)"""
|
||||
return await self.get_file_by_id(file_id)
|
||||
|
||||
async def download_file(self, file_id):
|
||||
"""下载文件(别名)"""
|
||||
return await self.download(file_id)
|
||||
|
||||
async def delete_file(self, file_id):
|
||||
"""删除文件(别名)"""
|
||||
return await self.delete(file_id)
|
||||
|
||||
|
||||
class SysFileAPI(FileAPI):
|
||||
"""系统文件 API (别名)"""
|
||||
pass
|
||||
Reference in New Issue
Block a user