Skip to content

[TEST] Add unit tests for report_generator.py — JSON, CSV, PDF, HTML formats #43

@advaitpatel

Description

@advaitpatel

Overview

`report_generator.py` has zero test coverage today. It owns all 4 output formats and any regression here would silently break user-facing reports. This is a great first contribution for anyone comfortable with `pytest`.

What Needs to Be Done

Create `tests/test_report_generator.py` covering:

JSON Report

  • Output file is created at the expected path
  • Required keys present: `scan_info`, `vulnerabilities`, `severity_counts`
  • `severity_counts` correctly tallies CRITICAL / HIGH / MEDIUM / LOW
  • Empty vulnerability list → valid JSON (no crash)

CSV Report

  • Output file is created
  • Header row matches: `ID, Severity, Package, Version, Title, CVSS, Status, Target, URL`
  • Each vulnerability maps to the correct column
  • Empty input → header-only CSV

PDF Report

  • Output file is created and non-empty
  • No exception raised on valid input

HTML Report

  • Output file is created
  • No `{{` placeholders remain in the rendered output
  • HTML special characters in vulnerability data are escaped (XSS prevention check)

Suggested Fixture (add to `tests/conftest.py`)

@pytest.fixture
def sample_vulnerabilities():
    return [
        {
            "VulnerabilityID": "CVE-2023-1234",
            "Severity": "CRITICAL",
            "PkgName": "openssl",
            "InstalledVersion": "1.0.0",
            "Title": "Buffer overflow in openssl",
            "CVSS": 9.8,
            "Status": "fixed",
            "Target": "python:3.9-slim",
            "PrimaryURL": "https://nvd.nist.gov/vuln/detail/CVE-2023-1234"
        }
    ]

Files

File Action
`tests/test_report_generator.py` Create
`tests/conftest.py` Update with fixtures

Acceptance Criteria

  • >= 3 tests per output format (12 tests minimum)
  • All tests use `tmp_path` pytest fixture — no hardcoded paths
  • No real LLM calls
  • `pytest tests/test_report_generator.py -v` passes with 0 failures

Skill Level

Beginner–Intermediate Python. Familiarity with `pytest` helpful but not required.

Related Files

  • `report_generator.py`
  • `docker_scanner.py` (also generates reports inline)
  • `tests/conftest.py`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions