fix tests

This commit is contained in:
2025-10-19 20:18:25 +02:00
parent d87ec398bb
commit 36e09b72ed
5 changed files with 56 additions and 162 deletions

View File

@@ -119,6 +119,40 @@ async def add_to_queue(
)
@router.delete("/completed", status_code=status.HTTP_200_OK)
async def clear_completed(
download_service: DownloadService = Depends(get_download_service),
_: dict = Depends(require_auth),
):
"""Clear completed downloads from history.
Removes all completed download items from the queue history. This helps
keep the queue display clean and manageable.
Requires authentication.
Returns:
dict: Status message with count of cleared items
Raises:
HTTPException: 401 if not authenticated, 500 on service error
"""
try:
cleared_count = await download_service.clear_completed()
return {
"status": "success",
"message": f"Cleared {cleared_count} completed item(s)",
"count": cleared_count,
}
except Exception as e:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to clear completed items: {str(e)}",
)
@router.delete("/{item_id}", status_code=status.HTTP_204_NO_CONTENT)
async def remove_from_queue(
item_id: str = Path(..., description="Download item ID to remove"),
@@ -399,40 +433,6 @@ async def reorder_queue(
)
@router.delete("/completed", status_code=status.HTTP_200_OK)
async def clear_completed(
download_service: DownloadService = Depends(get_download_service),
_: dict = Depends(require_auth),
):
"""Clear completed downloads from history.
Removes all completed download items from the queue history. This helps
keep the queue display clean and manageable.
Requires authentication.
Returns:
dict: Status message with count of cleared items
Raises:
HTTPException: 401 if not authenticated, 500 on service error
"""
try:
cleared_count = await download_service.clear_completed()
return {
"status": "success",
"message": f"Cleared {cleared_count} completed item(s)",
"count": cleared_count,
}
except Exception as e:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to clear completed items: {str(e)}",
)
@router.post("/retry", status_code=status.HTTP_200_OK)
async def retry_failed(
request: QueueOperationRequest,

View File

@@ -162,7 +162,7 @@ class DownloadRequest(BaseModel):
..., min_length=1, description="Series name for display"
)
episodes: List[EpisodeIdentifier] = Field(
..., min_length=1, description="List of episodes to download"
..., description="List of episodes to download"
)
priority: DownloadPriority = Field(
DownloadPriority.NORMAL, description="Priority level for queue items"
@@ -187,7 +187,7 @@ class QueueOperationRequest(BaseModel):
"""Request to perform operations on queue items."""
item_ids: List[str] = Field(
..., min_length=1, description="List of download item IDs"
..., description="List of download item IDs"
)

View File

@@ -84,12 +84,10 @@ class ConnectionManager:
for room_members in self._rooms.values():
room_members.discard(connection_id)
# Remove empty rooms
self._rooms = {
room: members
for room, members in self._rooms.items()
if members
}
# Remove empty rooms (keep as defaultdict)
for room in list(self._rooms.keys()):
if not self._rooms[room]:
del self._rooms[room]
# Remove connection and metadata
self._active_connections.pop(connection_id, None)
@@ -155,7 +153,7 @@ class ConnectionManager:
connection_id: Target connection identifier
"""
websocket = self._active_connections.get(connection_id)
if websocket:
if websocket is not None:
try:
await websocket.send_json(message)
logger.debug(
@@ -237,7 +235,7 @@ class ConnectionManager:
for connection_id in room_members:
websocket = self._active_connections.get(connection_id)
if not websocket:
if websocket is None:
continue
try: