test fixes
This commit is contained in:
@@ -29,6 +29,12 @@ async def authenticated_client(mock_download_service):
|
||||
if not auth_service.is_configured():
|
||||
auth_service.setup_master_password("TestPass123!")
|
||||
|
||||
# Override the dependency with our mock
|
||||
from src.server.utils.dependencies import get_download_service
|
||||
app.dependency_overrides[get_download_service] = (
|
||||
lambda: mock_download_service
|
||||
)
|
||||
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(
|
||||
transport=transport, base_url="http://test"
|
||||
@@ -44,66 +50,65 @@ async def authenticated_client(mock_download_service):
|
||||
client.headers["Authorization"] = f"Bearer {token}"
|
||||
|
||||
yield client
|
||||
|
||||
# Clean up dependency override
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_download_service():
|
||||
"""Mock DownloadService for testing."""
|
||||
with patch(
|
||||
"src.server.utils.dependencies.get_download_service"
|
||||
) as mock:
|
||||
service = MagicMock()
|
||||
service = MagicMock()
|
||||
|
||||
# Mock queue status
|
||||
service.get_queue_status = AsyncMock(
|
||||
return_value=QueueStatus(
|
||||
is_running=True,
|
||||
is_paused=False,
|
||||
active_downloads=[],
|
||||
pending_queue=[],
|
||||
completed_downloads=[],
|
||||
failed_downloads=[],
|
||||
)
|
||||
# Mock queue status
|
||||
service.get_queue_status = AsyncMock(
|
||||
return_value=QueueStatus(
|
||||
is_running=True,
|
||||
is_paused=False,
|
||||
active_downloads=[],
|
||||
pending_queue=[],
|
||||
completed_downloads=[],
|
||||
failed_downloads=[],
|
||||
)
|
||||
)
|
||||
|
||||
# Mock queue stats
|
||||
service.get_queue_stats = AsyncMock(
|
||||
return_value=QueueStats(
|
||||
total_items=0,
|
||||
pending_count=0,
|
||||
active_count=0,
|
||||
completed_count=0,
|
||||
failed_count=0,
|
||||
total_downloaded_mb=0.0,
|
||||
)
|
||||
# Mock queue stats
|
||||
service.get_queue_stats = AsyncMock(
|
||||
return_value=QueueStats(
|
||||
total_items=0,
|
||||
pending_count=0,
|
||||
active_count=0,
|
||||
completed_count=0,
|
||||
failed_count=0,
|
||||
total_downloaded_mb=0.0,
|
||||
)
|
||||
)
|
||||
|
||||
# Mock add_to_queue
|
||||
service.add_to_queue = AsyncMock(
|
||||
return_value=["item-id-1", "item-id-2"]
|
||||
)
|
||||
# Mock add_to_queue
|
||||
service.add_to_queue = AsyncMock(
|
||||
return_value=["item-id-1", "item-id-2"]
|
||||
)
|
||||
|
||||
# Mock remove_from_queue
|
||||
service.remove_from_queue = AsyncMock(return_value=["item-id-1"])
|
||||
# Mock remove_from_queue
|
||||
service.remove_from_queue = AsyncMock(return_value=["item-id-1"])
|
||||
|
||||
# Mock reorder_queue
|
||||
service.reorder_queue = AsyncMock(return_value=True)
|
||||
# Mock reorder_queue
|
||||
service.reorder_queue = AsyncMock(return_value=True)
|
||||
|
||||
# Mock start/stop/pause/resume
|
||||
service.start = AsyncMock()
|
||||
service.stop = AsyncMock()
|
||||
service.pause_queue = AsyncMock()
|
||||
service.resume_queue = AsyncMock()
|
||||
# Mock start/stop/pause/resume
|
||||
service.start = AsyncMock()
|
||||
service.stop = AsyncMock()
|
||||
service.pause_queue = AsyncMock()
|
||||
service.resume_queue = AsyncMock()
|
||||
|
||||
# Mock clear_completed and retry_failed
|
||||
service.clear_completed = AsyncMock(return_value=5)
|
||||
service.retry_failed = AsyncMock(return_value=["item-id-3"])
|
||||
# Mock clear_completed and retry_failed
|
||||
service.clear_completed = AsyncMock(return_value=5)
|
||||
service.retry_failed = AsyncMock(return_value=["item-id-3"])
|
||||
|
||||
mock.return_value = service
|
||||
yield service
|
||||
return service
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_queue_status(authenticated_client, mock_download_service):
|
||||
"""Test GET /api/queue/status endpoint."""
|
||||
response = await authenticated_client.get("/api/queue/status")
|
||||
@@ -120,7 +125,7 @@ async def test_get_queue_status(authenticated_client, mock_download_service):
|
||||
mock_download_service.get_queue_stats.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_queue_status_unauthorized(mock_download_service):
|
||||
"""Test GET /api/queue/status without authentication."""
|
||||
transport = ASGITransport(app=app)
|
||||
@@ -132,7 +137,7 @@ async def test_get_queue_status_unauthorized(mock_download_service):
|
||||
assert response.status_code in (401, 503)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_to_queue(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/add endpoint."""
|
||||
request_data = {
|
||||
@@ -159,7 +164,7 @@ async def test_add_to_queue(authenticated_client, mock_download_service):
|
||||
mock_download_service.add_to_queue.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_to_queue_with_high_priority(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
@@ -182,7 +187,7 @@ async def test_add_to_queue_with_high_priority(
|
||||
assert call_args[1]["priority"] == DownloadPriority.HIGH
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_to_queue_empty_episodes(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
@@ -201,7 +206,7 @@ async def test_add_to_queue_empty_episodes(
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_to_queue_service_error(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
@@ -225,7 +230,7 @@ async def test_add_to_queue_service_error(
|
||||
assert "Queue full" in response.json()["detail"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_from_queue_single(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
@@ -239,7 +244,7 @@ async def test_remove_from_queue_single(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_from_queue_not_found(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
@@ -253,7 +258,7 @@ async def test_remove_from_queue_not_found(
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_multiple_from_queue(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
@@ -271,7 +276,7 @@ async def test_remove_multiple_from_queue(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_multiple_empty_list(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
@@ -285,7 +290,7 @@ async def test_remove_multiple_empty_list(
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_queue(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/start endpoint."""
|
||||
response = await authenticated_client.post("/api/queue/start")
|
||||
@@ -299,7 +304,7 @@ async def test_start_queue(authenticated_client, mock_download_service):
|
||||
mock_download_service.start.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_queue(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/stop endpoint."""
|
||||
response = await authenticated_client.post("/api/queue/stop")
|
||||
@@ -313,7 +318,7 @@ async def test_stop_queue(authenticated_client, mock_download_service):
|
||||
mock_download_service.stop.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_pause_queue(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/pause endpoint."""
|
||||
response = await authenticated_client.post("/api/queue/pause")
|
||||
@@ -327,7 +332,7 @@ async def test_pause_queue(authenticated_client, mock_download_service):
|
||||
mock_download_service.pause_queue.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_resume_queue(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/resume endpoint."""
|
||||
response = await authenticated_client.post("/api/queue/resume")
|
||||
@@ -341,7 +346,7 @@ async def test_resume_queue(authenticated_client, mock_download_service):
|
||||
mock_download_service.resume_queue.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_reorder_queue(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/reorder endpoint."""
|
||||
request_data = {"item_id": "item-id-1", "new_position": 0}
|
||||
@@ -360,7 +365,7 @@ async def test_reorder_queue(authenticated_client, mock_download_service):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_reorder_queue_not_found(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
@@ -376,7 +381,7 @@ async def test_reorder_queue_not_found(
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_clear_completed(authenticated_client, mock_download_service):
|
||||
"""Test DELETE /api/queue/completed endpoint."""
|
||||
response = await authenticated_client.delete("/api/queue/completed")
|
||||
@@ -390,7 +395,7 @@ async def test_clear_completed(authenticated_client, mock_download_service):
|
||||
mock_download_service.clear_completed.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_retry_failed(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/retry endpoint."""
|
||||
request_data = {"item_ids": ["item-id-3"]}
|
||||
@@ -410,7 +415,7 @@ async def test_retry_failed(authenticated_client, mock_download_service):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_retry_all_failed(authenticated_client, mock_download_service):
|
||||
"""Test retrying all failed items with empty list."""
|
||||
request_data = {"item_ids": []}
|
||||
@@ -425,7 +430,7 @@ async def test_retry_all_failed(authenticated_client, mock_download_service):
|
||||
mock_download_service.retry_failed.assert_called_once_with(None)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.asyncio
|
||||
async def test_queue_endpoints_require_auth(mock_download_service):
|
||||
"""Test that all queue endpoints require authentication."""
|
||||
transport = ASGITransport(app=app)
|
||||
|
||||
Reference in New Issue
Block a user