def test_collect_vm_info(self, mock_get_ssh_client): """Test collect_vm_info method. """ distro = MagicMock() client = MagicMock() distro.get_vm_info.return_value = \ 'Failed to collect VM info: Does not exist.' mock_get_ssh_client.return_value = client cloud = IpaCloud(*args, **self.kwargs) cloud.distro = distro cloud.log_file = 'fake_file.name' cloud.logger = MagicMock() with patch('builtins.open', create=True) as mock_open: mock_open.return_value = MagicMock(spec=io.IOBase) file_handle = mock_open.return_value.__enter__.return_value cloud._collect_vm_info() file_handle.write.assert_has_calls([ call('\n'), call('Failed to collect VM info: Does not exist.') ]) cloud.logger.info.assert_called_once_with( 'Collecting basic info about VM') assert mock_get_ssh_client.call_count == 1
def test_cloud_install_package(self): client = MagicMock() distro = MagicMock() distro.install_package.return_value = 'package install successful!' cloud = IpaCloud(*args, **self.kwargs) cloud.log_file = 'fake_file.name' cloud.distro = distro with patch('builtins.open', create=True) as mock_open: mock_open.return_value = MagicMock(spec=io.IOBase) file_handle = mock_open.return_value.__enter__.return_value cloud.install_package(client, 'python') file_handle.write.assert_has_calls( [call('\n'), call('package install successful!')])