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:
@@ -110,81 +110,6 @@ class TestGetAllSeriesFromDataFiles:
|
||||
assert len(result) == 0
|
||||
|
||||
|
||||
class TestSyncSeriesToDatabase:
|
||||
"""Test sync_legacy_series_to_db function from anime_service."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_with_empty_directory(self):
|
||||
"""Test sync with empty anime directory."""
|
||||
from src.server.services.anime_service import sync_legacy_series_to_db
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
with patch('src.server.SeriesApp.Loaders'), \
|
||||
patch('src.server.SeriesApp.SerieScanner'):
|
||||
count = await sync_legacy_series_to_db(tmp_dir)
|
||||
|
||||
assert count == 0
|
||||
# Function should complete successfully with no series
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_adds_new_series_to_database(self):
|
||||
"""Test that sync adds new series to database.
|
||||
|
||||
This is a more realistic test that verifies series data is loaded
|
||||
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.services.anime_service import sync_legacy_series_to_db
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
# Create test data files
|
||||
_create_test_data_file(
|
||||
tmp_dir,
|
||||
folder="Sync Test Anime",
|
||||
key="sync-test-anime",
|
||||
name="Sync Test Anime",
|
||||
episodes={1: [1, 2]}
|
||||
)
|
||||
|
||||
# First verify that we can load the series from files
|
||||
with patch('src.server.SeriesApp.Loaders'), \
|
||||
patch('src.server.SeriesApp.SerieScanner'):
|
||||
app = SeriesApp(tmp_dir)
|
||||
series = app.get_all_series_from_data_files()
|
||||
assert len(series) == 1
|
||||
assert series[0].key == "sync-test-anime"
|
||||
|
||||
# Now test that the sync function loads series and handles DB
|
||||
# gracefully (even if DB operations fail, it should not crash)
|
||||
with patch('src.server.SeriesApp.Loaders'), \
|
||||
patch('src.server.SeriesApp.SerieScanner'):
|
||||
# The function should return 0 because DB isn't available
|
||||
# but should not crash
|
||||
count = await sync_legacy_series_to_db(tmp_dir)
|
||||
|
||||
# Since no real DB, it will fail gracefully
|
||||
# Function returns 0 when DB operations fail
|
||||
assert isinstance(count, int)
|
||||
assert count == 0
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_handles_exceptions_gracefully(self):
|
||||
"""Test that sync handles exceptions without crashing."""
|
||||
from src.server.services.anime_service import sync_legacy_series_to_db
|
||||
|
||||
# Make SeriesApp raise an exception during initialization
|
||||
with patch('src.server.SeriesApp.Loaders'), \
|
||||
patch('src.server.SeriesApp.SerieScanner'), \
|
||||
patch(
|
||||
'src.server.SeriesApp.SerieList',
|
||||
side_effect=Exception("Test error")
|
||||
):
|
||||
count = await sync_legacy_series_to_db("/fake/path")
|
||||
|
||||
assert count == 0
|
||||
# Function should complete without crashing
|
||||
|
||||
|
||||
class TestEndToEndSync:
|
||||
"""End-to-end tests for the sync functionality."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user