Add remaining test files: test_fixes, test_llm, test_generate, test_report, test_utils
This commit is contained in:
78
tests/test_report.py
Normal file
78
tests/test_report.py
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import pytest
|
||||||
|
from pathlib import Path
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from config_auditor.report import ReportGenerator
|
||||||
|
from config_auditor.rules import Issue
|
||||||
|
|
||||||
|
|
||||||
|
class TestReportGenerator:
|
||||||
|
def test_to_json(self):
|
||||||
|
issues = [
|
||||||
|
Issue(
|
||||||
|
severity="critical",
|
||||||
|
category="test",
|
||||||
|
message="Test issue",
|
||||||
|
file=Path("test.json"),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
generator = ReportGenerator()
|
||||||
|
result = generator.to_json(issues)
|
||||||
|
|
||||||
|
assert "critical" in result
|
||||||
|
assert "Test issue" in result
|
||||||
|
|
||||||
|
def test_to_yaml(self):
|
||||||
|
issues = [
|
||||||
|
Issue(
|
||||||
|
severity="warning",
|
||||||
|
category="test",
|
||||||
|
message="Warning issue",
|
||||||
|
file=Path("test.json"),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
generator = ReportGenerator()
|
||||||
|
result = generator.to_yaml(issues)
|
||||||
|
|
||||||
|
assert "warning" in result
|
||||||
|
assert "Warning issue" in result
|
||||||
|
|
||||||
|
def test_to_text(self):
|
||||||
|
issues = [
|
||||||
|
Issue(
|
||||||
|
severity="critical",
|
||||||
|
category="test",
|
||||||
|
message="Critical issue",
|
||||||
|
file=Path("test.json"),
|
||||||
|
suggestion="Fix this",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
generator = ReportGenerator()
|
||||||
|
|
||||||
|
output = []
|
||||||
|
generator.to_text(issues, output.append)
|
||||||
|
|
||||||
|
assert len(output) > 0
|
||||||
|
assert any("Critical" in line for line in output)
|
||||||
|
|
||||||
|
def test_empty_issues_text_output(self):
|
||||||
|
issues = []
|
||||||
|
generator = ReportGenerator()
|
||||||
|
|
||||||
|
output = []
|
||||||
|
generator.to_text(issues, output.append)
|
||||||
|
|
||||||
|
assert any("No issues found" in line for line in output)
|
||||||
|
|
||||||
|
def test_generate_summary(self):
|
||||||
|
issues = [
|
||||||
|
Issue(severity="critical", category="a", message="1", file=Path("f1")),
|
||||||
|
Issue(severity="critical", category="b", message="2", file=Path("f2")),
|
||||||
|
Issue(severity="warning", category="c", message="3", file=Path("f3")),
|
||||||
|
]
|
||||||
|
generator = ReportGenerator()
|
||||||
|
summary = generator.generate_summary(issues)
|
||||||
|
|
||||||
|
assert summary["total"] == 3
|
||||||
|
assert summary["by_severity"]["critical"] == 2
|
||||||
|
assert summary["by_severity"]["warning"] == 1
|
||||||
Reference in New Issue
Block a user