38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
import contextlib
|
|
import io
|
|
import json
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from scripts import run_visual_snapshot_capture
|
|
|
|
|
|
class RunVisualSnapshotCaptureScriptTests(unittest.TestCase):
|
|
def test_main_outputs_json_for_capture(self) -> None:
|
|
with patch("scripts.run_visual_snapshot_capture.capture_visual_watch_snapshot") as capture_mock:
|
|
capture_mock.return_value = {
|
|
"status": "captured",
|
|
"watch_run_id": 11,
|
|
"snapshot_id": 55,
|
|
"image_path": "captures/watch-11.png",
|
|
"html_path": "captures/watch-11.html",
|
|
"artifact_path": "captures/watch-11.json",
|
|
"browser_capture_status": "captured",
|
|
}
|
|
output = io.StringIO()
|
|
with contextlib.redirect_stdout(output):
|
|
exit_code = run_visual_snapshot_capture.main(
|
|
env={"VISUAL_CAPTURE_WATCH_RUN_ID": "11", "VISUAL_CAPTURE_OUTPUT_JSON": "1", "VISUAL_CAPTURE_BROWSER_ENABLED": "1"}
|
|
)
|
|
|
|
payload = json.loads(output.getvalue())
|
|
self.assertEqual(exit_code, 0)
|
|
self.assertEqual(payload["status"], "captured")
|
|
self.assertEqual(payload["snapshot_id"], 55)
|
|
capture_mock.assert_called_once()
|
|
self.assertTrue(capture_mock.call_args.kwargs["browser_capture_enabled"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|