|
| 1 | +from unittest.mock import MagicMock, patch |
| 2 | + |
| 3 | +from typer.testing import CliRunner |
| 4 | + |
| 5 | +from comfy_cli.command.custom_nodes.command import app |
| 6 | + |
| 7 | +runner = CliRunner() |
| 8 | + |
| 9 | + |
| 10 | +def test_publish_fails_on_security_violations(): |
| 11 | + # Mock subprocess.run to simulate security violations |
| 12 | + mock_result = MagicMock() |
| 13 | + mock_result.returncode = 1 |
| 14 | + mock_result.stdout = "S102 Use of exec() detected" |
| 15 | + |
| 16 | + with patch("subprocess.run", return_value=mock_result): |
| 17 | + result = runner.invoke(app, ["publish"]) |
| 18 | + |
| 19 | + assert result.exit_code == 1 |
| 20 | + assert "Security issues found" in result.stdout |
| 21 | + |
| 22 | + |
| 23 | +def test_publish_continues_on_no_security_violations(): |
| 24 | + # Mock subprocess.run to simulate no violations |
| 25 | + mock_result = MagicMock() |
| 26 | + mock_result.returncode = 0 |
| 27 | + mock_result.stdout = "" |
| 28 | + |
| 29 | + with ( |
| 30 | + patch("subprocess.run", return_value=mock_result), |
| 31 | + patch("comfy_cli.command.custom_nodes.command.extract_node_configuration") as mock_extract, |
| 32 | + patch("typer.prompt") as mock_prompt, |
| 33 | + patch("comfy_cli.command.custom_nodes.command.registry_api.publish_node_version") as mock_publish, |
| 34 | + patch("comfy_cli.command.custom_nodes.command.zip_files") as mock_zip, |
| 35 | + patch("comfy_cli.command.custom_nodes.command.upload_file_to_signed_url") as mock_upload, |
| 36 | + ): |
| 37 | + # Setup the mocks |
| 38 | + mock_extract.return_value = {"name": "test-node"} |
| 39 | + mock_prompt.return_value = "test-token" |
| 40 | + mock_publish.return_value = MagicMock(signedUrl="https://test.url") |
| 41 | + |
| 42 | + # Run the publish command |
| 43 | + _result = runner.invoke(app, ["publish"]) |
| 44 | + |
| 45 | + # Verify the publish flow continued |
| 46 | + assert mock_extract.called |
| 47 | + assert mock_publish.called |
| 48 | + assert mock_zip.called |
| 49 | + assert mock_upload.called |
| 50 | + |
| 51 | + |
| 52 | +def test_publish_handles_missing_ruff(): |
| 53 | + with patch("subprocess.run", side_effect=FileNotFoundError()): |
| 54 | + result = runner.invoke(app, ["publish"]) |
| 55 | + |
| 56 | + assert result.exit_code == 1 |
| 57 | + assert "Ruff is not installed" in result.stdout |
| 58 | + |
| 59 | + |
| 60 | +def test_publish_with_token_option(): |
| 61 | + # Mock subprocess.run to simulate no violations |
| 62 | + mock_result = MagicMock() |
| 63 | + mock_result.returncode = 0 |
| 64 | + mock_result.stdout = "" |
| 65 | + |
| 66 | + with ( |
| 67 | + patch("subprocess.run", return_value=mock_result), |
| 68 | + patch("comfy_cli.command.custom_nodes.command.extract_node_configuration") as mock_extract, |
| 69 | + patch("comfy_cli.command.custom_nodes.command.registry_api.publish_node_version") as mock_publish, |
| 70 | + patch("comfy_cli.command.custom_nodes.command.zip_files") as mock_zip, |
| 71 | + patch("comfy_cli.command.custom_nodes.command.upload_file_to_signed_url") as mock_upload, |
| 72 | + ): |
| 73 | + # Setup the mocks |
| 74 | + mock_extract.return_value = {"name": "test-node"} |
| 75 | + mock_publish.return_value = MagicMock(signedUrl="https://test.url") |
| 76 | + |
| 77 | + # Run the publish command with token |
| 78 | + _result = runner.invoke(app, ["publish", "--token", "test-token"]) |
| 79 | + |
| 80 | + # Verify the publish flow worked with provided token |
| 81 | + assert mock_extract.called |
| 82 | + assert mock_publish.called |
| 83 | + assert mock_zip.called |
| 84 | + assert mock_upload.called |
0 commit comments