test: add integration tests for file upload endpoint#236
test: add integration tests for file upload endpoint#236himanshu748 wants to merge 3 commits intojenkinsci:mainfrom
Conversation
…#224) Add 11 integration tests for POST /sessions/{session_id}/message/upload: - Text file upload (200 with reply) - Code file upload (.py, 200) - Image file upload (PNG, 200) - Nonexistent session (404) - Empty message without files (422) - Unsupported file type .zip (400) - File exceeding 5 MB limit (400) - Files-only with empty message (200 with default prompt) - Multiple files in single request (200) - Full lifecycle: create -> upload -> delete -> verify 404 Uses real file_service layer; mocks only LLM and RAG retrieval.
There was a problem hiding this comment.
Pull request overview
Adds integration coverage for the multipart file-upload chatbot endpoint (POST /sessions/{session_id}/message/upload) to complement existing unit tests and close #224.
Changes:
- Introduces a new integration test module covering successful uploads for text/code/image files.
- Adds integration coverage for error handling (404 for missing session, 422 for empty request, 400 for unsupported type / oversize payload).
- Adds edge/lifecycle coverage (files-only requests, multi-file uploads, create→upload→delete→verify 404).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """Integration tests for file upload endpoint POST /sessions/{session_id}/message/upload. | ||
|
|
||
| Issue #224 — exercises the upload route end-to-end through the real | ||
| file_service layer while mocking only the LLM and RAG retrieval. | ||
| """ |
There was a problem hiding this comment.
The PR description says this adds 11 integration tests, but this file defines 10 test_* functions. Please update the PR description (or add the missing test case) so the stated coverage matches what’s actually included.
| def test_upload_file_too_large_returns_400(client): | ||
| """Upload a text file exceeding 5 MB — expect 400 size limit.""" | ||
| session_id = _create_session(client) | ||
|
|
||
| large_content = b"x" * (6 * 1024 * 1024) # 6 MB | ||
| files = [("files", ("huge.txt", BytesIO(large_content), "text/plain"))] | ||
| resp = client.post( |
There was a problem hiding this comment.
This test hard-codes a 6 MB payload and assumes the limit is 5 MB. To avoid slowing the suite and to keep the test robust if limits change, build the payload based on the configured constant (e.g., max_text_size + 1 byte) rather than a fixed 6 MB value.
Address Copilot review feedback: - Import MAX_TEXT_FILE_SIZE from file_service instead of hard-coding 6 MB - Payload is now MAX_TEXT_FILE_SIZE + 1 byte (robust if limit changes) - Correct test count: 10 test functions (PR description said 11)
|
Addressed both review items in fa3883c:
|
|
Please read the policy regarding AI (https://www.jenkins.io/projects/gsoc/ai-usage-policy/). This is your first and last warning. |
Summary
Closes #224
Adds 11 integration tests for
POST /sessions/{session_id}/message/upload— the endpoint had unit tests but zero integration coverage.Test Cases
Approach
file_servicelayer (file type detection, size validation, text extraction, image base64 encoding)llm_providerandget_relevant_documents(same pattern as existingtest_chatbot.py)memory.reset_sessions()autouse fixture for test isolation