fixed : tests
This commit is contained in:
@@ -50,6 +50,20 @@ class FakeSeriesApp:
|
||||
if not any(s.key == serie.key for s in self._items):
|
||||
self._items.append(serie)
|
||||
|
||||
async def search(self, query):
|
||||
"""Search for series (async)."""
|
||||
# Return mock search results
|
||||
return [
|
||||
{
|
||||
"key": "test-result",
|
||||
"name": "Test Search Result",
|
||||
"site": "aniworld.to",
|
||||
"folder": "test-result",
|
||||
"link": "https://aniworld.to/anime/test",
|
||||
"missing_episodes": {},
|
||||
}
|
||||
]
|
||||
|
||||
def refresh_series_list(self):
|
||||
"""Refresh series list."""
|
||||
pass
|
||||
@@ -65,6 +79,20 @@ def reset_auth_state():
|
||||
auth_service._failed.clear()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_series_app_dependency():
|
||||
"""Override the series_app dependency with FakeSeriesApp."""
|
||||
from src.server.utils.dependencies import get_series_app
|
||||
|
||||
fake_app = FakeSeriesApp()
|
||||
app.dependency_overrides[get_series_app] = lambda: fake_app
|
||||
|
||||
yield fake_app
|
||||
|
||||
# Clean up
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def authenticated_client():
|
||||
"""Create authenticated async client."""
|
||||
|
||||
@@ -92,9 +92,9 @@ def mock_download_service():
|
||||
# Mock remove_from_queue
|
||||
service.remove_from_queue = AsyncMock(return_value=["item-id-1"])
|
||||
|
||||
# Mock start/stop
|
||||
service.start_next_download = AsyncMock(return_value="item-id-1")
|
||||
service.stop_downloads = AsyncMock()
|
||||
# Mock start/stop - start_queue_processing returns True on success
|
||||
service.start_queue_processing = AsyncMock(return_value=True)
|
||||
service.stop = AsyncMock()
|
||||
|
||||
# Mock clear_completed and retry_failed
|
||||
service.clear_completed = AsyncMock(return_value=5)
|
||||
@@ -266,17 +266,16 @@ async def test_remove_from_queue_not_found(
|
||||
async def test_start_download_success(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
"""Test POST /api/queue/start starts first pending download."""
|
||||
"""Test POST /api/queue/start starts queue processing."""
|
||||
response = await authenticated_client.post("/api/queue/start")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert data["status"] == "success"
|
||||
assert "item_id" in data
|
||||
assert data["item_id"] == "item-id-1"
|
||||
assert "started" in data["message"].lower()
|
||||
|
||||
mock_download_service.start_next_download.assert_called_once()
|
||||
mock_download_service.start_queue_processing.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -284,7 +283,7 @@ async def test_start_download_empty_queue(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
"""Test starting download with empty queue returns 400."""
|
||||
mock_download_service.start_next_download.return_value = None
|
||||
mock_download_service.start_queue_processing.return_value = None
|
||||
|
||||
response = await authenticated_client.post("/api/queue/start")
|
||||
|
||||
@@ -299,7 +298,7 @@ async def test_start_download_already_active(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
"""Test starting download while one is active returns 400."""
|
||||
mock_download_service.start_next_download.side_effect = (
|
||||
mock_download_service.start_queue_processing.side_effect = (
|
||||
DownloadServiceError("A download is already in progress")
|
||||
)
|
||||
|
||||
@@ -307,7 +306,8 @@ async def test_start_download_already_active(
|
||||
|
||||
assert response.status_code == 400
|
||||
data = response.json()
|
||||
assert "already" in data["detail"].lower()
|
||||
detail_lower = data["detail"].lower()
|
||||
assert "already" in detail_lower or "progress" in detail_lower
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -321,7 +321,7 @@ async def test_stop_downloads(authenticated_client, mock_download_service):
|
||||
assert data["status"] == "success"
|
||||
assert "stopped" in data["message"].lower()
|
||||
|
||||
mock_download_service.stop_downloads.assert_called_once()
|
||||
mock_download_service.stop.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user