Refactor: Defer folder creation to download time

- Remove folder creation from add_series endpoint
- Add folder creation to download() method in SeriesApp
- Maintain database persistence and targeted scanning
- Update tests to use tmp_path fixtures
- All add_series and download tests passing (13/13)
This commit is contained in:
2026-01-11 17:15:59 +01:00
parent 3d2ef53463
commit 5c0a019e72
4 changed files with 96 additions and 47 deletions

View File

@@ -107,10 +107,14 @@ class TestSeriesAppDownload:
@patch('src.core.SeriesApp.SerieScanner')
@patch('src.core.SeriesApp.SerieList')
async def test_download_success(
self, mock_serie_list, mock_scanner, mock_loaders
self, mock_serie_list, mock_scanner, mock_loaders, tmp_path
):
"""Test successful download."""
test_dir = "/test/anime"
test_dir = str(tmp_path / "anime")
# Create the test directory
import os
os.makedirs(test_dir, exist_ok=True)
app = SeriesApp(test_dir)
# Mock the events to prevent NoneType errors
@@ -130,16 +134,24 @@ class TestSeriesAppDownload:
# Verify result
assert result is True
app.loader.download.assert_called_once()
# Verify folder was created
folder_path = os.path.join(test_dir, "anime_folder")
assert os.path.exists(folder_path)
@pytest.mark.asyncio
@patch('src.core.SeriesApp.Loaders')
@patch('src.core.SeriesApp.SerieScanner')
@patch('src.core.SeriesApp.SerieList')
async def test_download_with_progress_callback(
self, mock_serie_list, mock_scanner, mock_loaders
self, mock_serie_list, mock_scanner, mock_loaders, tmp_path
):
"""Test download with progress callback."""
test_dir = "/test/anime"
test_dir = str(tmp_path / "anime")
# Create the test directory
import os
os.makedirs(test_dir, exist_ok=True)
app = SeriesApp(test_dir)
# Mock the events
@@ -172,10 +184,14 @@ class TestSeriesAppDownload:
@patch('src.core.SeriesApp.SerieScanner')
@patch('src.core.SeriesApp.SerieList')
async def test_download_cancellation(
self, mock_serie_list, mock_scanner, mock_loaders
self, mock_serie_list, mock_scanner, mock_loaders, tmp_path
):
"""Test download cancellation during operation."""
test_dir = "/test/anime"
test_dir = str(tmp_path / "anime")
# Create the test directory
import os
os.makedirs(test_dir, exist_ok=True)
app = SeriesApp(test_dir)
# Mock the events