feat: AI平台适配器(DeepSeek/Kimi/Open余额查询+Minimax骨架)+ capabilities按钮控制,测试17项通过
This commit is contained in:
@@ -9,6 +9,7 @@ import base64
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.adapters import registry
|
||||
from app.adapters.ai import DeepSeekAdapter, KimiAdapter, OpenAIAdapter
|
||||
from app.adapters.aliyun import AliyunAdapter
|
||||
from app.adapters.cloudflare import CloudflareAdapter
|
||||
from app.adapters.digitalocean import DigitalOceanAdapter
|
||||
@@ -172,3 +173,50 @@ def test_registry_get_adapter_routing():
|
||||
assert isinstance(registry.get_adapter("alibabacloud-sdk", {}), AliyunAdapter)
|
||||
assert isinstance(registry.get_adapter("tencent-sdk", {}), TencentAdapter)
|
||||
assert isinstance(registry.get_adapter("tencent-intl-sdk", {}), TencentAdapter)
|
||||
|
||||
|
||||
# --------------------------- AI 平台适配器 --------------------------- #
|
||||
def test_deepseek_balance_normalization():
|
||||
adapter = DeepSeekAdapter({"api_key": "x"})
|
||||
mock = {"data": {"total_balance": "88.50", "granted_balance": "10.00"}}
|
||||
with patch.object(DeepSeekAdapter, "_get", return_value=mock):
|
||||
acc = adapter.get_account()
|
||||
assert acc.balance == 88.5 # 字符串 -> float
|
||||
assert acc.currency == "CNY"
|
||||
|
||||
|
||||
def test_deepseek_test_connection_includes_balance():
|
||||
adapter = DeepSeekAdapter({"api_key": "x"})
|
||||
with patch.object(DeepSeekAdapter, "_get", return_value={"data": {"total_balance": "88.50"}}):
|
||||
result = adapter.test_connection()
|
||||
assert result["ok"] is True
|
||||
assert "88.5" in result["message"]
|
||||
|
||||
|
||||
def test_kimi_balance_normalization():
|
||||
adapter = KimiAdapter({"api_key": "x"})
|
||||
with patch.object(KimiAdapter, "_get", return_value={"data": {"available_balance": 123.45}}):
|
||||
acc = adapter.get_account()
|
||||
assert acc.balance == 123.45
|
||||
assert acc.currency == "CNY"
|
||||
|
||||
|
||||
def test_openai_test_connection_models():
|
||||
adapter = OpenAIAdapter({"api_key": "x"})
|
||||
mock = {"data": [{"id": "gpt-4"}, {"id": "gpt-3.5-turbo"}]}
|
||||
with patch.object(OpenAIAdapter, "_get", return_value=mock):
|
||||
result = adapter.test_connection()
|
||||
assert result["ok"] is True
|
||||
assert "2" in result["message"]
|
||||
|
||||
|
||||
def test_ai_capabilities_account_only():
|
||||
caps = DeepSeekAdapter({"api_key": "x"}).capabilities()
|
||||
assert caps["get_account"] is True
|
||||
assert caps["list_vps"] is False
|
||||
assert caps["list_domains"] is False
|
||||
|
||||
|
||||
def test_registry_supports_ai_types():
|
||||
for t in ["deepseek-api", "moonshot-api", "openai-api", "minimax-api"]:
|
||||
assert registry.is_supported(t), f"{t} 应被支持"
|
||||
|
||||
Reference in New Issue
Block a user