2.5 KiB
2.5 KiB
Problem Description
7 tests in tests/test_file_upload.py are failing in the CI pipeline due to Celery task mocking issues. The tests expect the delay method to be called once, but it's being called 0 times.
Failing Tests
test_upload_valid_text_filetest_upload_valid_image_jpegtest_upload_valid_png_imagetest_upload_office_document_docxtest_upload_csv_filetest_upload_executable_filetest_image_by_extension
Error Message
AssertionError: Expected 'delay' to have been called once. Called 0 times.
Root Cause Analysis
The test fixture mock_celery_tasks is patching the Celery tasks at:
app.api.files.process_document.delayapp.api.files.convert_to_pdf.delay
However, looking at the actual implementation in app/api/files.py (lines 656, 662, 669, 674), the tasks are invoked using .delay() method correctly:
- Line 656:
task = process_document.delay(target_path, original_filename=safe_filename) - Line 662:
task = convert_to_pdf.delay(target_path, original_filename=safe_filename) - Line 669:
task = convert_to_pdf.delay(target_path, original_filename=safe_filename) - Line 674:
task = convert_to_pdf.delay(target_path, original_filename=safe_filename)
The issue is that the patches are applied correctly but the mocks are not being invoked. This suggests:
- The patch path might need adjustment
- The tasks might be imported/accessed differently at runtime
- There might be an issue with how the tasks are being called in the test environment
Files to Fix
tests/test_file_upload.py- Fix the mock patching in themock_celery_tasksfixture (lines 20-36)
Expected Behavior
All tests should pass with 100% success rate. The mocked Celery tasks should be called appropriately when files are uploaded through the /api/ui-upload endpoint.
Solution Approach
- Verify the correct patch path for the Celery tasks
- Ensure the patch is applied before the import of the tasks
- Consider patching at the module level where tasks are defined rather than where they're used
- Alternative: Patch the task objects directly:
app.tasks.process_document.process_documentandapp.tasks.convert_to_pdf.convert_to_pdf
Reference
- Failing job: https://github.com/christianlouis/DocuElevate/actions/runs/21801196852/job/62896908441
- Commit:
17795620c6
Acceptance Criteria
- All 7 failing tests pass
- Total test suite passes with 180/180 tests passing (currently 173/180)
- CI pipeline succeeds
- No regression in other tests