refactor: move sync_series_from_data_files to anime_service

- Moved _sync_series_to_database from fastapi_app.py to anime_service.py
- Renamed to sync_series_from_data_files for better clarity
- Updated all imports and test references
- Removed completed TODO tasks from instructions.md
This commit is contained in:
2025-12-13 09:58:32 +01:00
parent 684337fd0c
commit 5f6ac8e507
4 changed files with 106 additions and 243 deletions

View File

@@ -187,19 +187,19 @@ class TestSerieListAddToDb:
class TestSyncSeriesToDatabase:
"""Test _sync_series_to_database function from fastapi_app."""
"""Test sync_series_from_data_files function from anime_service."""
@pytest.mark.asyncio
async def test_sync_with_empty_directory(self):
"""Test sync with empty anime directory."""
from src.server.fastapi_app import _sync_series_to_database
from src.server.services.anime_service import sync_series_from_data_files
with tempfile.TemporaryDirectory() as tmp_dir:
mock_logger = Mock()
with patch('src.core.SeriesApp.Loaders'), \
patch('src.core.SeriesApp.SerieScanner'):
count = await _sync_series_to_database(tmp_dir, mock_logger)
count = await sync_series_from_data_files(tmp_dir, mock_logger)
assert count == 0
# Should log that no series were found
@@ -213,7 +213,7 @@ class TestSyncSeriesToDatabase:
from files and the sync function attempts to add them to the DB.
The actual DB interaction is tested in test_add_to_db_creates_record.
"""
from src.server.fastapi_app import _sync_series_to_database
from src.server.services.anime_service import sync_series_from_data_files
with tempfile.TemporaryDirectory() as tmp_dir:
# Create test data files
@@ -241,7 +241,7 @@ class TestSyncSeriesToDatabase:
patch('src.core.SeriesApp.SerieScanner'):
# The function should return 0 because DB isn't available
# but should not crash
count = await _sync_series_to_database(tmp_dir, mock_logger)
count = await sync_series_from_data_files(tmp_dir, mock_logger)
# Since no real DB, it will fail gracefully
assert isinstance(count, int)
@@ -251,7 +251,7 @@ class TestSyncSeriesToDatabase:
@pytest.mark.asyncio
async def test_sync_handles_exceptions_gracefully(self):
"""Test that sync handles exceptions without crashing."""
from src.server.fastapi_app import _sync_series_to_database
from src.server.services.anime_service import sync_series_from_data_files
mock_logger = Mock()
@@ -262,7 +262,7 @@ class TestSyncSeriesToDatabase:
'src.core.SeriesApp.SerieList',
side_effect=Exception("Test error")
):
count = await _sync_series_to_database(
count = await sync_series_from_data_files(
"/fake/path", mock_logger
)