mirror of
https://github.com/outbackdingo/step-ca-webui.git
synced 2026-01-27 18:20:22 +00:00
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import unittest
|
|
import subprocess
|
|
from unittest.mock import patch
|
|
from shared.cli_wrapper import CLIWrapper
|
|
|
|
|
|
class TestCLIWrapper(unittest.TestCase):
|
|
|
|
@patch('subprocess.run')
|
|
def test_execute_command_success(self, mock_run):
|
|
mock_run.return_value.stdout = "Command output"
|
|
mock_run.return_value.returncode = 0
|
|
|
|
output, return_code = CLIWrapper.execute_command("test command")
|
|
|
|
self.assertEqual(output, "Command output")
|
|
self.assertEqual(return_code, 0)
|
|
mock_run.assert_called_once_with("test command", shell=True, check=True, text=True, capture_output=True)
|
|
|
|
@patch('subprocess.run')
|
|
def test_execute_command_failure(self, mock_run):
|
|
mock_run.side_effect = subprocess.CalledProcessError(1, "test command", output="Error output")
|
|
|
|
output, return_code = CLIWrapper.execute_command("test command")
|
|
|
|
self.assertEqual(output, "Error output")
|
|
self.assertEqual(return_code, 1)
|
|
mock_run.assert_called_once_with("test command", shell=True, check=True, text=True, capture_output=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|