def test_write_configuration_not_installed_not_running(self):
    self.patch('zaza.utilities.installers.user_directory', name='mock_user_directory')
    self.mock_user_directory.return_value = '/some/dir'
    self.patch_object(self.c, 'install', name='mock_c_install')
    self.patch_object(self.c, 'is_running', name='mock_c_is_running')
    self.mock_c_is_running.return_value = False
    self.patch_object(self.c, 'restart', name='mock_c_restart')
    mock_scp_fn = mock.Mock()
    self.c._scp_fn = mock_scp_fn
    mock_ssh_fn = mock.Mock()
    self.c._ssh_fn = mock_ssh_fn
    self.patch('yaml.dump', name='mock_yaml_dump')
    self.patch('tempfile.TemporaryDirectory', name='mock_TemporaryDirectory')
    mock_td = mock.MagicMock()
    mock_td.__enter__.return_value = '/target'
    self.mock_TemporaryDirectory.return_value = mock_td
    with tests_utils.patch_open() as (mock_open, mock_file):
        self.c.write_configuration()
    self.mock_c_install.assert_called_once_with()
    mock_open.assert_called_once_with('/target/config.yaml', 'wt')
    expected_config = {'name': 'base', 'file-log-path': '/some/dir/conncheck.log', 'collection': 'a-collection', 'log-format': 'InfluxDB', 'listeners': [], 'speakers': []}
    self.mock_yaml_dump.assert_called_once_with(expected_config, mock_file)
    mock_scp_fn.assert_called_once_with('/target/config.yaml', 'config.yaml')
    mock_ssh_fn.assert_called_once_with(['sudo', 'mv', 'config.yaml', '/some/dir/config.yaml'])
    self.mock_c_is_running.assert_called_once_with()
    self.mock_c_restart.assert_not_called()
def test_write_configuration_not_installed_not_running(self):
    self.patch('zaza.utilities.installers.user_directory', name='mock_user_directory')
    self.mock_user_directory.return_value = '/some/dir'
    self.patch_object(self.c, 'install', name='mock_c_install')
    self.patch_object(self.c, 'is_running', name='mock_c_is_running')
    self.mock_c_is_running.return_value = False
    self.patch_object(self.c, 'restart', name='mock_c_restart')
    mock_scp_fn = mock.Mock()
    self.c._scp_fn = mock_scp_fn
    mock_ssh_fn = mock.Mock()
    self.c._ssh_fn = mock_ssh_fn
    self.patch('yaml.dump', name='mock_yaml_dump')
    self.patch('tempfile.TemporaryDirectory', name='mock_TemporaryDirectory')
    mock_td = mock.MagicMock()
    mock_td.__enter__.return_value = '/target'
    self.mock_TemporaryDirectory.return_value = mock_td
    with tests_utils.patch_open() as (mock_open, mock_file):
        self.c.write_configuration()
    self.mock_c_install.assert_called_once_with()
    mock_open.assert_called_once_with('/target/config.yaml', 'wt')
    expected_config = {'name': 'base', 'file-log-path': '/some/dir/conncheck.log', 'collection': 'a-collection', 'log-format': 'InfluxDB', 'listeners': [], 'speakers': []}
    self.mock_yaml_dump.assert_called_once_with(expected_config, mock_file)
    mock_scp_fn.assert_called_once_with('/target/config.yaml', 'config.yaml')
    mock_ssh_fn.assert_called_once_with(['sudo', 'mv', 'config.yaml', '/some/dir/config.yaml'])
    self.mock_c_is_running.assert_called_once_with()
    self.mock_c_restart.assert_not_called()