Exemplo n.º 1
0
def test_writeDockerConfig(mockOutput, mockOS, mock_open):
    """
    Test that the writeDockerConfig function does it's job.
    """
    fd = MagicMock()
    mock_open.return_value = fd
    #Test we get a warning and nothing else if path doesn't exist
    mockOS.path.exists.return_value = False
    dockerapi.writeDockerConfig()
    assert not mock_open.called
    assert len(mockOS.method_calls) == 1

    #Test that it writes if we find path
    mockOS.path.exists.side_effect = [True, False, True]
    mockOS.listdir.return_value = ['/root', '/var']
    dockerapi.writeDockerConfig()
    assert mock_open.call_count == 1
    file_handle = mock_open.return_value.__enter__.return_value
    file_handle.write.assert_called_once_with(DOCKER_CONF)

    #Test that we handle an excpetion when opening
    mockOS.path.exists.side_effect = None
    mockOS.path.exists.return_value = True
    mockOS.listdir.return_value = ['/root']
    mock_open.side_effect = Exception('Blammo!')
    dockerapi.writeDockerConfig()
    assert mock_open.call_count == 2
Exemplo n.º 2
0
def initializeSystem():
    """
    Perform some initialization steps such as writing important configuration.
    """
    dockerapi.writeDockerConfig()