7e505a04c7
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
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
73 lines
2.1 KiB
Python
Executable File
73 lines
2.1 KiB
Python
Executable File
"""素材入库任务 UseCase 单元测试."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
from packages.application.ingest_jobs import (
|
|
SubmitIngestJobCommand,
|
|
SubmitIngestJobUseCase,
|
|
)
|
|
from packages.domain import IngestJob
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_repo():
|
|
return MagicMock()
|
|
|
|
|
|
class TestSubmitIngestJobUseCase:
|
|
"""SubmitIngestJobUseCase 测试"""
|
|
|
|
def test_submit_job_success(self, mock_repo):
|
|
"""正常提交入库任务"""
|
|
mock_repo.create.side_effect = lambda j: j
|
|
use_case = SubmitIngestJobUseCase(mock_repo)
|
|
|
|
command = SubmitIngestJobCommand(
|
|
project_id="proj_001",
|
|
library_id="lib_001",
|
|
storage_key="videos/test.mp4",
|
|
file_hash="abc123def",
|
|
)
|
|
result = use_case.execute(command)
|
|
|
|
assert isinstance(result, IngestJob)
|
|
assert result.project_id == "proj_001"
|
|
assert result.library_id == "lib_001"
|
|
assert result.storage_key == "videos/test.mp4"
|
|
assert result.file_hash == "abc123def"
|
|
mock_repo.create.assert_called_once()
|
|
|
|
def test_submit_job_without_hash(self, mock_repo):
|
|
"""不传 file_hash 时默认为空"""
|
|
mock_repo.create.side_effect = lambda j: j
|
|
use_case = SubmitIngestJobUseCase(mock_repo)
|
|
|
|
command = SubmitIngestJobCommand(
|
|
project_id="proj_001",
|
|
library_id="lib_001",
|
|
storage_key="images/test.png",
|
|
)
|
|
result = use_case.execute(command)
|
|
|
|
assert result.file_hash == ""
|
|
mock_repo.create.assert_called_once()
|
|
|
|
def test_submit_job_returns_repo_result(self, mock_repo):
|
|
"""返回 repository.create 的结果"""
|
|
expected_job = MagicMock(spec=IngestJob)
|
|
mock_repo.create.return_value = expected_job
|
|
|
|
use_case = SubmitIngestJobUseCase(mock_repo)
|
|
command = SubmitIngestJobCommand(
|
|
project_id="proj_001",
|
|
library_id="lib_001",
|
|
storage_key="test.mp4",
|
|
)
|
|
result = use_case.execute(command)
|
|
|
|
assert result is expected_job
|