refactor: remove database access from core layer
- Remove db_session parameter from SeriesApp, SerieList, SerieScanner - Move all database operations to AnimeService (service layer) - Add add_series_to_db, contains_in_db methods to AnimeService - Update sync_series_from_data_files to use inline DB operations - Remove obsolete test classes for removed DB methods - Fix pylint issues: add broad-except comments, fix line lengths - Core layer (src/core/) now has zero database imports 722 unit tests pass
This commit is contained in:
@@ -6,7 +6,7 @@ error handling, and progress reporting integration.
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -183,7 +183,17 @@ class TestRescan:
|
||||
self, anime_service, mock_series_app, mock_progress_service
|
||||
):
|
||||
"""Test successful rescan operation."""
|
||||
await anime_service.rescan()
|
||||
# Mock rescan to return empty list (no DB save needed)
|
||||
mock_series_app.rescan.return_value = []
|
||||
|
||||
# Mock the database operations
|
||||
with patch.object(
|
||||
anime_service, '_save_scan_results_to_db', new_callable=AsyncMock
|
||||
):
|
||||
with patch.object(
|
||||
anime_service, '_load_series_from_db', new_callable=AsyncMock
|
||||
):
|
||||
await anime_service.rescan()
|
||||
|
||||
# Verify SeriesApp.rescan was called (lowercase, not ReScan)
|
||||
mock_series_app.rescan.assert_called_once()
|
||||
@@ -193,7 +203,15 @@ class TestRescan:
|
||||
"""Test rescan operation (callback parameter removed)."""
|
||||
# Rescan no longer accepts callback parameter
|
||||
# Progress is tracked via event handlers automatically
|
||||
await anime_service.rescan()
|
||||
mock_series_app.rescan.return_value = []
|
||||
|
||||
with patch.object(
|
||||
anime_service, '_save_scan_results_to_db', new_callable=AsyncMock
|
||||
):
|
||||
with patch.object(
|
||||
anime_service, '_load_series_from_db', new_callable=AsyncMock
|
||||
):
|
||||
await anime_service.rescan()
|
||||
|
||||
# Verify rescan was called
|
||||
mock_series_app.rescan.assert_called_once()
|
||||
@@ -207,9 +225,17 @@ class TestRescan:
|
||||
|
||||
# Update series list
|
||||
mock_series_app.series_list = [{"name": "Test"}, {"name": "New"}]
|
||||
mock_series_app.rescan.return_value = []
|
||||
|
||||
# Rescan should clear cache
|
||||
await anime_service.rescan()
|
||||
# Mock the database operations
|
||||
with patch.object(
|
||||
anime_service, '_save_scan_results_to_db', new_callable=AsyncMock
|
||||
):
|
||||
with patch.object(
|
||||
anime_service, '_load_series_from_db', new_callable=AsyncMock
|
||||
):
|
||||
# Rescan should clear cache
|
||||
await anime_service.rescan()
|
||||
|
||||
# Next list_missing should return updated data
|
||||
result = await anime_service.list_missing()
|
||||
|
||||
Reference in New Issue
Block a user