From 77678f636807677ba4e1496cd842ac2a0a718a8f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 17:53:12 +0000 Subject: [PATCH] Fix single file deletion frontend to parse JSON response properly Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- frontend/templates/files.html | 7 ++++++- tests/test_bulk_operations.py | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/frontend/templates/files.html b/frontend/templates/files.html index bd9acec7..7b01274c 100644 --- a/frontend/templates/files.html +++ b/frontend/templates/files.html @@ -501,8 +501,13 @@ }) .then(response => { if (!response.ok) { - throw new Error('Failed to delete file'); + return response.json().then(err => { + throw new Error(err.detail || 'Failed to delete file'); + }); } + return response.json(); + }) + .then(data => { // Reload the page to show updated file list window.location.reload(); }) diff --git a/tests/test_bulk_operations.py b/tests/test_bulk_operations.py index 97224d4d..cd7dc5b6 100644 --- a/tests/test_bulk_operations.py +++ b/tests/test_bulk_operations.py @@ -7,6 +7,44 @@ from app.models import FileRecord, ProcessingLog from unittest.mock import patch, MagicMock +@pytest.mark.integration +@pytest.mark.requires_db +class TestSingleFileOperations: + """Tests for single file operations.""" + + def test_single_file_delete_success(self, client: TestClient, db_session): + """Test deletion of a single file.""" + # Create a sample file + file_record = FileRecord( + filehash="hash1", + original_filename="test.pdf", + local_filename="/tmp/test.pdf", + file_size=1024, + mime_type="application/pdf" + ) + db_session.add(file_record) + db_session.commit() + file_id = file_record.id + + # Delete the file + response = client.delete(f"/api/files/{file_id}") + assert response.status_code == 200 + data = response.json() + assert data["status"] == "success" + assert f"File record {file_id} deleted successfully" in data["message"] + + # Verify file is deleted + file_record = db_session.query(FileRecord).filter(FileRecord.id == file_id).first() + assert file_record is None + + def test_single_file_delete_nonexistent(self, client: TestClient, db_session): + """Test deletion of a non-existent file.""" + response = client.delete("/api/files/9999") + assert response.status_code == 404 + data = response.json() + assert "not found" in data["detail"].lower() + + @pytest.mark.integration @pytest.mark.requires_db class TestBulkOperations: