Files
novalon-manage-system/api_integration_tests/tests/test_file.py
T
张翔 be5d5ede90 feat: 添加异常日志功能并优化UI样式
refactor: 重构后端查询逻辑和API响应处理

fix: 修复用户角色更新和文件上传问题

test: 添加前端性能测试脚本和E2E测试用例

chore: 更新依赖版本和配置文件

docs: 添加环境检查脚本和测试文档

style: 统一表格标签样式和路由命名

perf: 优化前端页面加载速度和响应时间
2026-03-24 13:32:20 +08:00

115 lines
3.2 KiB
Python

"""
文件管理测试用例
"""
import pytest
import os
import time
from api.file_api import SysFileAPI
@pytest.mark.file
@pytest.mark.regression
class TestSysFile:
"""文件管理测试类"""
@pytest.mark.asyncio
async def test_upload_file(self, authenticated_client):
"""测试文件上传"""
api = SysFileAPI(authenticated_client)
test_file_path = "/tmp/test_file.txt"
with open(test_file_path, "w") as f:
f.write("This is a test file content")
response = await api.upload(test_file_path, "test_user")
os.remove(test_file_path)
assert response.status_code == 201
result = response.json()
assert "id" in result
@pytest.mark.asyncio
async def test_get_all_files(self, authenticated_client):
"""测试获取所有文件"""
api = SysFileAPI(authenticated_client)
response = await api.get_all()
assert response.status_code == 200
assert isinstance(response.json(), list)
@pytest.mark.asyncio
async def test_get_file_by_id(self, authenticated_client):
"""测试根据ID获取文件"""
api = SysFileAPI(authenticated_client)
test_file_path = "/tmp/test_file.txt"
with open(test_file_path, "w") as f:
f.write("Test content")
upload_response = await api.upload(test_file_path, "test_user")
file_id = upload_response.json()["id"]
os.remove(test_file_path)
response = await api.get_by_id(file_id)
assert response.status_code == 200
assert response.json()["id"] == file_id
@pytest.mark.asyncio
async def test_download_file(self, authenticated_client):
"""测试文件下载"""
api = SysFileAPI(authenticated_client)
test_file_path = "/tmp/test_file.txt"
with open(test_file_path, "w") as f:
f.write("Download test content")
upload_response = await api.upload(test_file_path, "test_user")
file_name = upload_response.json()["fileName"]
os.remove(test_file_path)
response = await api.download(file_name)
assert response.status_code == 200
@pytest.mark.asyncio
async def test_preview_file(self, authenticated_client):
"""测试文件预览"""
api = SysFileAPI(authenticated_client)
test_file_path = "/tmp/test_file.txt"
with open(test_file_path, "w") as f:
f.write("Preview test content")
upload_response = await api.upload(test_file_path, "test_user")
file_name = upload_response.json()["fileName"]
os.remove(test_file_path)
response = await api.preview(file_name)
assert response.status_code == 200
@pytest.mark.asyncio
async def test_delete_file(self, authenticated_client):
"""测试删除文件"""
api = SysFileAPI(authenticated_client)
test_file_path = "/tmp/test_file.txt"
with open(test_file_path, "w") as f:
f.write("Delete test content")
upload_response = await api.upload(test_file_path, "test_user")
file_id = upload_response.json()["id"]
os.remove(test_file_path)
response = await api.delete(file_id)
assert response.status_code == 204