123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- # -*- coding: utf-8 -*-
- # Import Python libs
- from __future__ import absolute_import, print_function, unicode_literals
- # Import Salt Libs
- import salt.modules.win_dism as dism
- # Import Salt Testing Libs
- from tests.support.mixins import LoaderModuleMockMixin
- from tests.support.mock import MagicMock, patch
- from tests.support.unit import TestCase
- class WinDismTestCase(TestCase, LoaderModuleMockMixin):
- def setup_loader_modules(self):
- return {dism: {}}
- def test_add_capability(self):
- """
- Test installing a capability with DISM
- """
- mock = MagicMock()
- with patch.dict(dism.__salt__, {"cmd.run_all": mock}):
- with patch.dict(dism.__grains__, {"osversion": 10}):
- dism.add_capability("test")
- mock.assert_called_once_with(
- [
- dism.bin_dism,
- "/Quiet",
- "/Online",
- "/Add-Capability",
- "/CapabilityName:test",
- "/NoRestart",
- ]
- )
- def test_add_capability_with_extras(self):
- """
- Test installing a capability with DISM
- """
- mock = MagicMock()
- with patch.dict(dism.__salt__, {"cmd.run_all": mock}):
- with patch.dict(dism.__grains__, {"osversion": 10}):
- dism.add_capability("test", "life", True)
- mock.assert_called_once_with(
- [
- dism.bin_dism,
- "/Quiet",
- "/Online",
- "/Add-Capability",
- "/CapabilityName:test",
- "/Source:life",
- "/LimitAccess",
- "/NoRestart",
- ]
- )
- def test_remove_capability(self):
- """
- Test uninstalling a capability with DISM
- """
- mock = MagicMock()
- with patch.dict(dism.__salt__, {"cmd.run_all": mock}):
- with patch.dict(dism.__grains__, {"osversion": 10}):
- dism.remove_capability("test")
- mock.assert_called_once_with(
- [
- dism.bin_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.bin_dism, "/English", "/Online", "/Get-Capabilities"]
- )
- self.assertEqual(out, ["Capa1", "Capa2"])
- def test_installed_capabilities(self):
- """
- Test getting all the installed 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.installed_capabilities()
- mock.assert_called_once_with(
- [dism.bin_dism, "/English", "/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.bin_dism, "/English", "/Online", "/Get-Capabilities"]
- )
- self.assertEqual(out, ["Capa2"])
- def test_add_feature(self):
- """
- Test installing a feature with DISM
- """
- mock = MagicMock()
- with patch.dict(dism.__salt__, {"cmd.run_all": mock}):
- dism.add_feature("test")
- mock.assert_called_once_with(
- [
- dism.bin_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.bin_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
- """
- mock = MagicMock()
- with patch.dict(dism.__salt__, {"cmd.run_all": mock}):
- dism.remove_feature("test")
- mock.assert_called_once_with(
- [
- dism.bin_dism,
- "/Quiet",
- "/Online",
- "/Disable-Feature",
- "/FeatureName:test",
- "/NoRestart",
- ]
- )
- def test_remove_feature_with_extras(self):
- """
- Test uninstalling a capability with DISM
- """
- mock = MagicMock()
- with patch.dict(dism.__salt__, {"cmd.run_all": mock}):
- dism.remove_feature("sponge", True)
- mock.assert_called_once_with(
- [
- dism.bin_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=features)
- with patch.dict(dism.__salt__, {"cmd.run": mock}):
- out = dism.get_features()
- mock.assert_called_once_with(
- [dism.bin_dism, "/English", "/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.bin_dism, "/English", "/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.bin_dism, "/English", "/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.bin_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.bin_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.bin_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.bin_dism, "/English", "/Online", "/Get-Packages"]
- )
- self.assertEqual(out, ["Capa1", "Capa2"])
|