def test_install_force(self): mock = MagicMock(return_value={'retval': 0}) with patch.dict(cpan.__salt__, {'cmd.run_all': mock}): with patch.object(cpan, 'show', MagicMock()): # Pass a list of mirrors cpan.install('Module', force=True) self.assertIn("-f", mock.call_args[0][0])
def test_install_mirror(self): mock = MagicMock(return_value={'retval': 0}) mirrors = ['ftp://mirror1.org', 'http://mirror2.org'] with patch.dict(cpan.__salt__, {'cmd.run_all': mock}): with patch.object(cpan, 'show', MagicMock()): # Pass a list of mirrors cpan.install('Module', mirror=mirrors, bin_env='') self.assertIn("-M", mock.call_args[0][0]) self.assertIn(",".join(mirrors), mock.call_args[0][0]) # Same test but pass a string instead of a list cpan.install('Module', mirror=",".join(mirrors), bin_env='') self.assertIn(",".join(mirrors), mock.call_args[0][0])
def test_install_error(self): ''' Test if it install a module from cpan ''' mock = MagicMock(return_value="don't know what it is") with patch.dict(cpan.__salt__, {'cmd.run': mock}): self.assertDictEqual(cpan.install('Alloy'), {'error': 'CPAN cannot identify this package', 'new': None, 'old': None})
def test_install(self): ''' Test if it install a module from cpan ''' mock = MagicMock(return_value='') with patch.dict(cpan.__salt__, {'cmd.run': mock}): mock = MagicMock(side_effect=[{'installed version': None}, {'installed version': '3.1'}]) with patch.object(cpan, 'show', mock): self.assertDictEqual(cpan.install('Alloy'), {'new': '3.1', 'old': None})
def test_install_error(self): ''' Test if it install a module from cpan ''' mock = MagicMock(return_value={'retval': 1}) module = 'File::Temp' with patch.dict(cpan.__salt__, {'cmd.run_all': mock}): self.assertDictEqual(cpan.install(module), { 'error': 'Could not find package {}'.format(module), 'new': {}, 'old': {}})
def test_install_error(self): ''' Test if it install a module from cpan ''' mock = MagicMock(return_value="don't know what it is") with patch.dict(cpan.__salt__, {'cmd.run': mock}): self.assertDictEqual( cpan.install('Alloy'), { 'error': 'CPAN cannot identify this package', 'new': None, 'old': None })
def test_install_error(self): """ Test if it install a module from cpan """ mock = MagicMock(return_value="don't know what it is") with patch.dict(cpan.__salt__, {"cmd.run": mock}): self.assertDictEqual( cpan.install("Alloy"), { "error": "CPAN cannot identify this package", "new": None, "old": None, }, )
def test_install(self): ''' Test if it install a module from cpan ''' mock = MagicMock(return_value='') with patch.dict(cpan.__salt__, {'cmd.run': mock}): mock = MagicMock(side_effect=[{ 'installed version': None }, { 'installed version': '3.1' }]) with patch.object(cpan, 'show', mock): self.assertDictEqual(cpan.install('Alloy'), { 'new': '3.1', 'old': None })
def test_install(self): ''' Test if it install a module from cpan ''' module = 'File::Temp' mock1 = MagicMock(return_value={'retval': 0}) with patch.dict(cpan.__salt__, {'cmd.run_all': mock1}): mock = MagicMock(side_effect=[{'installed version': None}, {'installed version': '3.1'}]) with patch.object(cpan, 'show', mock): self.assertDictEqual(cpan.install(module), { 'new': {'installed version': '3.1'}, 'old': {'installed version': None}, 'error': None}) self.assertIn("-i", mock1.call_args[0][0]) self.assertIn(module, mock1.call_args[0][0])
def test_install(self): """ Test if it install a module from cpan """ mock = MagicMock(return_value="") with patch.dict(cpan.__salt__, {"cmd.run": mock}): mock = MagicMock(side_effect=[{ "installed version": None }, { "installed version": "3.1" }]) with patch.object(cpan, "show", mock): self.assertDictEqual(cpan.install("Alloy"), { "new": "3.1", "old": None })
class CpanTestCase(TestCase, LoaderModuleMockMixin): """ Test cases for salt.modules.cpan ''' # 'install' function tests: 2 def setup_loader_modules(self): return {cpan: {}} def test__get_binary_no_env(self): # Verify that the name of the default cpan executable starts with 'cpan' with patch.object(salt.utils.path, 'which', MagicMock(return_value='/usr/bin/cpan')): bin_path = cpan._get_cpan_bin() self.assertEqual('cpan', os.path.split(bin_path)[-1]) def test__get_binary(self): # Verify that the name of the default cpan executable starts with 'cpan' with patch('os.access', lambda path, mode: True): with patch.object(os.path, 'isfile', MagicMock(return_value=True)): bin_path = cpan._get_cpan_bin('cpan') self.assertEqual('cpan', os.path.split(bin_path)[-1]) def test_get_version(self): mock = MagicMock(return_value={ 'installed version': '2.26', 'installed file': "", 'cpan build dirs': [] } ) with patch.object(cpan, 'show', mock): self.assertEqual(cpan.version(), "2.26") def test_install(self): """ Test if it install a module from cpan ''' module = 'File::Temp' mock1 = MagicMock(return_value={'retval': 0}) with patch.dict(cpan.__salt__, {'cmd.run_all': mock1}): mock = MagicMock(side_effect=[{'installed version': None}, {'installed version': '3.1'}]) with patch.object(cpan, 'show', mock): self.assertDictEqual(cpan.install(module), { 'new': {'installed version': '3.1'}, 'old': {'installed version': None}, 'error': None}) self.assertIn("-i", mock1.call_args[0][0]) self.assertIn(module, mock1.call_args[0][0]) def test_install_mirror(self): mock = MagicMock(return_value={'retval': 0}) mirrors = ['ftp://mirror1.org', 'http://mirror2.org'] with patch.dict(cpan.__salt__, {'cmd.run_all': mock}): with patch.object(cpan, 'show', MagicMock()): # Pass a list of mirrors cpan.install('Module', mirror=mirrors, bin_env='') self.assertIn("-M", mock.call_args[0][0]) self.assertIn(",".join(mirrors), mock.call_args[0][0]) # Same test but pass a string instead of a list cpan.install('Module', mirror=",".join(mirrors), bin_env='') self.assertIn(",".join(mirrors), mock.call_args[0][0]) def test_install_notest(self): mock = MagicMock(return_value={'retval': 0}) with patch.dict(cpan.__salt__, {'cmd.run_all': mock}): with patch.object(cpan, 'show', MagicMock()): # Pass a list of mirrors cpan.install('Module', notest=True) self.assertIn("-T", mock.call_args[0][0]) def test_install_force(self): mock = MagicMock(return_value={'retval': 0}) with patch.dict(cpan.__salt__, {'cmd.run_all': mock}): with patch.object(cpan, 'show', MagicMock()): # Pass a list of mirrors cpan.install('Module', force=True) self.assertIn("-f", mock.call_args[0][0]) def test_install_error(self): """ Test if it install a module from cpan ''' mock = MagicMock(return_value={'retval': 1}) module = 'File::Temp' with patch.dict(cpan.__salt__, {'cmd.run_all': mock}): self.assertDictEqual(cpan.install(module), { 'error': 'Could not find package {}'.format(module), 'new': {}, 'old': {}})