2e67be39f7
AI Code Review / AI Code Review (pull_request) Failing after 0s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 6s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m24s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 51s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m26s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 1m46s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 43s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 43s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 32s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 46s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m57s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m48s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m47s
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m43s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Failing after 23s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 25s
- module_registry: 新增42个测试 - Module状态转换(6个) - 注册补充场景(5个) - 能力查询补充(9个) - 依赖检查补充(4个) - list_modules补充(3个) - QuotaRule补充(3个) - ModuleCapability补充(3个) - subtitle_domain: 新增19个测试 - merge_short_segments补充(6个) - split_long_segments补充(5个) - _split_text_by_punctuation补充(8个) - voice_library_domain: 新增13个测试 - 各种status状态 - 零值/大值边界 - 标签、元数据、project_id
168 lines
5.6 KiB
Python
Executable File
168 lines
5.6 KiB
Python
Executable File
"""
|
|
VoiceLibraryItem 配音库领域模型单元测试
|
|
"""
|
|
|
|
from packages.domain.voice_library import VoiceLibraryItem
|
|
|
|
|
|
class TestVoiceLibraryItem:
|
|
"""VoiceLibraryItem 测试"""
|
|
|
|
def test_create_minimal(self):
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="我的配音")
|
|
assert item.id == "v1"
|
|
assert item.user_id == "u1"
|
|
assert item.name == "我的配音"
|
|
|
|
def test_default_values(self):
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n")
|
|
assert item.text == ""
|
|
assert item.voice_provider == ""
|
|
assert item.voice_id == ""
|
|
assert item.voice_name == ""
|
|
assert item.audio_url == ""
|
|
assert item.duration == 0
|
|
assert item.file_size == 0
|
|
assert item.status == "completed"
|
|
assert item.project_id is None
|
|
assert item.tags == []
|
|
assert item.metadata_ == {}
|
|
|
|
def test_with_voice_info(self):
|
|
item = VoiceLibraryItem(
|
|
id="v1",
|
|
user_id="u1",
|
|
name="温柔女声",
|
|
text="大家好",
|
|
voice_provider="cosyvoice",
|
|
voice_id="longxiaochun_v3",
|
|
voice_name="龙小淳",
|
|
)
|
|
assert item.voice_provider == "cosyvoice"
|
|
assert item.voice_id == "longxiaochun_v3"
|
|
assert item.voice_name == "龙小淳"
|
|
|
|
def test_with_audio_info(self):
|
|
item = VoiceLibraryItem(
|
|
id="v1",
|
|
user_id="u1",
|
|
name="n",
|
|
audio_url="https://example.com/audio.wav",
|
|
duration=15.5,
|
|
file_size=102400,
|
|
)
|
|
assert item.audio_url == "https://example.com/audio.wav"
|
|
assert item.duration == 15.5
|
|
assert item.file_size == 102400
|
|
|
|
def test_with_project_id(self):
|
|
item = VoiceLibraryItem(
|
|
id="v1",
|
|
user_id="u1",
|
|
name="n",
|
|
project_id="proj-123",
|
|
)
|
|
assert item.project_id == "proj-123"
|
|
|
|
def test_status_values(self):
|
|
for status in ["pending", "processing", "completed", "failed"]:
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", status=status)
|
|
assert item.status == status
|
|
|
|
def test_with_tags(self):
|
|
item = VoiceLibraryItem(
|
|
id="v1",
|
|
user_id="u1",
|
|
name="n",
|
|
tags=["温柔", "女声", "解说"],
|
|
)
|
|
assert len(item.tags) == 3
|
|
assert "温柔" in item.tags
|
|
|
|
def test_with_metadata(self):
|
|
item = VoiceLibraryItem(
|
|
id="v1",
|
|
user_id="u1",
|
|
name="n",
|
|
metadata_={"speed": 1.0, "pitch": 0.5},
|
|
)
|
|
assert item.metadata_["speed"] == 1.0
|
|
assert item.metadata_["pitch"] == 0.5
|
|
|
|
def test_has_timestamps(self):
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n")
|
|
assert item.created_at is not None
|
|
assert item.updated_at is not None
|
|
|
|
|
|
# ── VoiceLibraryItem 更多边界测试 ──────────────────────────────────────
|
|
|
|
|
|
class TestVoiceLibraryItemMore:
|
|
"""VoiceLibraryItem 补充测试."""
|
|
|
|
def test_status_pending(self):
|
|
"""pending状态."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", status="pending")
|
|
assert item.status == "pending"
|
|
|
|
def test_status_processing(self):
|
|
"""processing状态."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", status="processing")
|
|
assert item.status == "processing"
|
|
|
|
def test_status_failed(self):
|
|
"""failed状态."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", status="failed")
|
|
assert item.status == "failed"
|
|
|
|
def test_zero_duration_and_size(self):
|
|
"""零时长零大小."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", duration=0, file_size=0)
|
|
assert item.duration == 0
|
|
assert item.file_size == 0
|
|
|
|
def test_large_duration_and_size(self):
|
|
"""大时长大文件."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", duration=3600.0, file_size=1024 * 1024 * 100)
|
|
assert item.duration == 3600.0
|
|
assert item.file_size == 104857600
|
|
|
|
def test_empty_tags_list(self):
|
|
"""空标签列表."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", tags=[])
|
|
assert item.tags == []
|
|
|
|
def test_many_tags(self):
|
|
"""多个标签."""
|
|
tags = ["温柔", "女声", "情感", "治愈", "朗读", "故事"]
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", tags=tags)
|
|
assert len(item.tags) == 6
|
|
assert "治愈" in item.tags
|
|
|
|
def test_empty_metadata(self):
|
|
"""空元数据."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n")
|
|
assert item.metadata_ == {}
|
|
|
|
def test_metadata_with_nested_values(self):
|
|
"""嵌套元数据."""
|
|
meta = {
|
|
"settings": {"speed": 1.0, "pitch": 0.5},
|
|
"source": "upload",
|
|
"version": 2,
|
|
}
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", metadata_=meta)
|
|
assert item.metadata_["settings"]["speed"] == 1.0
|
|
assert item.metadata_["source"] == "upload"
|
|
|
|
def test_project_id_none_by_default(self):
|
|
"""默认project_id为None."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n")
|
|
assert item.project_id is None
|
|
|
|
def test_project_id_set(self):
|
|
"""设置project_id."""
|
|
item = VoiceLibraryItem(id="v1", user_id="u1", name="n", project_id="proj-abc-123")
|
|
assert item.project_id == "proj-abc-123"
|