From 0422c705f5f686ebc8d992b988b130bb29f2d31f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 8 Feb 2026 16:57:38 +0000 Subject: [PATCH] fix(tests): fix Celery task mocking in file upload tests Patch entire task objects instead of just .delay method to properly intercept Celery task calls in app.api.files module. This fixes 7 failing tests that were getting 'Expected delay to have been called once. Called 0 times.' errors. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- tests/test_file_upload.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_file_upload.py b/tests/test_file_upload.py index 24b22c96..07243a47 100644 --- a/tests/test_file_upload.py +++ b/tests/test_file_upload.py @@ -20,19 +20,19 @@ from fastapi.testclient import TestClient @pytest.fixture(autouse=True) def mock_celery_tasks(): """Mock all Celery tasks to prevent execution.""" - # Patch where the tasks are USED (in app.api.files), not where they're defined - with patch("app.api.files.process_document.delay") as mock_process, \ - patch("app.api.files.convert_to_pdf.delay") as mock_convert: + # 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: - # Setup default return values + # Setup default return values for .delay() mock_task = MagicMock() mock_task.id = "test-task-id-123" - mock_process.return_value = mock_task - mock_convert.return_value = mock_task + mock_process_task.delay.return_value = mock_task + mock_convert_task.delay.return_value = mock_task yield { - "process_document": mock_process, - "convert_to_pdf": mock_convert + "process_document": mock_process_task.delay, + "convert_to_pdf": mock_convert_task.delay }