mirror of
https://github.com/fsecada01/Pygentic-AI.git
synced 2026-05-12 04:04:57 +00:00
Tests mock the exact production bug scenario: - Session exists but result is None → 404 with proper Response Regression Tests: - test_download_pdf_without_session_returns_404 → No session ID error path - test_download_pdf_without_result_returns_404 → Session but no result (EXACT production bug) - test_download_pdf_error_paths_use_response_not_streaming → Verifies Response used, not StreamingResponse Additional Tests: - test_download_pdf_returns_pdf_file → Successful PDF generation and download - test_download_pdf_uses_cache → PDF caching behavior validation - test_download_pdf_filename_format → Filename format verification Mocking Strategy: - Use unittest.mock.MagicMock for request.session - Mock session.get() to return test session_id - Call download_pdf() handler directly with mocked request - Avoids TestClient session middleware complications Coverage Improvements: - pdf_service.py: 31% → 99% - pdf_cache.py: 37% → 76% - router.py: 35% → 53% - Overall: 49% → 63% All tests pass and prevent regression of AttributeError bug. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>