Files
xiaoxia-saas/tests/unit/test_generated_video.py
xiaoxia e38f13eb96
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Validate - Code Quality (push) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (push) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
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 / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
test: P3-1 第49波单元测试(generated_video/duplication/tts_config/classification,+88) (#837)
2026-07-24 18:58:17 +08:00

140 lines
4.8 KiB
Python
Executable File

"""GeneratedVideo 生成视频领域实体单测."""
import pytest
from packages.domain.generated_video import GeneratedVideo
class TestGeneratedVideoCreate:
def test_create_normal(self):
video = GeneratedVideo.create(
project_id="proj1",
generation_task_id="task1",
name="我的视频",
file_url="https://example.com/video.mp4",
file_size=1024000,
duration=30.5,
width=1920,
height=1080,
fps=30.0,
)
assert video.id
assert video.project_id == "proj1"
assert video.generation_task_id == "task1"
assert video.name == "我的视频"
assert video.file_url == "https://example.com/video.mp4"
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.status == "completed"
assert video.review_status == "pending_review"
assert video.is_duplicate is False
assert video.generation_params == {}
def test_create_strips_whitespace(self):
video = GeneratedVideo.create(
project_id=" proj1 ",
generation_task_id=" task1 ",
name=" 我的视频 ",
file_url=" https://example.com/video.mp4 ",
user_id=" user1 ",
)
assert video.project_id == "proj1"
assert video.generation_task_id == "task1"
assert video.name == "我的视频"
assert video.file_url == "https://example.com/video.mp4"
assert video.user_id == "user1"
def test_create_empty_project_id_raises(self):
with pytest.raises(ValueError, match="project_id cannot be empty"):
GeneratedVideo.create(
project_id="",
generation_task_id="task1",
name="视频",
file_url="https://example.com/v.mp4",
)
def test_create_whitespace_project_id_raises(self):
with pytest.raises(ValueError, match="project_id cannot be empty"):
GeneratedVideo.create(
project_id=" ",
generation_task_id="task1",
name="视频",
file_url="https://example.com/v.mp4",
)
def test_create_empty_generation_task_id_raises(self):
with pytest.raises(ValueError, match="generation_task_id cannot be empty"):
GeneratedVideo.create(
project_id="proj1",
generation_task_id="",
name="视频",
file_url="https://example.com/v.mp4",
)
def test_create_empty_name_raises(self):
with pytest.raises(ValueError, match="name cannot be empty"):
GeneratedVideo.create(
project_id="proj1",
generation_task_id="task1",
name="",
file_url="https://example.com/v.mp4",
)
def test_create_empty_file_url_raises(self):
with pytest.raises(ValueError, match="file_url cannot be empty"):
GeneratedVideo.create(
project_id="proj1",
generation_task_id="task1",
name="视频",
file_url="",
)
def test_create_default_values(self):
video = GeneratedVideo.create(
project_id="proj1",
generation_task_id="task1",
name="视频",
file_url="https://example.com/v.mp4",
)
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.user_id == ""
assert video.generation_params == {}
def test_create_with_generation_params(self):
params = {"mode": "pip", "resolution": "1080p"}
video = GeneratedVideo.create(
project_id="proj1",
generation_task_id="task1",
name="视频",
file_url="https://example.com/v.mp4",
generation_params=params,
)
assert video.generation_params == params
def test_create_none_generation_params(self):
video = GeneratedVideo.create(
project_id="proj1",
generation_task_id="task1",
name="视频",
file_url="https://example.com/v.mp4",
generation_params=None,
)
assert video.generation_params == {}
def test_create_unique_ids(self):
v1 = GeneratedVideo.create(
project_id="proj1", generation_task_id="t1", name="v1", file_url="https://a.com/1.mp4"
)
v2 = GeneratedVideo.create(
project_id="proj1", generation_task_id="t2", name="v2", file_url="https://a.com/2.mp4"
)
assert v1.id != v2.id