fixed some tests

This commit is contained in:
2025-11-15 16:56:12 +01:00
parent f49598d82b
commit fac0cecf90
13 changed files with 10434 additions and 3301 deletions

View File

@@ -185,35 +185,18 @@ class TestRescan:
"""Test successful rescan operation."""
await anime_service.rescan()
# Verify SeriesApp.ReScan was called
mock_series_app.ReScan.assert_called_once()
# Verify progress tracking
mock_progress_service.start_progress.assert_called_once()
mock_progress_service.complete_progress.assert_called_once()
# Verify SeriesApp.rescan was called (lowercase, not ReScan)
mock_series_app.rescan.assert_called_once()
@pytest.mark.asyncio
async def test_rescan_with_callback(self, anime_service, mock_series_app):
"""Test rescan with progress callback."""
callback_called = False
callback_data = None
"""Test rescan operation (callback parameter removed)."""
# Rescan no longer accepts callback parameter
# Progress is tracked via event handlers automatically
await anime_service.rescan()
def callback(data):
nonlocal callback_called, callback_data
callback_called = True
callback_data = data
# Mock ReScan to call the callback
def mock_rescan(cb):
if cb:
cb({"current": 5, "total": 10, "message": "Scanning..."})
mock_series_app.ReScan.side_effect = mock_rescan
await anime_service.rescan(callback=callback)
assert callback_called
assert callback_data is not None
# Verify rescan was called
mock_series_app.rescan.assert_called_once()
@pytest.mark.asyncio
async def test_rescan_clears_cache(self, anime_service, mock_series_app):
@@ -237,13 +220,10 @@ class TestRescan:
self, anime_service, mock_series_app, mock_progress_service
):
"""Test error handling during rescan."""
mock_series_app.ReScan.side_effect = Exception("Rescan failed")
mock_series_app.rescan.side_effect = Exception("Rescan failed")
with pytest.raises(AnimeServiceError, match="Rescan failed"):
await anime_service.rescan()
# Verify progress failure was recorded
mock_progress_service.fail_progress.assert_called_once()
class TestDownload:
@@ -263,13 +243,19 @@ class TestDownload:
assert result is True
mock_series_app.download.assert_called_once_with(
"test_series", 1, 1, "test_key", None
serie_folder="test_series",
season=1,
episode=1,
key="test_key",
)
@pytest.mark.asyncio
async def test_download_with_callback(self, anime_service, mock_series_app):
"""Test download with progress callback."""
callback = MagicMock()
async def test_download_with_callback(
self, anime_service, mock_series_app
):
"""Test download operation (callback parameter removed)."""
# Download no longer accepts callback parameter
# Progress is tracked via event handlers automatically
mock_series_app.download.return_value = True
result = await anime_service.download(
@@ -277,17 +263,21 @@ class TestDownload:
season=1,
episode=1,
key="test_key",
callback=callback,
)
assert result is True
# Verify callback was passed to SeriesApp
# Verify download was called with correct parameters
mock_series_app.download.assert_called_once_with(
"test_series", 1, 1, "test_key", callback
serie_folder="test_series",
season=1,
episode=1,
key="test_key",
)
@pytest.mark.asyncio
async def test_download_error_handling(self, anime_service, mock_series_app):
async def test_download_error_handling(
self, anime_service, mock_series_app
):
"""Test error handling during download."""
mock_series_app.download.side_effect = Exception("Download failed")
@@ -326,12 +316,12 @@ class TestConcurrency:
class TestFactoryFunction:
"""Test factory function."""
def test_get_anime_service(self):
def test_get_anime_service(self, mock_series_app):
"""Test get_anime_service factory function."""
from src.server.services.anime_service import get_anime_service
# The factory function doesn't take directory anymore
service = get_anime_service()
# The factory function requires a series_app parameter
service = get_anime_service(mock_series_app)
assert isinstance(service, AnimeService)
assert service._app is not None
assert service._app is mock_series_app