Migrate download queue from JSON to SQLite database

- Created QueueRepository adapter in src/server/services/queue_repository.py
- Refactored DownloadService to use repository pattern instead of JSON
- Updated application startup to initialize download service from database
- Updated all test fixtures to use MockQueueRepository
- All 1104 tests passing
This commit is contained in:
2025-12-02 16:01:25 +01:00
parent 48daeba012
commit b0f3b643c7
18 changed files with 1393 additions and 330 deletions

View File

@@ -28,12 +28,13 @@ class TestDownloadQueueStress:
@pytest.fixture
def download_service(self, mock_anime_service, tmp_path):
"""Create download service with mock."""
persistence_path = str(tmp_path / "test_queue.json")
"""Create download service with mock repository."""
from tests.unit.test_download_service import MockQueueRepository
mock_repo = MockQueueRepository()
service = DownloadService(
anime_service=mock_anime_service,
max_retries=3,
persistence_path=persistence_path,
queue_repository=mock_repo,
)
return service
@@ -176,12 +177,13 @@ class TestDownloadMemoryUsage:
@pytest.fixture
def download_service(self, mock_anime_service, tmp_path):
"""Create download service with mock."""
persistence_path = str(tmp_path / "test_queue.json")
"""Create download service with mock repository."""
from tests.unit.test_download_service import MockQueueRepository
mock_repo = MockQueueRepository()
service = DownloadService(
anime_service=mock_anime_service,
max_retries=3,
persistence_path=persistence_path,
queue_repository=mock_repo,
)
return service
@@ -232,12 +234,13 @@ class TestDownloadConcurrency:
@pytest.fixture
def download_service(self, mock_anime_service, tmp_path):
"""Create download service with mock."""
persistence_path = str(tmp_path / "test_queue.json")
"""Create download service with mock repository."""
from tests.unit.test_download_service import MockQueueRepository
mock_repo = MockQueueRepository()
service = DownloadService(
anime_service=mock_anime_service,
max_retries=3,
persistence_path=persistence_path,
queue_repository=mock_repo,
)
return service
@@ -321,11 +324,12 @@ class TestDownloadErrorHandling:
self, mock_failing_anime_service, tmp_path
):
"""Create download service with failing mock."""
persistence_path = str(tmp_path / "test_queue.json")
from tests.unit.test_download_service import MockQueueRepository
mock_repo = MockQueueRepository()
service = DownloadService(
anime_service=mock_failing_anime_service,
max_retries=3,
persistence_path=persistence_path,
queue_repository=mock_repo,
)
return service
@@ -338,12 +342,13 @@ class TestDownloadErrorHandling:
@pytest.fixture
def download_service(self, mock_anime_service, tmp_path):
"""Create download service with mock."""
persistence_path = str(tmp_path / "test_queue.json")
"""Create download service with mock repository."""
from tests.unit.test_download_service import MockQueueRepository
mock_repo = MockQueueRepository()
service = DownloadService(
anime_service=mock_anime_service,
max_retries=3,
persistence_path=persistence_path,
queue_repository=mock_repo,
)
return service