Merge pull request #143 from christianlouis/copilot/fix-file-upload-tests

fix(tests): Fix Celery task mocking in file upload tests
This commit is contained in:
Christian Krakau-Louis
2026-02-08 17:59:22 +01:00
committed by GitHub
+8 -8
View File
@@ -20,19 +20,19 @@ from fastapi.testclient import TestClient
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_celery_tasks(): def mock_celery_tasks():
"""Mock all Celery tasks to prevent execution.""" """Mock all Celery tasks to prevent execution."""
# Patch where the tasks are USED (in app.api.files), not where they're defined # Patch the entire task object where it's used (in app.api.files)
with patch("app.api.files.process_document.delay") as mock_process, \ with patch("app.api.files.process_document") as mock_process_task, \
patch("app.api.files.convert_to_pdf.delay") as mock_convert: patch("app.api.files.convert_to_pdf") as mock_convert_task:
# Setup default return values # Setup default return values for .delay()
mock_task = MagicMock() mock_task = MagicMock()
mock_task.id = "test-task-id-123" mock_task.id = "test-task-id-123"
mock_process.return_value = mock_task mock_process_task.delay.return_value = mock_task
mock_convert.return_value = mock_task mock_convert_task.delay.return_value = mock_task
yield { yield {
"process_document": mock_process, "process_document": mock_process_task.delay,
"convert_to_pdf": mock_convert "convert_to_pdf": mock_convert_task.delay
} }