Exemple #1
0
def test_execute_with_unforeseen_exception():
    """
    Ensure a HelmError is raised if any other sort of exception is encountered.
    """
    mock_Popen = MagicMock(side_effect=ValueError("Boom"))
    with pytest.raises(helm.HelmError):
        with patch("controlpanel.api.helm.subprocess.Popen", mock_Popen):
            result = helm._execute("delete", "foo")
Exemple #2
0
def test_execute_with_failing_helm_command():
    """
    Ensure a HelmError is raised if the helm command returns a non-0 code.
    """
    mock_proc = MagicMock()
    mock_proc.returncode = 1  # Boom ;-)
    mock_Popen = MagicMock(return_value=mock_proc)
    with pytest.raises(helm.HelmError):
        with patch("controlpanel.api.helm.subprocess.Popen", mock_Popen):
            result = helm._execute("delete", "foo")
Exemple #3
0
def test_execute_with_failing_process():
    """
    Ensure a HelmError is raised if the subprocess was unable to run.
    """
    mock_stderr = MagicMock()
    mock_stderr.read.return_value = "boom"
    mock_Popen = MagicMock(side_effect=subprocess.CalledProcessError(
        1, "boom", stderr=mock_stderr))
    with pytest.raises(helm.HelmError):
        with patch("controlpanel.api.helm.subprocess.Popen", mock_Popen):
            result = helm._execute("delete", "foo")
Exemple #4
0
def test_execute_with_timeout():
    """
    Ensure the subprocess is waited on (blocks) for timeout seconds.
    """
    mock_proc = MagicMock()
    mock_proc.returncode = 0
    mock_Popen = MagicMock(return_value=mock_proc)
    timeout = 1
    with patch("controlpanel.api.helm.subprocess.Popen", mock_Popen):
        result = helm._execute("delete", "foo", timeout=timeout)
    assert result == mock_proc
    mock_proc.wait.assert_called_once_with(timeout)
Exemple #5
0
def test_execute_ignores_debug():
    """
    If the DEBUG flag is set in the environment, ensure this is removed before
    calling the helm command via Popen (apparently, helm checks for the
    existence of DEBUG env var, and we don't want this to happen).
    """
    mock_proc = MagicMock()
    mock_proc.returncode = 0
    mock_Popen = MagicMock(return_value=mock_proc)
    mock_environ = MagicMock()
    mock_environ.copy.return_value = {"DEBUG": "1"}
    with patch("controlpanel.api.helm.subprocess.Popen",
               mock_Popen), patch("controlpanel.api.helm.os.environ",
                                  mock_environ):
        helm._execute("delete", "foo")
    mock_Popen.assert_called_once_with(
        ["helm", "delete", "foo"],
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE,
        encoding="utf8",
        env={},  # Missing the DEBUG flag.
    )