From 041ecfa8b5d2fc0102908cb717849847ece36992 Mon Sep 17 00:00:00 2001 From: rarebuffalo Date: Fri, 12 Jun 2026 19:10:58 +0530 Subject: [PATCH] add unit tests for local pdf exporter --- tests/test_cli_pdf.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/test_cli_pdf.py diff --git a/tests/test_cli_pdf.py b/tests/test_cli_pdf.py new file mode 100644 index 0000000..bac0ede --- /dev/null +++ b/tests/test_cli_pdf.py @@ -0,0 +1,48 @@ +import pytest +from pathlib import Path +from securelens.scanners import LocalScanResult, VulnerabilityFinding +from securelens.output.exporters import save_pdf + +@pytest.fixture(autouse=True) +def setup_db(): + # Override the database autouse fixture because these tests do not touch the DB. + pass + +def test_export_code_pdf_compiles(tmp_path): + # Setup mock result + findings = [ + VulnerabilityFinding( + file_path="app.py", + severity="Critical", + issue="Hardcoded Secret Key", + explanation="Exposing secret key inside app.py.", + suggested_fix="Load key from environment", + line_number=5 + ), + VulnerabilityFinding( + file_path="db.py", + severity="High", + issue="Raw SQL Statement", + explanation="SQL injection inside db.py.", + suggested_fix="Use parameterized queries", + line_number=20 + ) + ] + + result = LocalScanResult( + target="/home/user/project", + total_files_found=10, + files_triaged=["app.py", "db.py"], + vulnerabilities=findings, + ai_summary="This is a dummy AI report summary describing security posture." + ) + result.compute_score() + + # Save to temp PDF file + out_file = tmp_path / "report.pdf" + + from securelens.output.pdf import export_code_pdf + export_code_pdf(result, str(out_file)) + + assert out_file.exists() + assert out_file.stat().st_size > 1000 # should be non-empty PDF file