Attachment Test 3: filter_text() Unit Tests

Status: PASSED 2026-03-16

Tests filter_text(ctype, content_bytes) in list_email_attachments.py. Pure function, no I/O. All cases assert exact expected output, not just type.

Output

PASS — all 6 cases passed

Cases Covered

1. application/json — valid JSON

Input b'{"b": 2, "a": 1}'. Expected: json.dumps({"b": 2, "a": 1}, indent=2). Asserts exact pretty-printed string equality.

2. application/json — invalid JSON

Input b'{ not valid json !!!'. Expected: '{ not valid json !!!' (raw decode, no exception).

3. text/html — tags stripped

Input b'<p>Hello <b>world</b></p>'. Expected exact output: 'Hello world'.

4. text/plain

Input b'plain text content'. Expected exact: 'plain text content'.

5. text/csv

Input b'name,age\nAlice,30\nBob,25'. Expected exact: 'name,age\nAlice,30\nBob,25' — decoded, no transformation.

6. Binary types → None

image/png, application/pdf, application/octet-stream all return None.

How to Run

cd ~/py/envoy && python3 test_filter_text.py
version 3  ·  created 2026-03-16  ·  updated 2026-03-16  ·  status passed