Skip to content

Add unit tests for PDF export endpoint #72

@bradjin8

Description

@bradjin8

Repository: cppa-cursor-browser
Assignee: Brad @bradjin8
Points: 3
Severity: Medium

Problem

The PDF export endpoint (api/pdf.py) has no dedicated unit tests. The endpoint generates PDF output via fpdf2 from conversation data, but its rendering correctness, error handling for missing/malformed conversations, and edge cases (empty conversations, very long content, Unicode characters) are unverified. The eval notes this as part of the broader "Unverified Pipeline" — the best-tested code is at the boundaries while interior pipeline paths lack dedicated coverage.

Acceptance Criteria

  • A new test file tests/test_pdf_export.py (or equivalent) is created
  • At least 5 test cases cover: successful PDF generation for a normal conversation, empty conversation handling, very long content handling, Unicode/emoji content, and error response when the conversation ID is invalid
  • Tests verify: HTTP status codes, Content-Type header (application/pdf), non-empty response body, and that the PDF is valid (parseable by a basic check)
  • Tests use Flask's test client (consistent with existing API tests)
  • Tests pass in CI
  • PR approved by at least 1 reviewer

Implementation Notes

Follow the pattern of existing API tests in tests/. Use Flask's test_client() to make requests to the PDF endpoint. For PDF validation, a simple check is sufficient: verify the response starts with %PDF- (the PDF magic bytes) or use fpdf2's own parsing if available. Mock the service layer to provide controlled conversation data. The fpdf2 library (pinned with Pillow >=12.2.0,<13 per CVE comment in pyproject.toml) handles the actual PDF generation — focus tests on the endpoint's integration of data retrieval and PDF rendering, not on fpdf2 internals.

References

  • Eval finding: Test 30 (Test Presence) — part of the "Unverified Dark Path" compound
  • Related files: api/pdf.py, tests/ (existing API test files for reference patterns)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions