From 09b8b2990fe21d704d62f6bd44ce0a040a3aa8c2 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 1 Oct 2026 04:38:58 +0800 Subject: [PATCH] test: fix unit tests to match TTS import path and storage_service.get_url mock - test_viral_video_p0: patch new apps.worker.services.tts_service_factory path, assert format='mp3' is passed - test_prepare_dedup: storage_service.get_url.return_value = '' so DirectUploadPrepareResponse.url: str doesn't receive a MagicMock --- tests/unit/test_prepare_dedup_1714.py | 3 +++ tests/unit/test_viral_video_p0.py | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_prepare_dedup_1714.py b/tests/unit/test_prepare_dedup_1714.py index cb0ad9ff8..689fa618d 100644 --- a/tests/unit/test_prepare_dedup_1714.py +++ b/tests/unit/test_prepare_dedup_1714.py @@ -144,6 +144,9 @@ def _storage(): "expires_at": "2026-01-01T00:00:00Z", "fields": {"key": "uploads/abc/test.mp4"}, } + # Bug #2110: duplicated 命中时 _get_existing_asset_url 调用 get_url 返回公网 URL 字符串, + # Mock 默认返回 MagicMock,会让 DirectUploadPrepareResponse.url: str 校验失败。 + s.get_url.return_value = "" return s diff --git a/tests/unit/test_viral_video_p0.py b/tests/unit/test_viral_video_p0.py index d5d98b8c4..76ccd31b0 100644 --- a/tests/unit/test_viral_video_p0.py +++ b/tests/unit/test_viral_video_p0.py @@ -120,7 +120,7 @@ class TestTTSPath: """get_tts_service 抛 ImportError 时 _step_tts 返回 None。""" from apps.worker.worker_app.tasks import viral_video as vv - with patch("services.tts_service_factory.get_tts_service", side_effect=ImportError("no tts")): + with patch("apps.worker.services.tts_service_factory.get_tts_service", side_effect=ImportError("no tts")): assert vv._step_tts(mock_job, "文案") is None def test_tts_returns_none_when_path_not_exists(self, mock_job, tmp_path): @@ -128,7 +128,7 @@ class TestTTSPath: fake_service = MagicMock() fake_service.synthesize.return_value = str(tmp_path / "not_exist.mp3") - with patch("services.tts_service_factory.get_tts_service", return_value=fake_service): + with patch("apps.worker.services.tts_service_factory.get_tts_service", return_value=fake_service): assert vv._step_tts(mock_job, "文案") is None def test_tts_returns_path_when_exists(self, mock_job, tmp_path): @@ -138,8 +138,11 @@ class TestTTSPath: audio.write_bytes(b"ID3fake") fake_service = MagicMock() fake_service.synthesize.return_value = audio - with patch("services.tts_service_factory.get_tts_service", return_value=fake_service): + with patch("apps.worker.services.tts_service_factory.get_tts_service", return_value=fake_service): result = vv._step_tts(mock_job, "文案") + # Bug #2110: 校验传入了 voice_id+format=mp3 + call_kwargs = fake_service.synthesize.call_args.kwargs + assert call_kwargs.get("format") == "mp3" assert isinstance(result, Path) assert result.exists()