feat: 重构测试框架并优化代码结构
refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests style: 为Java类添加文档注释 docs: 更新.gitignore和配置文件 test: 添加性能测试和Playwright测试脚本 chore: 清理旧测试文件和配置
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
import httpx
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
async def test_upload():
|
||||
base_url = "http://localhost:8080"
|
||||
|
||||
# 先登录获取token
|
||||
login_url = f"{base_url}/api/auth/login"
|
||||
login_data = {
|
||||
"username": "admin",
|
||||
"password": "admin123"
|
||||
}
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
# 登录
|
||||
login_response = await client.post(login_url, json=login_data)
|
||||
print(f"Login Status: {login_response.status_code}")
|
||||
if login_response.status_code == 200:
|
||||
token_data = login_response.json()
|
||||
token = token_data.get("token")
|
||||
print(f"Got token: {token[:20]}...")
|
||||
|
||||
# 上传文件
|
||||
upload_url = f"{base_url}/api/files/upload"
|
||||
|
||||
# 创建测试文件
|
||||
test_file_path = "/tmp/test_file.txt"
|
||||
with open(test_file_path, "w") as f:
|
||||
f.write("This is a test file content")
|
||||
|
||||
# 准备文件和数据
|
||||
files = {
|
||||
"file": ("test_file.txt", open(test_file_path, "rb"), "multipart/form-data")
|
||||
}
|
||||
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
# 发送请求
|
||||
response = await client.post(upload_url, files=files, headers=headers)
|
||||
print(f"\nUpload Status Code: {response.status_code}")
|
||||
print(f"Response Headers: {dict(response.headers)}")
|
||||
print(f"Response Body: {response.text}")
|
||||
|
||||
# 清理
|
||||
import os
|
||||
os.remove(test_file_path)
|
||||
else:
|
||||
print(f"Login failed: {login_response.text}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_upload())
|
||||
Reference in New Issue
Block a user