mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add missing unit tests
This commit is contained in:
parent
60f856f73d
commit
8d66fac74c
2 changed files with 136 additions and 10 deletions
|
@ -166,7 +166,7 @@ def get_capabilities(image=None):
|
|||
'/Get-Capabilities']
|
||||
out = __salt__['cmd.run'](cmd)
|
||||
|
||||
pattern = r'Capability Identity : (.*)'
|
||||
pattern = r'Capability Identity : (.*)\r\n'
|
||||
capabilities = re.findall(pattern, out, re.MULTILINE)
|
||||
capabilities.sort()
|
||||
|
||||
|
@ -365,11 +365,11 @@ def get_features(package=None, image=None):
|
|||
|
||||
out = __salt__['cmd.run'](cmd)
|
||||
|
||||
pattern = r'Feature Name : (.*)'
|
||||
capabilities = re.findall(pattern, out, re.MULTILINE)
|
||||
capabilities.sort()
|
||||
pattern = r'Feature Name : (.*)\r\n'
|
||||
features = re.findall(pattern, out, re.MULTILINE)
|
||||
features.sort()
|
||||
|
||||
return capabilities
|
||||
return features
|
||||
|
||||
|
||||
def installed_features(image=None):
|
||||
|
|
|
@ -20,7 +20,7 @@ dism.__salt__ = {}
|
|||
dism.__grains__ = {}
|
||||
|
||||
|
||||
class DISMTestCase(TestCase):
|
||||
class WinDismTestCase(TestCase):
|
||||
|
||||
def test_add_capability(self):
|
||||
'''
|
||||
|
@ -59,6 +59,21 @@ class DISMTestCase(TestCase):
|
|||
['DISM', '/Quiet', '/Online', '/Remove-Capability',
|
||||
'/CapabilityName:test', '/NoRestart'])
|
||||
|
||||
def test_get_capabilities(self):
|
||||
'''
|
||||
Test getting all the capabilities
|
||||
'''
|
||||
capabilties = "Capability Identity : Capa1\r\n State : Installed\r\n" \
|
||||
"Capability Identity : Capa2\r\n State : Disabled\r\n"
|
||||
|
||||
mock = MagicMock(return_value=capabilties)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
with patch.dict(dism.__grains__, {'osversion': 10}):
|
||||
out = dism.get_capabilities()
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Online', '/Get-Capabilities'])
|
||||
self.assertEqual(out, ['Capa1', 'Capa2'])
|
||||
|
||||
def test_installed_capabilities(self):
|
||||
'''
|
||||
Test getting all the installed capabilities
|
||||
|
@ -74,6 +89,21 @@ class DISMTestCase(TestCase):
|
|||
['DISM', '/Online', '/Get-Capabilities'])
|
||||
self.assertEqual(out, ["Capa1"])
|
||||
|
||||
def test_available_capabilities(self):
|
||||
'''
|
||||
Test getting all the available capabilities
|
||||
'''
|
||||
capabilties = "Capability Identity : Capa1\r\n State : Installed\r\n" \
|
||||
"Capability Identity : Capa2\r\n State : Not Present\r\n"
|
||||
|
||||
mock = MagicMock(return_value=capabilties)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
with patch.dict(dism.__grains__, {'osversion': 10}):
|
||||
out = dism.available_capabilities()
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Online', '/Get-Capabilities'])
|
||||
self.assertEqual(out, ["Capa2"])
|
||||
|
||||
def test_add_feature(self):
|
||||
'''
|
||||
Test installing a feature with DISM
|
||||
|
@ -85,6 +115,18 @@ class DISMTestCase(TestCase):
|
|||
['DISM', '/Quiet', '/Online', '/Enable-Feature',
|
||||
'/FeatureName:test', '/NoRestart'])
|
||||
|
||||
def test_add_feature_with_extras(self):
|
||||
'''
|
||||
Test installing a feature with DISM
|
||||
'''
|
||||
mock = MagicMock()
|
||||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.add_feature('sponge', 'bob', 'C:\\temp', True, True)
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Enable-Feature',
|
||||
'/FeatureName:sponge', '/PackageName:bob', '/Source:C:\\temp',
|
||||
'/LimitAccess', '/All', '/NoRestart'])
|
||||
|
||||
def test_remove_feature(self):
|
||||
'''
|
||||
Test uninstalling a capability with DISM
|
||||
|
@ -96,19 +138,103 @@ class DISMTestCase(TestCase):
|
|||
['DISM', '/Quiet', '/Online', '/Disable-Feature',
|
||||
'/FeatureName:test', '/NoRestart'])
|
||||
|
||||
def test_installed_features(self):
|
||||
def test_remove_feature_with_extras(self):
|
||||
'''
|
||||
Test getting all the installed capabilities
|
||||
Test uninstalling a capability with DISM
|
||||
'''
|
||||
capabilties = "Feature Name : Capa1\r\n State : Enabled\r\n" \
|
||||
mock = MagicMock()
|
||||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.remove_feature('sponge', True)
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Disable-Feature',
|
||||
'/FeatureName:sponge', '/Remove', '/NoRestart'])
|
||||
|
||||
def test_get_features(self):
|
||||
'''
|
||||
Test getting all the features
|
||||
'''
|
||||
features = "Feature Name : Capa1\r\n State : Enabled\r\n" \
|
||||
"Feature Name : Capa2\r\n State : Disabled\r\n"
|
||||
|
||||
mock = MagicMock(return_value=capabilties)
|
||||
mock = MagicMock(return_value=features)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
out = dism.get_features()
|
||||
mock.assert_called_once_with(['DISM', '/Online', '/Get-Features'])
|
||||
self.assertEqual(out, ['Capa1', 'Capa2'])
|
||||
|
||||
def test_installed_features(self):
|
||||
'''
|
||||
Test getting all the installed features
|
||||
'''
|
||||
features = "Feature Name : Capa1\r\n State : Enabled\r\n" \
|
||||
"Feature Name : Capa2\r\n State : Disabled\r\n"
|
||||
|
||||
mock = MagicMock(return_value=features)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
out = dism.installed_features()
|
||||
mock.assert_called_once_with(['DISM', '/Online', '/Get-Features'])
|
||||
self.assertEqual(out, ["Capa1"])
|
||||
|
||||
def test_available_features(self):
|
||||
'''
|
||||
Test getting all the available features
|
||||
'''
|
||||
features = "Feature Name : Capa1\r\n State : Enabled\r\n" \
|
||||
"Feature Name : Capa2\r\n State : Disabled\r\n"
|
||||
|
||||
mock = MagicMock(return_value=features)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
out = dism.available_features()
|
||||
mock.assert_called_once_with(['DISM', '/Online', '/Get-Features'])
|
||||
self.assertEqual(out, ["Capa2"])
|
||||
|
||||
def test_add_package(self):
|
||||
'''
|
||||
Test installing a package with DISM
|
||||
'''
|
||||
mock = MagicMock()
|
||||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.add_package("test")
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Add-Package',
|
||||
'/PackagePath:test', '/NoRestart'])
|
||||
|
||||
def test_add_package_with_extras(self):
|
||||
'''
|
||||
Test installing a package with DISM
|
||||
'''
|
||||
mock = MagicMock()
|
||||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.add_package('sponge', True, True)
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Add-Package',
|
||||
'/PackagePath:sponge', '/IgnoreCheck', '/PreventPending',
|
||||
'/NoRestart'])
|
||||
|
||||
def test_remove_package(self):
|
||||
'''
|
||||
Test uninstalling a package with DISM
|
||||
'''
|
||||
mock = MagicMock()
|
||||
with patch.dict(dism.__salt__, {'cmd.run_all': mock}):
|
||||
dism.remove_package("test")
|
||||
mock.assert_called_once_with(
|
||||
['DISM', '/Quiet', '/Online', '/Remove-Package', '/NoRestart',
|
||||
'/PackagePath:test'])
|
||||
|
||||
def test_installed_packages(self):
|
||||
'''
|
||||
Test getting all the installed features
|
||||
'''
|
||||
features = "Package Identity : Capa1\r\n State : Installed\r\n" \
|
||||
"Package Identity : Capa2\r\n State : Installed\r\n"
|
||||
|
||||
mock = MagicMock(return_value=features)
|
||||
with patch.dict(dism.__salt__, {'cmd.run': mock}):
|
||||
out = dism.installed_packages()
|
||||
mock.assert_called_once_with(['DISM', '/Online', '/Get-Packages'])
|
||||
self.assertEqual(out, ['Capa1', 'Capa2'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(DISMTestCase, needs_daemon=False)
|
||||
|
|
Loading…
Add table
Reference in a new issue