Skip to content

Commit 2b9e536

Browse files
committed
Update old constructor to use current Mock(spec=CliConfig) pattern, plus other test fixes
Signed-off-by: lelia <lelia@socket.dev>
1 parent ddf7ede commit 2b9e536

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

tests/unit/test_output.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,37 @@
66
class TestOutputHandler:
77
@pytest.fixture
88
def handler(self):
9-
return OutputHandler(blocking_disabled=False)
9+
from socketsecurity.config import CliConfig
10+
from unittest.mock import Mock
11+
config = Mock(spec=CliConfig)
12+
config.disable_blocking = False
13+
config.strict_blocking = False
14+
config.sarif_file = None
15+
config.sarif_reachable_only = False
16+
config.sbom_file = None
17+
return OutputHandler(config, Mock())
1018

1119
def test_report_pass_with_blocking_issues(self, handler):
1220
diff = Diff()
1321
diff.new_alerts = [Issue(error=True)]
1422
assert not handler.report_pass(diff)
1523

1624
def test_report_pass_with_blocking_disabled(self):
17-
handler = OutputHandler(blocking_disabled=True)
25+
from socketsecurity.config import CliConfig
26+
from unittest.mock import Mock
27+
config = Mock(spec=CliConfig)
28+
config.disable_blocking = True
29+
config.strict_blocking = False
30+
handler = OutputHandler(config, Mock())
1831
diff = Diff()
1932
diff.new_alerts = [Issue(error=True)]
2033
assert handler.report_pass(diff)
2134

22-
def test_json_output_format(self, handler, capsys):
35+
def test_json_output_format(self, handler, caplog):
36+
import logging
2337
diff = Diff()
38+
diff.id = "test-scan-id"
39+
diff.diff_url = "https://socket.dev/test"
2440
test_issue = Issue(
2541
title="Test",
2642
severity="high",
@@ -35,15 +51,14 @@ def test_json_output_format(self, handler, capsys):
3551
)
3652
diff.new_alerts = [test_issue]
3753

38-
handler.output_console_json(diff)
39-
captured = capsys.readouterr()
54+
with caplog.at_level(logging.INFO, logger="socketcli"):
55+
handler.output_console_json(diff)
4056

41-
# Parse the JSON output and verify structure
42-
output = json.loads(captured.out)
43-
assert output["issues"][0]["title"] == "Test"
44-
assert output["issues"][0]["severity"] == "high"
45-
assert output["issues"][0]["blocking"] is True
46-
assert output["issues"][0]["description"] == "Test description"
57+
output = json.loads(caplog.messages[-1])
58+
assert output["new_alerts"][0]["title"] == "Test"
59+
assert output["new_alerts"][0]["severity"] == "high"
60+
assert output["new_alerts"][0]["error"] is True
61+
assert output["new_alerts"][0]["description"] == "Test description"
4762

4863
def test_sbom_file_saving(self, handler, tmp_path):
4964
# Test SBOM file is created correctly

0 commit comments

Comments
 (0)