forked from ChelseaKR/habitable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_court_bundle.py
More file actions
81 lines (68 loc) · 3.05 KB
/
Copy pathtest_court_bundle.py
File metadata and controls
81 lines (68 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright 2026 Chelsea Kelly-Reif
"""The recipient packet: cover sheet, chronology, and an integrity summary.
Asserts both renderings carry the three recipient-facing sections and that the
accessible HTML stays structurally sound (one h1, landmarks, captioned tables).
The data layer is exercised in ``test_bundleview.py``; this is the wiring.
"""
from __future__ import annotations
from collections.abc import Callable
from pathlib import Path
from habitable.capture import capture
from habitable.packet import build_packet
from habitable.tsa import LocalRfc3161TSA
from habitable.vault import Vault
def _packet(
make_vault: Callable[..., Vault],
make_jpeg: Callable[..., Path],
tsa: LocalRfc3161TSA,
out: Path,
) -> Path:
vault = make_vault()
issue = vault.document.add_issue(category="mold", room="bath", title="Mold", issue_id="i1")
vault.document.add_timeline_entry(issue, "observed", "spreading after roof leak")
capture(vault, make_jpeg(with_location=True), issue_id=issue, tsa=tsa)
result = build_packet(vault, out, generated_at="2026-01-02T00:10:00Z")
assert result.html_path is not None and result.pdf_path is not None
return out
def test_html_packet_has_recipient_facing_sections(
make_vault: Callable[..., Vault],
make_jpeg: Callable[..., Path],
local_tsa: LocalRfc3161TSA,
tmp_path: Path,
) -> None:
out = _packet(make_vault, make_jpeg, local_tsa, tmp_path / "pkt")
html = (out / "packet.html").read_text(encoding="utf-8")
# Exactly one h1 even with the added sections (accessibility invariant).
assert html.count("<h1>") == 1
# Cover sheet, chronology, and integrity sections are all present and labelled.
assert 'id="cover-heading">Cover sheet' in html
assert 'id="chronology-heading">Chronological evidence timeline' in html
assert "Chain of custody & integrity" in html
# The chronology interleaves the note and the photo.
assert "[observed]" in html
assert "Custody chain head:" in html
def test_pdf_packet_builds_with_recipient_facing_sections(
make_vault: Callable[..., Vault],
make_jpeg: Callable[..., Path],
local_tsa: LocalRfc3161TSA,
tmp_path: Path,
) -> None:
out = _packet(make_vault, make_jpeg, local_tsa, tmp_path / "pkt")
pdf = (out / "packet.pdf").read_bytes()
assert pdf.startswith(b"%PDF-")
# The added headings are recorded in the navigable outline (uncompressed in the
# catalog), so they are findable even though body text is stream-encoded.
assert b"Cover sheet" in pdf
assert b"Chronological evidence timeline" in pdf
assert b"Chain of custody" in pdf
def test_court_sections_do_not_break_verification(
make_vault: Callable[..., Vault],
make_jpeg: Callable[..., Path],
local_tsa: LocalRfc3161TSA,
tmp_path: Path,
) -> None:
from habitable.verify import verify_packet
out = _packet(make_vault, make_jpeg, local_tsa, tmp_path / "pkt")
report = verify_packet(out, trusted_certs=[local_tsa.certificate])
assert report.ok, report.summary()