class TestOVFTool(HelperUT): """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() Helper.find_executable = self.stub_find_executable def test_invalid_version(self): """Negative test for .version getter logic.""" self.fake_path = "/fake/ovftool" self.fake_output = "Error: Unknown option: 'version'" with self.assertRaises(RuntimeError): self.helper.version def test_install_helper_already_present(self): """Do nothing when trying to re-install.""" self.fake_path = "/fake/ovftool" self.helper.install_helper() self.assertEqual([], self.last_argv) self.assertLogged(**self.ALREADY_INSTALLED) def test_install_helper_unsupported(self): """No support for automated installation of ovftool.""" with self.assertRaises(NotImplementedError): self.helper.install_helper() def test_validate_ovf(self): """Try the validate_ovf() API.""" self.fake_path = "/fake/ovftool" self.fake_output = "" self.helper.validate_ovf(self.input_ovf) self.assertEqual(["ovftool", "--schemaValidate", self.input_ovf], self.last_argv[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()
def setUp(self): """Test case setup function called automatically prior to each test.""" self.helper = OVFTool() super(TestOVFTool, self).setUp()
def setUp(self): """Test case setup function called automatically prior to each test.""" self.helper = OVFTool() super(TestOVFTool, self).setUp() Helper.find_executable = self.stub_find_executable