Beispiel #1
0
class TestOVFTool(HelperTestCase):
    """Test cases for OVFTool helper class."""

    def setUp(self):
        """Test case setup function called automatically prior to each test."""
        self.helper = OVFTool()
        super(TestOVFTool, self).setUp()

    @mock.patch('COT.helpers.helper.check_output',
                return_value="Error: Unknown option: 'version'")
    @mock.patch('distutils.spawn.find_executable',
                return_value="/fake/ovftool")
    def test_invalid_version(self, *_):
        """Negative test for .version getter logic."""
        self.helper._installed = True
        with self.assertRaises(RuntimeError):
            assert self.helper.version

    @mock.patch('distutils.spawn.find_executable',
                return_value="/fake/ovftool")
    @mock.patch('COT.helpers.helper.check_output')
    @mock.patch('subprocess.check_call')
    def test_install_already_present(self, mock_check_call,
                                     mock_check_output, *_):
        """Do nothing when trying to re-install."""
        self.helper._installed = True
        self.helper.install()
        mock_check_call.assert_not_called()
        mock_check_output.assert_not_called()

    def test_install_helper_unsupported(self):
        """No support for automated installation of ovftool."""
        with mock.patch('COT.helpers.ovftool.OVFTool.path',
                        new_callable=mock.PropertyMock, return_value=None):
            with self.assertRaises(NotImplementedError):
                self.helper.install()