abc3fbea1b
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Successful in 34s
CI/CD Pipeline / Frontend Lint (push) Successful in 1m35s
CI/CD Pipeline / Build Staging API Image (push) Successful in 2m14s
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 2m23s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 2m25s
CI/CD Pipeline / Unit Tests (push) Successful in 2m42s
CI/CD Pipeline / Integration Tests (push) Successful in 1m4s
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
Co-authored-by: CI Bot <dev@xiaoxiajianji.com> Co-committed-by: CI Bot <dev@xiaoxiajianji.com>
154 lines
4.5 KiB
Python
154 lines
4.5 KiB
Python
"""
|
|
Template 模板领域模型单元测试
|
|
"""
|
|
|
|
from domain.template import Template, TemplateCategory, TemplateSegment
|
|
|
|
|
|
class TestTemplateSegment:
|
|
"""TemplateSegment 测试"""
|
|
|
|
def test_create_segment(self):
|
|
seg = TemplateSegment(
|
|
id="seg-1",
|
|
template_id="tpl-1",
|
|
segment_order=1,
|
|
duration_min=3.0,
|
|
duration_max=5.0,
|
|
)
|
|
assert seg.id == "seg-1"
|
|
assert seg.template_id == "tpl-1"
|
|
assert seg.segment_order == 1
|
|
assert seg.duration_min == 3.0
|
|
assert seg.duration_max == 5.0
|
|
assert seg.material_type is None
|
|
|
|
def test_segment_with_material_type(self):
|
|
seg = TemplateSegment(
|
|
id="seg-1",
|
|
template_id="tpl-1",
|
|
segment_order=0,
|
|
duration_min=2.0,
|
|
duration_max=4.0,
|
|
material_type="人物",
|
|
)
|
|
assert seg.material_type == "人物"
|
|
|
|
def test_segment_has_timestamps(self):
|
|
seg = TemplateSegment(
|
|
id="seg-1",
|
|
template_id="tpl-1",
|
|
segment_order=1,
|
|
duration_min=1.0,
|
|
duration_max=2.0,
|
|
)
|
|
assert seg.created_at is not None
|
|
assert seg.updated_at is not None
|
|
|
|
|
|
class TestTemplate:
|
|
"""Template 测试"""
|
|
|
|
def test_create_template_minimal(self):
|
|
t = Template(
|
|
id="tpl-1",
|
|
user_id="user-1",
|
|
name="测试模板",
|
|
mode="one_take",
|
|
)
|
|
assert t.id == "tpl-1"
|
|
assert t.user_id == "user-1"
|
|
assert t.name == "测试模板"
|
|
assert t.mode == "one_take"
|
|
|
|
def test_default_values(self):
|
|
t = Template(id="tpl-1", user_id="u1", name="n", mode="one_take")
|
|
assert t.category == ""
|
|
assert t.tags == []
|
|
assert t.title_config == {}
|
|
assert t.subtitle_config == {}
|
|
assert t.bgm_config == {}
|
|
assert t.estimated_duration == 0.0
|
|
assert t.segments == []
|
|
assert t.is_active is True
|
|
|
|
def test_with_segments(self):
|
|
segs = [
|
|
TemplateSegment(id="s1", template_id="t1", segment_order=0, duration_min=2, duration_max=4),
|
|
TemplateSegment(id="s2", template_id="t1", segment_order=1, duration_min=3, duration_max=5),
|
|
]
|
|
t = Template(
|
|
id="tpl-1",
|
|
user_id="u1",
|
|
name="n",
|
|
mode="voice_over",
|
|
segments=segs,
|
|
)
|
|
assert len(t.segments) == 2
|
|
assert t.segments[0].segment_order == 0
|
|
assert t.segments[1].segment_order == 1
|
|
|
|
def test_all_modes(self):
|
|
for mode in ["pip", "voice_pip", "one_take", "voice_over"]:
|
|
t = Template(id="t1", user_id="u1", name="n", mode=mode)
|
|
assert t.mode == mode
|
|
|
|
def test_with_configs(self):
|
|
t = Template(
|
|
id="t1",
|
|
user_id="u1",
|
|
name="n",
|
|
mode="one_take",
|
|
title_config={"font_size": 24, "color": "#ffffff"},
|
|
subtitle_config={"style": "bottom"},
|
|
bgm_config={"volume": 0.5},
|
|
)
|
|
assert t.title_config["font_size"] == 24
|
|
assert t.subtitle_config["style"] == "bottom"
|
|
assert t.bgm_config["volume"] == 0.5
|
|
|
|
def test_estimated_duration(self):
|
|
t = Template(
|
|
id="t1",
|
|
user_id="u1",
|
|
name="n",
|
|
mode="one_take",
|
|
estimated_duration=30.5,
|
|
)
|
|
assert t.estimated_duration == 30.5
|
|
|
|
def test_is_active_false(self):
|
|
t = Template(id="t1", user_id="u1", name="n", mode="one_take", is_active=False)
|
|
assert t.is_active is False
|
|
|
|
def test_has_timestamps(self):
|
|
t = Template(id="t1", user_id="u1", name="n", mode="one_take")
|
|
assert t.created_at is not None
|
|
assert t.updated_at is not None
|
|
|
|
def test_tags_list(self):
|
|
t = Template(
|
|
id="t1",
|
|
user_id="u1",
|
|
name="n",
|
|
mode="one_take",
|
|
tags=["风景", "vlog"],
|
|
)
|
|
assert "风景" in t.tags
|
|
assert "vlog" in t.tags
|
|
assert len(t.tags) == 2
|
|
|
|
|
|
class TestTemplateCategory:
|
|
"""TemplateCategory 测试"""
|
|
|
|
def test_create_category(self):
|
|
cat = TemplateCategory(id="cat-1", user_id="u1", name="风景")
|
|
assert cat.id == "cat-1"
|
|
assert cat.user_id == "u1"
|
|
assert cat.name == "风景"
|
|
|
|
def test_category_has_timestamp(self):
|
|
cat = TemplateCategory(id="cat-1", user_id="u1", name="风景")
|
|
assert cat.created_at is not None
|