07f6705534
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 36s
CI/CD Pipeline / Frontend Lint (push) Successful in 1m36s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 1m47s
CI/CD Pipeline / Build Staging API Image (push) Successful in 2m15s
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 2m23s
CI/CD Pipeline / Unit Tests (push) Successful in 2m23s
CI/CD Pipeline / Integration Tests (push) Successful in 1m3s
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>
197 lines
6.7 KiB
Python
Executable File
197 lines
6.7 KiB
Python
Executable File
"""generated_video 领域模型单元测试."""
|
|
|
|
import pytest
|
|
from domain.generated_video import GeneratedVideo
|
|
|
|
|
|
class TestGeneratedVideoCreate:
|
|
"""GeneratedVideo.create 工厂方法测试."""
|
|
|
|
def test_create_with_required_fields(self):
|
|
video = GeneratedVideo.create(
|
|
project_id="proj_001",
|
|
generation_task_id="task_001",
|
|
name="测试视频",
|
|
file_url="https://example.com/out.mp4",
|
|
)
|
|
assert video.id
|
|
assert len(video.id) == 32
|
|
assert video.project_id == "proj_001"
|
|
assert video.generation_task_id == "task_001"
|
|
assert video.name == "测试视频"
|
|
assert video.file_url == "https://example.com/out.mp4"
|
|
# 默认值
|
|
assert video.user_id == ""
|
|
assert video.file_size == 0
|
|
assert video.duration == 0.0
|
|
assert video.width == 0
|
|
assert video.height == 0
|
|
assert video.fps == 0.0
|
|
assert video.thumbnail_url is None
|
|
assert video.status == "completed"
|
|
assert video.review_status == "pending_review"
|
|
assert video.generation_params == {}
|
|
assert video.video_fingerprint is None
|
|
assert video.is_duplicate is False
|
|
assert video.duplicate_of is None
|
|
assert video.generated_at is not None
|
|
assert video.created_at is not None
|
|
|
|
def test_create_with_all_fields(self):
|
|
video = GeneratedVideo.create(
|
|
project_id="proj_002",
|
|
generation_task_id="task_002",
|
|
name="完整视频",
|
|
file_url="https://example.com/full.mp4",
|
|
user_id="user_001",
|
|
file_size=1024000,
|
|
duration=30.5,
|
|
width=1920,
|
|
height=1080,
|
|
fps=30.0,
|
|
thumbnail_url="https://example.com/thumb.jpg",
|
|
generation_params={"quality": "high"},
|
|
)
|
|
assert video.user_id == "user_001"
|
|
assert video.file_size == 1024000
|
|
assert video.duration == 30.5
|
|
assert video.width == 1920
|
|
assert video.height == 1080
|
|
assert video.fps == 30.0
|
|
assert video.thumbnail_url == "https://example.com/thumb.jpg"
|
|
assert video.generation_params == {"quality": "high"}
|
|
|
|
def test_create_strips_strings(self):
|
|
video = GeneratedVideo.create(
|
|
project_id=" proj_003 ",
|
|
generation_task_id=" task_003 ",
|
|
name=" 测试视频 ",
|
|
file_url=" https://example.com/out.mp4 ",
|
|
user_id=" user_003 ",
|
|
)
|
|
assert video.project_id == "proj_003"
|
|
assert video.generation_task_id == "task_003"
|
|
assert video.name == "测试视频"
|
|
assert video.file_url == "https://example.com/out.mp4"
|
|
assert video.user_id == "user_003"
|
|
|
|
def test_create_empty_project_id_raises(self):
|
|
with pytest.raises(ValueError, match="project_id"):
|
|
GeneratedVideo.create(
|
|
project_id="",
|
|
generation_task_id="t",
|
|
name="n",
|
|
file_url="u",
|
|
)
|
|
|
|
def test_create_whitespace_project_id_raises(self):
|
|
with pytest.raises(ValueError, match="project_id"):
|
|
GeneratedVideo.create(
|
|
project_id=" ",
|
|
generation_task_id="t",
|
|
name="n",
|
|
file_url="u",
|
|
)
|
|
|
|
def test_create_empty_generation_task_id_raises(self):
|
|
with pytest.raises(ValueError, match="generation_task_id"):
|
|
GeneratedVideo.create(
|
|
project_id="p",
|
|
generation_task_id="",
|
|
name="n",
|
|
file_url="u",
|
|
)
|
|
|
|
def test_create_empty_name_raises(self):
|
|
with pytest.raises(ValueError, match="name"):
|
|
GeneratedVideo.create(
|
|
project_id="p",
|
|
generation_task_id="t",
|
|
name="",
|
|
file_url="u",
|
|
)
|
|
|
|
def test_create_empty_file_url_raises(self):
|
|
with pytest.raises(ValueError, match="file_url"):
|
|
GeneratedVideo.create(
|
|
project_id="p",
|
|
generation_task_id="t",
|
|
name="n",
|
|
file_url="",
|
|
)
|
|
|
|
def test_create_none_generation_params_defaults_to_empty_dict(self):
|
|
video = GeneratedVideo.create(
|
|
project_id="p",
|
|
generation_task_id="t",
|
|
name="n",
|
|
file_url="u",
|
|
generation_params=None,
|
|
)
|
|
assert video.generation_params == {}
|
|
|
|
def test_create_ids_are_unique(self):
|
|
v1 = GeneratedVideo.create(project_id="p", generation_task_id="t1", name="n1", file_url="u1")
|
|
v2 = GeneratedVideo.create(project_id="p", generation_task_id="t2", name="n2", file_url="u2")
|
|
assert v1.id != v2.id
|
|
|
|
def test_create_timestamps_are_utc(self):
|
|
video = GeneratedVideo.create(project_id="p", generation_task_id="t", name="n", file_url="u")
|
|
assert video.created_at.tzinfo is not None
|
|
assert video.generated_at.tzinfo is not None
|
|
|
|
|
|
class TestGeneratedVideoProperties:
|
|
"""GeneratedVideo 属性测试"""
|
|
|
|
def test_default_status_completed(self):
|
|
gv = GeneratedVideo.create(
|
|
project_id="proj-1",
|
|
generation_task_id="task-1",
|
|
name="测试视频",
|
|
file_url="https://example.com/video.mp4",
|
|
)
|
|
assert gv.status == "completed"
|
|
|
|
def test_default_review_status(self):
|
|
gv = GeneratedVideo.create(
|
|
project_id="proj-1",
|
|
generation_task_id="task-1",
|
|
name="测试视频",
|
|
file_url="https://example.com/video.mp4",
|
|
)
|
|
assert gv.review_status == "pending_review"
|
|
|
|
def test_set_status(self):
|
|
gv = GeneratedVideo.create(
|
|
project_id="proj-1",
|
|
generation_task_id="task-1",
|
|
name="测试视频",
|
|
file_url="https://example.com/video.mp4",
|
|
)
|
|
gv.status = "failed"
|
|
assert gv.status == "failed"
|
|
|
|
def test_mark_as_duplicate(self):
|
|
gv = GeneratedVideo.create(
|
|
project_id="proj-1",
|
|
generation_task_id="task-1",
|
|
name="测试视频",
|
|
file_url="https://example.com/video.mp4",
|
|
)
|
|
gv.is_duplicate = True
|
|
gv.duplicate_of = "video-original"
|
|
assert gv.is_duplicate is True
|
|
assert gv.duplicate_of == "video-original"
|
|
|
|
def test_set_fingerprint(self):
|
|
gv = GeneratedVideo.create(
|
|
project_id="proj-1",
|
|
generation_task_id="task-1",
|
|
name="测试视频",
|
|
file_url="https://example.com/video.mp4",
|
|
)
|
|
fingerprint = {"phash": "abc123", "md5": "def456"}
|
|
gv.video_fingerprint = fingerprint
|
|
assert gv.video_fingerprint == fingerprint
|