download re implemented
This commit is contained in:
@@ -92,14 +92,9 @@ def mock_download_service():
|
||||
# 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 start/stop/pause/resume
|
||||
service.start = AsyncMock()
|
||||
service.stop = AsyncMock()
|
||||
service.pause_queue = AsyncMock()
|
||||
service.resume_queue = AsyncMock()
|
||||
# Mock start/stop
|
||||
service.start_next_download = AsyncMock(return_value="item-id-1")
|
||||
service.stop_downloads = AsyncMock()
|
||||
|
||||
# Mock clear_completed and retry_failed
|
||||
service.clear_completed = AsyncMock(return_value=5)
|
||||
@@ -259,54 +254,56 @@ async def test_remove_from_queue_not_found(
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_multiple_from_queue(
|
||||
async def test_start_download_success(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
"""Test DELETE /api/queue/ with multiple items."""
|
||||
request_data = {"item_ids": ["item-id-1", "item-id-2"]}
|
||||
|
||||
response = await authenticated_client.request(
|
||||
"DELETE", "/api/queue/", json=request_data
|
||||
)
|
||||
|
||||
assert response.status_code == 204
|
||||
|
||||
mock_download_service.remove_from_queue.assert_called_once_with(
|
||||
["item-id-1", "item-id-2"]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remove_multiple_empty_list(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
"""Test removing with empty item list returns 400."""
|
||||
request_data = {"item_ids": []}
|
||||
|
||||
response = await authenticated_client.request(
|
||||
"DELETE", "/api/queue/", json=request_data
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_queue(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/start endpoint."""
|
||||
"""Test POST /api/queue/start starts first pending download."""
|
||||
response = await authenticated_client.post("/api/queue/start")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert data["status"] == "success"
|
||||
assert "started" in data["message"].lower()
|
||||
assert "item_id" in data
|
||||
assert data["item_id"] == "item-id-1"
|
||||
|
||||
mock_download_service.start.assert_called_once()
|
||||
mock_download_service.start_next_download.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_queue(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/stop endpoint."""
|
||||
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
|
||||
|
||||
response = await authenticated_client.post("/api/queue/start")
|
||||
|
||||
assert response.status_code == 400
|
||||
data = response.json()
|
||||
detail = data["detail"].lower()
|
||||
assert "empty" in detail or "no pending" in detail
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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 = (
|
||||
DownloadServiceError("A download is already in progress")
|
||||
)
|
||||
|
||||
response = await authenticated_client.post("/api/queue/start")
|
||||
|
||||
assert response.status_code == 400
|
||||
data = response.json()
|
||||
assert "already" in data["detail"].lower()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_downloads(authenticated_client, mock_download_service):
|
||||
"""Test POST /api/queue/stop stops queue processing."""
|
||||
response = await authenticated_client.post("/api/queue/stop")
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -315,70 +312,7 @@ async def test_stop_queue(authenticated_client, mock_download_service):
|
||||
assert data["status"] == "success"
|
||||
assert "stopped" in data["message"].lower()
|
||||
|
||||
mock_download_service.stop.assert_called_once()
|
||||
|
||||
|
||||
@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")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert data["status"] == "success"
|
||||
assert "paused" in data["message"].lower()
|
||||
|
||||
mock_download_service.pause_queue.assert_called_once()
|
||||
|
||||
|
||||
@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")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert data["status"] == "success"
|
||||
assert "resumed" in data["message"].lower()
|
||||
|
||||
mock_download_service.resume_queue.assert_called_once()
|
||||
|
||||
|
||||
@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}
|
||||
|
||||
response = await authenticated_client.post(
|
||||
"/api/queue/reorder", json=request_data
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert data["status"] == "success"
|
||||
|
||||
mock_download_service.reorder_queue.assert_called_once_with(
|
||||
item_id="item-id-1", new_position=0
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reorder_queue_not_found(
|
||||
authenticated_client, mock_download_service
|
||||
):
|
||||
"""Test reordering non-existent item returns 404."""
|
||||
mock_download_service.reorder_queue.return_value = False
|
||||
|
||||
request_data = {"item_id": "non-existent", "new_position": 0}
|
||||
|
||||
response = await authenticated_client.post(
|
||||
"/api/queue/reorder", json=request_data
|
||||
)
|
||||
|
||||
assert response.status_code == 404
|
||||
mock_download_service.stop_downloads.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -444,8 +378,6 @@ async def test_queue_endpoints_require_auth(mock_download_service):
|
||||
("DELETE", "/api/queue/item-1"),
|
||||
("POST", "/api/queue/start"),
|
||||
("POST", "/api/queue/stop"),
|
||||
("POST", "/api/queue/pause"),
|
||||
("POST", "/api/queue/resume"),
|
||||
]
|
||||
|
||||
for method, url in endpoints:
|
||||
@@ -456,7 +388,8 @@ async def test_queue_endpoints_require_auth(mock_download_service):
|
||||
elif method == "DELETE":
|
||||
response = await client.delete(url)
|
||||
|
||||
# Should return 401 or 503 (503 if service not available)
|
||||
# Should return 401 or 503 (503 if service unavailable)
|
||||
assert response.status_code in (401, 503), (
|
||||
f"{method} {url} should require auth, got {response.status_code}"
|
||||
f"{method} {url} should require auth, "
|
||||
f"got {response.status_code}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user