test: remove sync_legacy_series_to_db tests
- Removed TestSyncSeriesFromDataFiles class from test_anime_service.py - Updated TestSyncAnimeFolders tests to expect sync_count=0 - Removed TestSyncSeriesToDatabase class from test_data_file_db_sync.py
This commit is contained in:
@@ -13,11 +13,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from src.server.services.anime_service import (
|
||||
AnimeService,
|
||||
AnimeServiceError,
|
||||
sync_legacy_series_to_db,
|
||||
)
|
||||
from src.server.services.anime_service import AnimeService, AnimeServiceError
|
||||
from src.server.services.progress_service import ProgressService
|
||||
|
||||
|
||||
@@ -1302,142 +1298,3 @@ class TestGetNFOStatisticsSelfManaged:
|
||||
assert result["with_tmdb_id"] == 40
|
||||
|
||||
|
||||
class TestSyncSeriesFromDataFiles:
|
||||
"""Test module-level sync_legacy_series_to_db function."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_adds_new_series(self, tmp_path):
|
||||
"""Should create series for data files not in DB."""
|
||||
mock_serie = MagicMock()
|
||||
mock_serie.key = "new-series"
|
||||
mock_serie.name = "New Series"
|
||||
mock_serie.site = "aniworld.to"
|
||||
mock_serie.folder = "New Series"
|
||||
mock_serie.episodeDict = {1: [1]}
|
||||
|
||||
mock_session = AsyncMock()
|
||||
mock_ctx = AsyncMock()
|
||||
mock_ctx.__aenter__ = AsyncMock(return_value=mock_session)
|
||||
mock_ctx.__aexit__ = AsyncMock(return_value=False)
|
||||
|
||||
with patch(
|
||||
"src.server.services.anime_service.SeriesApp"
|
||||
) as MockApp, patch(
|
||||
"src.server.database.connection.get_db_session",
|
||||
return_value=mock_ctx,
|
||||
), patch(
|
||||
"src.server.database.service.AnimeSeriesService.get_by_key",
|
||||
new_callable=AsyncMock,
|
||||
return_value=None,
|
||||
), patch(
|
||||
"src.server.database.service.AnimeSeriesService.create",
|
||||
new_callable=AsyncMock,
|
||||
return_value=MagicMock(id=1),
|
||||
) as mock_create, patch(
|
||||
"src.server.database.service.EpisodeService.create",
|
||||
new_callable=AsyncMock,
|
||||
):
|
||||
mock_app_instance = MagicMock()
|
||||
mock_app_instance.get_all_series_from_data_files.return_value = [
|
||||
mock_serie
|
||||
]
|
||||
MockApp.return_value = mock_app_instance
|
||||
|
||||
count = await sync_legacy_series_to_db(str(tmp_path))
|
||||
|
||||
assert count == 1
|
||||
mock_create.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_skips_existing(self, tmp_path):
|
||||
"""Already-existing series should be skipped."""
|
||||
mock_serie = MagicMock()
|
||||
mock_serie.key = "exists"
|
||||
mock_serie.name = "Exists"
|
||||
mock_serie.site = "x"
|
||||
mock_serie.folder = "Exists"
|
||||
mock_serie.episodeDict = {}
|
||||
|
||||
mock_session = AsyncMock()
|
||||
mock_ctx = AsyncMock()
|
||||
mock_ctx.__aenter__ = AsyncMock(return_value=mock_session)
|
||||
mock_ctx.__aexit__ = AsyncMock(return_value=False)
|
||||
|
||||
with patch(
|
||||
"src.server.services.anime_service.SeriesApp"
|
||||
) as MockApp, patch(
|
||||
"src.server.database.connection.get_db_session",
|
||||
return_value=mock_ctx,
|
||||
), patch(
|
||||
"src.server.database.service.AnimeSeriesService.get_by_key",
|
||||
new_callable=AsyncMock,
|
||||
return_value=MagicMock(),
|
||||
), patch(
|
||||
"src.server.database.service.AnimeSeriesService.create",
|
||||
new_callable=AsyncMock,
|
||||
) as mock_create:
|
||||
mock_app_instance = MagicMock()
|
||||
mock_app_instance.get_all_series_from_data_files.return_value = [
|
||||
mock_serie
|
||||
]
|
||||
MockApp.return_value = mock_app_instance
|
||||
|
||||
count = await sync_legacy_series_to_db(str(tmp_path))
|
||||
|
||||
assert count == 0
|
||||
mock_create.assert_not_called()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_no_data_files(self, tmp_path):
|
||||
"""Empty directory should return 0."""
|
||||
with patch(
|
||||
"src.server.services.anime_service.SeriesApp"
|
||||
) as MockApp:
|
||||
mock_app_instance = MagicMock()
|
||||
mock_app_instance.get_all_series_from_data_files.return_value = []
|
||||
MockApp.return_value = mock_app_instance
|
||||
|
||||
count = await sync_legacy_series_to_db(str(tmp_path))
|
||||
|
||||
assert count == 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_handles_empty_name(self, tmp_path):
|
||||
"""Series with empty name should use folder as fallback."""
|
||||
mock_serie = MagicMock()
|
||||
mock_serie.key = "no-name"
|
||||
mock_serie.name = ""
|
||||
mock_serie.site = "x"
|
||||
mock_serie.folder = "FallbackFolder"
|
||||
mock_serie.episodeDict = {}
|
||||
|
||||
mock_session = AsyncMock()
|
||||
mock_ctx = AsyncMock()
|
||||
mock_ctx.__aenter__ = AsyncMock(return_value=mock_session)
|
||||
mock_ctx.__aexit__ = AsyncMock(return_value=False)
|
||||
|
||||
with patch(
|
||||
"src.server.services.anime_service.SeriesApp"
|
||||
) as MockApp, patch(
|
||||
"src.server.database.connection.get_db_session",
|
||||
return_value=mock_ctx,
|
||||
), patch(
|
||||
"src.server.database.service.AnimeSeriesService.get_by_key",
|
||||
new_callable=AsyncMock,
|
||||
return_value=None,
|
||||
), patch(
|
||||
"src.server.database.service.AnimeSeriesService.create",
|
||||
new_callable=AsyncMock,
|
||||
return_value=MagicMock(id=1),
|
||||
) as mock_create:
|
||||
mock_app_instance = MagicMock()
|
||||
mock_app_instance.get_all_series_from_data_files.return_value = [
|
||||
mock_serie
|
||||
]
|
||||
MockApp.return_value = mock_app_instance
|
||||
|
||||
count = await sync_legacy_series_to_db(str(tmp_path))
|
||||
|
||||
assert count == 1
|
||||
# The name should have been set to folder
|
||||
assert mock_serie.name == "FallbackFolder"
|
||||
|
||||
@@ -161,14 +161,11 @@ class TestSyncAnimeFolders:
|
||||
async def test_sync_anime_folders_without_progress(self):
|
||||
"""Test syncing anime folders without progress service."""
|
||||
with patch('src.server.services.initialization_service.settings') as mock_settings, \
|
||||
patch('src.server.services.initialization_service.os.path.isdir', return_value=True), \
|
||||
patch('src.server.services.initialization_service.sync_legacy_series_to_db',
|
||||
new_callable=AsyncMock, return_value=42) as mock_sync:
|
||||
patch('src.server.services.initialization_service.os.path.isdir', return_value=True):
|
||||
mock_settings.anime_directory = "/path/to/anime"
|
||||
result = await _sync_anime_folders()
|
||||
|
||||
assert result == 42
|
||||
mock_sync.assert_called_once()
|
||||
assert result == 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_anime_folders_with_progress(self):
|
||||
@@ -176,13 +173,11 @@ class TestSyncAnimeFolders:
|
||||
mock_progress = AsyncMock()
|
||||
|
||||
with patch('src.server.services.initialization_service.settings') as mock_settings, \
|
||||
patch('src.server.services.initialization_service.os.path.isdir', return_value=True), \
|
||||
patch('src.server.services.initialization_service.sync_legacy_series_to_db',
|
||||
new_callable=AsyncMock, return_value=10) as mock_sync:
|
||||
patch('src.server.services.initialization_service.os.path.isdir', return_value=True):
|
||||
mock_settings.anime_directory = "/path/to/anime"
|
||||
result = await _sync_anime_folders(progress_service=mock_progress)
|
||||
|
||||
assert result == 10
|
||||
assert result == 0
|
||||
# Verify progress updates were called
|
||||
assert mock_progress.update_progress.call_count == 2
|
||||
mock_progress.update_progress.assert_any_call(
|
||||
@@ -194,7 +189,7 @@ class TestSyncAnimeFolders:
|
||||
mock_progress.update_progress.assert_any_call(
|
||||
progress_id="series_sync",
|
||||
current=75,
|
||||
message="Synced 10 series from data files",
|
||||
message="Series loaded directly from database",
|
||||
metadata={"step_id": "series_sync"}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user