style: fix linting issues (whitespace and formatting)

- Remove trailing whitespace from blank lines
- Apply black formatting to test file
- All tests still pass

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-09 21:05:44 +00:00
parent 43b512fee8
commit 3d2b21b3c8
2 changed files with 113 additions and 143 deletions
+34 -64
View File
@@ -9,6 +9,7 @@ Tests cover:
- Security issues (path traversal)
- Error handling
"""
import io
import os
import pytest
@@ -21,8 +22,10 @@ from fastapi.testclient import TestClient
def mock_celery_tasks():
"""Mock all Celery tasks to prevent execution."""
# Patch the entire task object where it's used (in app.api.files)
with patch("app.api.files.process_document") as mock_process_task, \
patch("app.api.files.convert_to_pdf") as mock_convert_task:
with (
patch("app.api.files.process_document") as mock_process_task,
patch("app.api.files.convert_to_pdf") as mock_convert_task,
):
# Setup default return values for .delay()
mock_task = MagicMock()
@@ -30,10 +33,7 @@ def mock_celery_tasks():
mock_process_task.delay.return_value = mock_task
mock_convert_task.delay.return_value = mock_task
yield {
"process_document": mock_process_task.delay,
"convert_to_pdf": mock_convert_task.delay
}
yield {"process_document": mock_process_task.delay, "convert_to_pdf": mock_convert_task.delay}
@pytest.mark.integration
@@ -43,10 +43,7 @@ class TestValidFileUploads:
def test_upload_valid_pdf(self, client: TestClient, sample_pdf_path: str, mock_celery_tasks):
"""Test uploading a valid PDF file."""
with open(sample_pdf_path, "rb") as f:
response = client.post(
"/api/ui-upload",
files={"file": ("document.pdf", f, "application/pdf")}
)
response = client.post("/api/ui-upload", files={"file": ("document.pdf", f, "application/pdf")})
assert response.status_code == 200
data = response.json()
@@ -71,8 +68,7 @@ class TestValidFileUploads:
"""Test uploading a valid text file."""
text_content = b"This is a test text file.\nWith multiple lines."
response = client.post(
"/api/ui-upload",
files={"file": ("document.txt", io.BytesIO(text_content), "text/plain")}
"/api/ui-upload", files={"file": ("document.txt", io.BytesIO(text_content), "text/plain")}
)
assert response.status_code == 200
@@ -92,10 +88,7 @@ class TestValidFileUploads:
b"\xff\xd9"
)
response = client.post(
"/api/ui-upload",
files={"file": ("image.jpg", io.BytesIO(jpeg_content), "image/jpeg")}
)
response = client.post("/api/ui-upload", files={"file": ("image.jpg", io.BytesIO(jpeg_content), "image/jpeg")})
assert response.status_code == 200
data = response.json()
@@ -114,8 +107,7 @@ class TestValidFileUploads:
)
response = client.post(
"/api/ui-upload",
files={"file": ("screenshot.png", io.BytesIO(png_content), "image/png")}
"/api/ui-upload", files={"file": ("screenshot.png", io.BytesIO(png_content), "image/png")}
)
assert response.status_code == 200
@@ -127,17 +119,17 @@ class TestValidFileUploads:
def test_upload_office_document_docx(self, client: TestClient, mock_celery_tasks):
"""Test uploading a Word document."""
# Create minimal DOCX content (ZIP file with proper structure)
docx_content = (
b"PK\x03\x04\x14\x00\x00\x00\x08\x00" + b"\x00" * 50
)
docx_content = b"PK\x03\x04\x14\x00\x00\x00\x08\x00" + b"\x00" * 50
response = client.post(
"/api/ui-upload",
files={"file": (
"report.docx",
io.BytesIO(docx_content),
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)}
files={
"file": (
"report.docx",
io.BytesIO(docx_content),
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
)
},
)
assert response.status_code == 200
@@ -152,10 +144,7 @@ class TestValidFileUploads:
"""Test uploading a CSV file."""
csv_content = b"name,age,city\nJohn,30,NYC\nJane,25,LA\n"
response = client.post(
"/api/ui-upload",
files={"file": ("data.csv", io.BytesIO(csv_content), "text/csv")}
)
response = client.post("/api/ui-upload", files={"file": ("data.csv", io.BytesIO(csv_content), "text/csv")})
assert response.status_code == 200
data = response.json()
@@ -177,8 +166,7 @@ class TestInvalidFileUploads:
mock_getsize.return_value = 501 * 1024 * 1024 # 501MB
response = client.post(
"/api/ui-upload",
files={"file": ("huge.pdf", io.BytesIO(large_content), "application/pdf")}
"/api/ui-upload", files={"file": ("huge.pdf", io.BytesIO(large_content), "application/pdf")}
)
assert response.status_code == 413 # Request Entity Too Large
@@ -189,8 +177,7 @@ class TestInvalidFileUploads:
exe_content = b"MZ\x90\x00" # PE header
response = client.post(
"/api/ui-upload",
files={"file": ("program.exe", io.BytesIO(exe_content), "application/x-msdownload")}
"/api/ui-upload", files={"file": ("program.exe", io.BytesIO(exe_content), "application/x-msdownload")}
)
# Per the code, unsupported types get a warning but are still processed
@@ -200,10 +187,7 @@ class TestInvalidFileUploads:
def test_upload_empty_file(self, client: TestClient, mock_celery_tasks):
"""Test uploading an empty file."""
response = client.post(
"/api/ui-upload",
files={"file": ("empty.txt", io.BytesIO(b""), "text/plain")}
)
response = client.post("/api/ui-upload", files={"file": ("empty.txt", io.BytesIO(b""), "text/plain")})
# Empty files are accepted and queued for processing
assert response.status_code == 200
@@ -230,8 +214,7 @@ class TestUploadSecurity:
pdf_content = b"%PDF-1.4\n%EOF"
response = client.post(
"/api/ui-upload",
files={"file": (malicious_filename, io.BytesIO(pdf_content), "application/pdf")}
"/api/ui-upload", files={"file": (malicious_filename, io.BytesIO(pdf_content), "application/pdf")}
)
assert response.status_code == 200
@@ -248,8 +231,7 @@ class TestUploadSecurity:
pdf_content = b"%PDF-1.4\n%EOF"
response = client.post(
"/api/ui-upload",
files={"file": (malicious_filename, io.BytesIO(pdf_content), "application/pdf")}
"/api/ui-upload", files={"file": (malicious_filename, io.BytesIO(pdf_content), "application/pdf")}
)
assert response.status_code == 200
@@ -265,8 +247,7 @@ class TestUploadSecurity:
pdf_content = b"%PDF-1.4\n%EOF"
response = client.post(
"/api/ui-upload",
files={"file": (special_filename, io.BytesIO(pdf_content), "application/pdf")}
"/api/ui-upload", files={"file": (special_filename, io.BytesIO(pdf_content), "application/pdf")}
)
assert response.status_code == 200
@@ -289,8 +270,7 @@ class TestUploadSecurity:
pdf_content = b"%PDF-1.4\n%EOF"
response = client.post(
"/api/ui-upload",
files={"file": (malicious_filename, io.BytesIO(pdf_content), "application/pdf")}
"/api/ui-upload", files={"file": (malicious_filename, io.BytesIO(pdf_content), "application/pdf")}
)
assert response.status_code == 200
@@ -315,8 +295,7 @@ class TestUploadSecurity:
pdf_content = b"%PDF-1.4\n%EOF"
response = client.post(
"/api/ui-upload",
files={"file": (malicious_filename, io.BytesIO(pdf_content), "application/pdf")}
"/api/ui-upload", files={"file": (malicious_filename, io.BytesIO(pdf_content), "application/pdf")}
)
assert response.status_code == 200
@@ -342,8 +321,7 @@ class TestUploadErrorHandling:
pdf_content = b"%PDF-1.4\n%EOF"
response = client.post(
"/api/ui-upload",
files={"file": ("test.pdf", io.BytesIO(pdf_content), "application/pdf")}
"/api/ui-upload", files={"file": ("test.pdf", io.BytesIO(pdf_content), "application/pdf")}
)
assert response.status_code == 500
@@ -358,10 +336,7 @@ class TestUploadErrorHandling:
# The endpoint should still handle the error gracefully
# In this case, the exception will propagate
with pytest.raises(Exception):
client.post(
"/api/ui-upload",
files={"file": ("test.pdf", io.BytesIO(pdf_content), "application/pdf")}
)
client.post("/api/ui-upload", files={"file": ("test.pdf", io.BytesIO(pdf_content), "application/pdf")})
@pytest.mark.integration
@@ -374,13 +349,11 @@ class TestUploadFilenameHandling:
# Upload same file twice
response1 = client.post(
"/api/ui-upload",
files={"file": ("same.pdf", io.BytesIO(pdf_content), "application/pdf")}
"/api/ui-upload", files={"file": ("same.pdf", io.BytesIO(pdf_content), "application/pdf")}
)
response2 = client.post(
"/api/ui-upload",
files={"file": ("same.pdf", io.BytesIO(pdf_content), "application/pdf")}
"/api/ui-upload", files={"file": ("same.pdf", io.BytesIO(pdf_content), "application/pdf")}
)
assert response1.status_code == 200
@@ -400,8 +373,7 @@ class TestUploadFilenameHandling:
content = b"Some content"
response = client.post(
"/api/ui-upload",
files={"file": ("NOEXTENSION", io.BytesIO(content), "application/octet-stream")}
"/api/ui-upload", files={"file": ("NOEXTENSION", io.BytesIO(content), "application/octet-stream")}
)
assert response.status_code == 200
@@ -420,8 +392,7 @@ class TestUploadMimeTypeDetection:
pdf_content = b"%PDF-1.4\n%EOF"
response = client.post(
"/api/ui-upload",
files={"file": ("doc.pdf", io.BytesIO(pdf_content), "application/octet-stream")}
"/api/ui-upload", files={"file": ("doc.pdf", io.BytesIO(pdf_content), "application/octet-stream")}
)
assert response.status_code == 200
@@ -434,8 +405,7 @@ class TestUploadMimeTypeDetection:
image_content = b"\x00\x01\x02\x03"
response = client.post(
"/api/ui-upload",
files={"file": ("photo.jpg", io.BytesIO(image_content), "application/octet-stream")}
"/api/ui-upload", files={"file": ("photo.jpg", io.BytesIO(image_content), "application/octet-stream")}
)
assert response.status_code == 200