- Add the 样片模式 flow: 480p draft generation, a linkable draft task ID, and pre-flight verification before the 1080p final request. - Allow reference images and audio in video edit/extend requests, matching the provider's 2.5 contract. - Move 主模型 and 样片模式 ahead of 生成模式, default 主模型 to seedance 2.5, and migrate saved widget values. - Refresh the video panel, asset API response logs, and LLM node handling; cover the new behavior with offline tests.
197 lines
6.2 KiB
Python
197 lines
6.2 KiB
Python
"""统一 Seedance HC 素材创建/查询接口测试。"""
|
|
|
|
import json
|
|
import sys
|
|
import types
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
|
|
PACKAGE_DIR = Path(__file__).resolve().parents[1]
|
|
COMFY_ROOT = PACKAGE_DIR.parent.parent
|
|
sys.path.insert(0, str(COMFY_ROOT))
|
|
sys.path.insert(0, str(PACKAGE_DIR.parent))
|
|
|
|
package = types.ModuleType("comfyui_o1key")
|
|
package.__path__ = [str(PACKAGE_DIR)]
|
|
sys.modules["comfyui_o1key"] = package
|
|
for child in ("utils", "clients"):
|
|
module = types.ModuleType(f"comfyui_o1key.{child}")
|
|
module.__path__ = [str(PACKAGE_DIR / child)]
|
|
sys.modules[f"comfyui_o1key.{child}"] = module
|
|
|
|
from comfyui_o1key.clients.seedance_element_client import SeedanceElementClient
|
|
|
|
|
|
class _FakeResponse:
|
|
def __init__(self, payload, status=200):
|
|
self.status = status
|
|
self._text = json.dumps(payload)
|
|
|
|
async def text(self):
|
|
return self._text
|
|
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, exc_type, exc, traceback):
|
|
return False
|
|
|
|
|
|
class _FakeSession:
|
|
def __init__(self, post_payload=None, get_payload=None):
|
|
self.post_payload = post_payload
|
|
self.get_payload = get_payload
|
|
self.post_call = None
|
|
self.get_call = None
|
|
|
|
def post(self, url, **kwargs):
|
|
self.post_call = (url, kwargs)
|
|
return _FakeResponse(self.post_payload)
|
|
|
|
def get(self, url, **kwargs):
|
|
self.get_call = (url, kwargs)
|
|
return _FakeResponse(self.get_payload)
|
|
|
|
|
|
class SeedanceHCAssetClientTests(unittest.IsolatedAsyncioTestCase):
|
|
def setUp(self):
|
|
self.client = SeedanceElementClient(
|
|
api_key="test-key",
|
|
base_url="https://cf-api.o1key.com",
|
|
)
|
|
|
|
async def test_create_uses_unified_seedance_asset_endpoint(self):
|
|
session = _FakeSession(post_payload={
|
|
"success": True,
|
|
"data": {"Id": "asset-test", "base_resp": {"status_code": 0}},
|
|
})
|
|
|
|
result = await self.client.create_hc_asset(
|
|
name="参考视频1",
|
|
asset_url="https://upload.o1key.com/uploads/reference.mp4",
|
|
asset_type="Video",
|
|
session=session,
|
|
)
|
|
|
|
url, kwargs = session.post_call
|
|
self.assertEqual(url, "https://cf-api.o1key.com/v1/seedance/assets")
|
|
self.assertEqual(kwargs["json"], {
|
|
"type": "hc",
|
|
"url": "https://upload.o1key.com/uploads/reference.mp4",
|
|
"name": "参考视频1",
|
|
"asset_type": "video",
|
|
})
|
|
self.assertEqual(result["Id"], "asset-test")
|
|
|
|
async def test_query_uses_hc_type_query_parameter(self):
|
|
session = _FakeSession(get_payload={
|
|
"success": True,
|
|
"data": {"Id": "asset/a b", "Status": "Active"},
|
|
})
|
|
|
|
result = await self.client.get_hc_asset("asset/a b", session=session)
|
|
|
|
url, kwargs = session.get_call
|
|
self.assertEqual(
|
|
url,
|
|
"https://cf-api.o1key.com/v1/seedance/assets/asset%2Fa%20b",
|
|
)
|
|
self.assertEqual(kwargs["params"], {"type": "hc"})
|
|
self.assertEqual(result["Status"], "Active")
|
|
|
|
async def test_create_omits_empty_optional_name(self):
|
|
session = _FakeSession(post_payload={
|
|
"success": True,
|
|
"data": {"Id": "asset-unnamed"},
|
|
})
|
|
|
|
await self.client.create_hc_asset(
|
|
name="",
|
|
asset_url="https://upload.o1key.com/uploads/reference.png",
|
|
asset_type="image",
|
|
session=session,
|
|
)
|
|
|
|
_, kwargs = session.post_call
|
|
self.assertNotIn("name", kwargs["json"])
|
|
|
|
async def test_doubao_type_is_used_for_create_and_query(self):
|
|
session = _FakeSession(
|
|
post_payload={
|
|
"success": True,
|
|
"data": {"Id": "asset-doubao"},
|
|
},
|
|
get_payload={
|
|
"success": True,
|
|
"data": {"Id": "asset-doubao", "Status": "Active"},
|
|
},
|
|
)
|
|
|
|
await self.client.create_hc_asset(
|
|
name="豆包真人素材",
|
|
asset_url="https://upload.o1key.com/uploads/reference.png",
|
|
asset_type="image",
|
|
session=session,
|
|
request_type="doubao",
|
|
)
|
|
_, create_kwargs = session.post_call
|
|
self.assertEqual(create_kwargs["json"]["type"], "doubao")
|
|
|
|
await self.client.get_hc_asset(
|
|
"asset-doubao",
|
|
session=session,
|
|
request_type="doubao",
|
|
)
|
|
_, query_kwargs = session.get_call
|
|
self.assertEqual(query_kwargs["params"], {"type": "doubao"})
|
|
|
|
async def test_create_logs_full_response_but_folds_signed_urls(self):
|
|
session = _FakeSession(post_payload={
|
|
"success": True,
|
|
"data": {
|
|
"Id": "asset-test",
|
|
"Status": "Active",
|
|
"SourceUrl": "https://upload.example.com/a.png?signature=secret",
|
|
},
|
|
})
|
|
|
|
with patch("builtins.print") as print_mock:
|
|
await self.client.create_hc_asset(
|
|
name="参考图片1",
|
|
asset_url="https://upload.o1key.com/uploads/reference.png",
|
|
asset_type="image",
|
|
session=session,
|
|
)
|
|
|
|
printed = "\n".join(
|
|
str(call.args[0]) for call in print_mock.call_args_list if call.args
|
|
)
|
|
self.assertIn("创建响应体 HTTP 200", printed)
|
|
self.assertIn('"Id": "asset-test"', printed)
|
|
self.assertIn('"Status": "Active"', printed)
|
|
self.assertNotIn("signature=secret", printed)
|
|
|
|
async def test_query_logs_response_only_when_status_changes(self):
|
|
session = _FakeSession(get_payload={
|
|
"success": True,
|
|
"data": {"Id": "asset-q", "Status": "Processing"},
|
|
})
|
|
|
|
with patch("builtins.print") as print_mock:
|
|
await self.client.get_hc_asset("asset-q", session=session)
|
|
await self.client.get_hc_asset("asset-q", session=session)
|
|
|
|
printed = [
|
|
str(call.args[0])
|
|
for call in print_mock.call_args_list
|
|
if call.args
|
|
]
|
|
self.assertEqual(sum("查询响应体" in line for line in printed), 1)
|
|
self.assertIn('"Status": "Processing"', "\n".join(printed))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|