forked from xiaohei/taiji-AI-PAD
90 lines
2.4 KiB
Python
90 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试配额分配和使用的修复
|
|
"""
|
|
import requests
|
|
import json
|
|
|
|
BASE_URL = "http://localhost:8002"
|
|
|
|
# 测试数据
|
|
TENANT_ID = "b00a7b8e-9e8b-463d-9593-a3b4d0006778"
|
|
|
|
def test_allocate_resources():
|
|
"""测试分配资源"""
|
|
print("=" * 60)
|
|
print("测试1: 分配 2核4G 配额给租户")
|
|
print("=" * 60)
|
|
|
|
url = f"{BASE_URL}/api/channel/tenants/{TENANT_ID}/resources"
|
|
payload = {
|
|
"customAgentQuota": {
|
|
"cpuQuota": 2,
|
|
"memoryQuota": 4
|
|
}
|
|
}
|
|
|
|
response = requests.put(url, json=payload)
|
|
print(f"状态码: {response.status_code}")
|
|
print(f"响应: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
|
|
|
|
if response.status_code == 200:
|
|
print("✓ 资源分配成功")
|
|
else:
|
|
print("✗ 资源分配失败")
|
|
return False
|
|
|
|
return True
|
|
|
|
def test_create_agent():
|
|
"""测试创建 Agent"""
|
|
print("\n" + "=" * 60)
|
|
print("测试2: 创建 1核2G 的 Agent")
|
|
print("=" * 60)
|
|
|
|
url = f"{BASE_URL}/api/user/tools/generate"
|
|
payload = {
|
|
"name": "test-agent-quota",
|
|
"description": "测试配额修复的 Agent",
|
|
"frameworkTemplate": "A2A",
|
|
"gateway": "MCP",
|
|
"agentCount": 1,
|
|
"cpu": 1,
|
|
"memory": 2,
|
|
"maxScale": 1,
|
|
"model": "taiji/gpt-4o-mini"
|
|
}
|
|
|
|
response = requests.post(url, json=payload)
|
|
print(f"状态码: {response.status_code}")
|
|
print(f"响应: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
|
|
|
|
if response.status_code == 200:
|
|
print("✓ Agent 创建成功")
|
|
return True, response.json().get("data", {}).get("id")
|
|
else:
|
|
print("✗ Agent 创建失败")
|
|
return False, None
|
|
|
|
def main():
|
|
print("开始测试配额分配和使用的修复...\n")
|
|
|
|
# 测试1: 分配资源
|
|
if not test_allocate_resources():
|
|
print("\n配额分配失败,停止测试")
|
|
return
|
|
|
|
# 测试2: 创建 Agent
|
|
success, agent_id = test_create_agent()
|
|
if success:
|
|
print(f"\n测试通过!Agent ID: {agent_id}")
|
|
print("\n说明: 修复已生效")
|
|
print("- 渠道管理员分配的配额已正确写入数据库")
|
|
print("- 租户可以正常使用分配的配额创建 Agent")
|
|
else:
|
|
print("\n测试失败!")
|
|
print("请检查日志以获取更多信息")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|