Files
Aniworld/tests/unit/test_ffmpeg_health_check.py
Lukas 9c3f03d610 refactor(scheduler): separate scheduler logic from scan/rescan logic
- Extract rescan logic into new RescanService (src/server/services/rescan_service.py)
- SchedulerService now only handles APScheduler cron scheduling
- Move scheduler sub-services (folder_rename, folder_scan, key_resolution) to scheduler/ folder
- Keep RescanOrchestrator as backward-compatible alias
- Update all imports across api/, server/, and test files
2026-06-03 20:58:30 +02:00

86 lines
5.4 KiB
Python

"""Unit tests for ffmpeg health check in fastapi_app.py."""
import asyncio
from unittest.mock import MagicMock, patch, AsyncMock
import pytest
class TestFfmpegHealthCheck:
"""Test ffmpeg health check warns when not in PATH."""
@pytest.mark.asyncio
async def test_ffmpeg_missing_warns(self):
"""Should log warning when ffmpeg not found in PATH."""
mock_logger = MagicMock()
mock_logger.warning = MagicMock()
mock_logger.info = MagicMock()
mock_logger.debug = MagicMock()
with patch("shutil.which", return_value=None):
with patch("src.server.fastapi_app.setup_logging", return_value=mock_logger):
# Patch service getters at their actual definition modules
with patch("src.server.services.config_service.get_config_service"):
with patch("src.server.services.progress_service.get_progress_service"):
with patch("src.server.services.websocket_service.get_websocket_service"):
with patch("src.server.utils.dependencies.get_anime_service"):
with patch("src.server.utils.dependencies.get_download_service"):
with patch("src.server.utils.dependencies.get_background_loader_service"):
with patch("src.server.services.scheduler.scheduler_service.get_scheduler_service") as mock_get_sched:
mock_sched = MagicMock()
mock_sched.start = AsyncMock(return_value=None)
mock_get_sched.return_value = mock_sched
with patch("src.server.database.connection.init_db", new_callable=AsyncMock):
with patch("src.server.services.initialization_service.perform_initial_setup", new_callable=AsyncMock):
with patch("src.server.services.initialization_service.perform_nfo_scan_if_needed", new_callable=AsyncMock):
with patch("src.server.services.initialization_service.perform_media_scan_if_needed", new_callable=AsyncMock):
from src.server.fastapi_app import lifespan
app = MagicMock()
async with lifespan(app):
pass
# Should have logged a warning about ffmpeg
warning_calls = [
c for c in mock_logger.warning.call_args_list
if "ffmpeg" in str(c)
]
assert len(warning_calls) >= 1
@pytest.mark.asyncio
async def test_ffmpeg_present_no_warning(self):
"""Should not log warning when ffmpeg is found."""
mock_logger = MagicMock()
mock_logger.warning = MagicMock()
mock_logger.info = MagicMock()
mock_logger.debug = MagicMock()
with patch("shutil.which", return_value="/usr/bin/ffmpeg"):
with patch("src.server.fastapi_app.setup_logging", return_value=mock_logger):
# Patch service getters at their actual definition modules
with patch("src.server.services.config_service.get_config_service"):
with patch("src.server.services.progress_service.get_progress_service"):
with patch("src.server.services.websocket_service.get_websocket_service"):
with patch("src.server.utils.dependencies.get_anime_service"):
with patch("src.server.utils.dependencies.get_download_service"):
with patch("src.server.utils.dependencies.get_background_loader_service"):
with patch("src.server.services.scheduler.scheduler_service.get_scheduler_service") as mock_get_sched:
mock_sched = MagicMock()
mock_sched.start = AsyncMock(return_value=None)
mock_get_sched.return_value = mock_sched
with patch("src.server.database.connection.init_db", new_callable=AsyncMock):
with patch("src.server.services.initialization_service.perform_initial_setup", new_callable=AsyncMock):
with patch("src.server.services.initialization_service.perform_nfo_scan_if_needed", new_callable=AsyncMock):
with patch("src.server.services.initialization_service.perform_media_scan_if_needed", new_callable=AsyncMock):
from src.server.fastapi_app import lifespan
app = MagicMock()
async with lifespan(app):
pass
# Should NOT have logged a warning about ffmpeg
warning_calls = [
c for c in mock_logger.warning.call_args_list
if "ffmpeg" in str(c)
]
assert len(warning_calls) == 0