diff --git a/tests/unit/modules/test_cassandra_cql.py b/tests/unit/modules/test_cassandra_cql.py index 877104a09e..e5da9790d6 100644 --- a/tests/unit/modules/test_cassandra_cql.py +++ b/tests/unit/modules/test_cassandra_cql.py @@ -9,15 +9,13 @@ from __future__ import absolute_import import ssl # Import Salt Testing libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf # Import salt libs import salt.modules.cassandra_cql as cassandra_cql from salt.exceptions import CommandExecutionError -cassandra_cql.__salt__ = {} -cassandra_cql.__opts__ = {} - try: import cassandra # pylint: disable=unused-import,wrong-import-position HAS_CASSANDRA = True @@ -29,10 +27,13 @@ except ImportError: not HAS_CASSANDRA, 'Please install the cassandra datastax driver to run cassandra_cql module unit tests.' ) -class CassandraCQLReturnerTestCase(TestCase): +class CassandraCQLReturnerTestCase(TestCase, LoaderModuleMockMixin): ''' Test cassandra CQL module ''' + def setup_loader_modules(self): + return {cassandra_cql: {}} + def test_returns_opts_if_specified(self): ''' If ssl options are present then check that they are parsed and returned diff --git a/tests/unit/modules/test_deb_apache.py b/tests/unit/modules/test_deb_apache.py index e031c07fd6..14457d5c64 100644 --- a/tests/unit/modules/test_deb_apache.py +++ b/tests/unit/modules/test_deb_apache.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -17,17 +18,16 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.deb_apache as deb_apache -# Globals -deb_apache.__grains__ = {} -deb_apache.__salt__ = {} -deb_apache.__context__ = {} @skipIf(NO_MOCK, NO_MOCK_REASON) -class DebApacheTestCase(TestCase): +class DebApacheTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.deb_apache ''' + def setup_loader_modules(self): + return {deb_apache: {}} + # 'check_site_enabled' function tests: 3 @patch('os.path.islink', MagicMock(return_value=True)) diff --git a/tests/unit/modules/test_deb_postgres.py b/tests/unit/modules/test_deb_postgres.py index 3c613e5fea..995ac15eb8 100644 --- a/tests/unit/modules/test_deb_postgres.py +++ b/tests/unit/modules/test_deb_postgres.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function # Import Salt Testing libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, Mock, patch @@ -11,32 +12,31 @@ from tests.support.mock import NO_MOCK, NO_MOCK_REASON, Mock, patch import salt.ext.six as six import salt.modules.deb_postgres as deb_postgres -deb_postgres.__grains__ = None # in order to stub it w/patch below -deb_postgres.__salt__ = None # in order to stub it w/patch below - - LSCLUSTER = '''\ 8.4 main 5432 online postgres /srv/8.4/main \ /var/log/postgresql/postgresql-8.4-main.log 9.1 main 5433 online postgres /srv/9.1/main \ /var/log/postgresql/postgresql-9.1-main.log ''' -if NO_MOCK is False: - SALT_STUB = { - 'config.option': Mock(), - 'cmd.run_all': Mock(return_value={'stdout': LSCLUSTER}), - 'file.chown': Mock(), - 'file.remove': Mock(), - } -else: - SALT_STUB = {} @skipIf(NO_MOCK, NO_MOCK_REASON) -@patch.multiple(deb_postgres, - __salt__=SALT_STUB) @patch('salt.utils.which', Mock(return_value='/usr/bin/pg_createcluster')) -class PostgresClusterTestCase(TestCase): +class PostgresClusterTestCase(TestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + self.cmd_run_all_mock = Mock(return_value={'stdout': LSCLUSTER}) + self.addCleanup(delattr, self, 'cmd_run_all_mock') + return { + deb_postgres: { + '__salt__': { + 'config.option': Mock(), + 'cmd.run_all': self.cmd_run_all_mock, + 'file.chown': Mock(), + 'file.remove': Mock(), + } + } + } def test_cluster_create(self): deb_postgres.cluster_create( @@ -47,13 +47,11 @@ class PostgresClusterTestCase(TestCase): encoding='UTF-8', datadir='/opt/postgresql' ) - cmd = SALT_STUB['cmd.run_all'] - cmdstr = '/usr/bin/pg_createcluster ' \ '--port 5432 --locale fr_FR --encoding UTF-8 ' \ '--datadir /opt/postgresql ' \ '9.3 main' - self.assertEqual(cmdstr, cmd.call_args[0][0]) + self.assertEqual(cmdstr, self.cmd_run_all_mock.call_args[0][0]) # XXX version should be a string but from cmdline you get a float # def test_cluster_create_with_float(self): @@ -66,10 +64,22 @@ class PostgresClusterTestCase(TestCase): @skipIf(NO_MOCK, NO_MOCK_REASON) -@patch.multiple(deb_postgres, - __salt__=SALT_STUB) @patch('salt.utils.which', Mock(return_value='/usr/bin/pg_lsclusters')) -class PostgresLsClusterTestCase(TestCase): +class PostgresLsClusterTestCase(TestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + self.cmd_run_all_mock = Mock(return_value={'stdout': LSCLUSTER}) + self.addCleanup(delattr, self, 'cmd_run_all_mock') + return { + deb_postgres: { + '__salt__': { + 'config.option': Mock(), + 'cmd.run_all': self.cmd_run_all_mock, + 'file.chown': Mock(), + 'file.remove': Mock(), + } + } + } def test_parse_pg_lsclusters(self): stdout = LSCLUSTER @@ -91,9 +101,8 @@ class PostgresLsClusterTestCase(TestCase): def test_cluster_list(self): return_list = deb_postgres.cluster_list() - cmd = SALT_STUB['cmd.run_all'] self.assertEqual('/usr/bin/pg_lsclusters --no-header', - cmd.call_args[0][0]) + self.cmd_run_all_mock.call_args[0][0]) if six.PY2: # Python 3 returns iterable views (dict_keys in this case) on # dict.keys() calls instead of lists. We should only perform @@ -109,17 +118,27 @@ class PostgresLsClusterTestCase(TestCase): @skipIf(NO_MOCK, NO_MOCK_REASON) -@patch.multiple(deb_postgres, - __salt__=SALT_STUB) @patch('salt.utils.which', Mock(return_value='/usr/bin/pg_dropcluster')) -class PostgresDeleteClusterTestCase(TestCase): +class PostgresDeleteClusterTestCase(TestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + self.cmd_run_all_mock = Mock(return_value={'stdout': LSCLUSTER}) + self.addCleanup(delattr, self, 'cmd_run_all_mock') + return { + deb_postgres: { + '__salt__': { + 'config.option': Mock(), + 'cmd.run_all': self.cmd_run_all_mock, + 'file.chown': Mock(), + 'file.remove': Mock(), + } + } + } def test_cluster_delete(self): deb_postgres.cluster_remove('9.3', 'main') - cmd = SALT_STUB['cmd.run_all'] self.assertEqual('/usr/bin/pg_dropcluster 9.3 main', - cmd.call_args[0][0]) + self.cmd_run_all_mock.call_args[0][0]) deb_postgres.cluster_remove('9.3', 'main', stop=True) - cmd = SALT_STUB['cmd.run_all'] self.assertEqual('/usr/bin/pg_dropcluster --stop 9.3 main', - cmd.call_args[0][0]) + self.cmd_run_all_mock.call_args[0][0]) diff --git a/tests/unit/modules/test_debian_ip.py b/tests/unit/modules/test_debian_ip.py index a8a25175b9..bd16dc0f85 100644 --- a/tests/unit/modules/test_debian_ip.py +++ b/tests/unit/modules/test_debian_ip.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -21,16 +22,15 @@ import salt.modules.debian_ip as debian_ip # Import third party libs import jinja2.exceptions -# Globals -debian_ip.__grains__ = {} -debian_ip.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DebianIpTestCase(TestCase): +class DebianIpTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.debian_ip ''' + def setup_loader_modules(self): + return {debian_ip: {}} + # 'build_bond' function tests: 3 @patch('salt.modules.debian_ip._parse_settings_bond', diff --git a/tests/unit/modules/test_debian_service.py b/tests/unit/modules/test_debian_service.py index be29aa0363..92bef04d56 100644 --- a/tests/unit/modules/test_debian_service.py +++ b/tests/unit/modules/test_debian_service.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,18 +19,14 @@ from tests.support.mock import ( import salt.modules.debian_service as debian_service -# Globals -debian_service.__grains__ = {} -debian_service.__salt__ = {} -debian_service.__context__ = {} -debian_service.__opts__ = {} - - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DebianServicesTestCase(TestCase): +class DebianServicesTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.debian_service ''' + def setup_loader_modules(self): + return {debian_service: {}} + def test_get_enabled(self): ''' Test for Return a list of service that are enabled on boot diff --git a/tests/unit/modules/test_etcd_mod.py b/tests/unit/modules/test_etcd_mod.py index 4058769a3c..d0a7d7cabc 100644 --- a/tests/unit/modules/test_etcd_mod.py +++ b/tests/unit/modules/test_etcd_mod.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( create_autospec, @@ -18,27 +19,26 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.etcd_mod as etcd_mod -from salt.utils import etcd_util - -# Globals -etcd_mod.__opts__ = {} -etcd_mod.__utils__ = {} +import salt.utils.etcd_util as etcd_util @skipIf(NO_MOCK, NO_MOCK_REASON) -class EtcdModTestCase(TestCase): +class EtcdModTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.etcd_mod ''' + def setup_loader_modules(self): + return {etcd_mod: {}} + def setUp(self): self.instance = create_autospec(etcd_util.EtcdClient) self.EtcdClientMock = MagicMock() self.EtcdClientMock.return_value = self.instance def tearDown(self): - self.instance = None - self.EtcdClientMock = None + del self.instance + del self.EtcdClientMock # 'get_' function tests: 1 diff --git a/tests/unit/modules/test_gentoo_service.py b/tests/unit/modules/test_gentoo_service.py index 876b282d7b..1bec0e74c2 100644 --- a/tests/unit/modules/test_gentoo_service.py +++ b/tests/unit/modules/test_gentoo_service.py @@ -4,6 +4,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -17,23 +18,19 @@ from tests.support.mock import ( import salt.modules.gentoo_service as gentoo_service -# Globals -gentoo_service.__grains__ = {} -gentoo_service.__salt__ = {} -gentoo_service.__context__ = {} -gentoo_service.__opts__ = {} - - @skipIf(NO_MOCK, NO_MOCK_REASON) -class GentooServicesTestCase(TestCase): - """ +class GentooServicesTestCase(TestCase, LoaderModuleMockMixin): + ''' Test cases for salt.modules.gentoo_service - """ + ''' + + def setup_loader_modules(self): + return {gentoo_service: {}} def test_service_list_parser(self): - """ + ''' Test for parser of rc-status results - """ + ''' # no services is enabled mock = MagicMock(return_value='') with patch.dict(gentoo_service.__salt__, {'cmd.run': mock}): @@ -41,9 +38,9 @@ class GentooServicesTestCase(TestCase): mock.assert_called_once_with('rc-update -v show') def test_get_enabled_single_runlevel(self): - """ + ''' Test for Return a list of service that are enabled on boot - """ + ''' service_name = 'name' runlevels = ['default'] mock = MagicMock(return_value=self.__services({service_name: runlevels})) @@ -53,9 +50,9 @@ class GentooServicesTestCase(TestCase): self.assertEqual(enabled_services[service_name], runlevels) def test_get_enabled_filters_out_disabled_services(self): - """ + ''' Test for Return a list of service that are enabled on boot - """ + ''' service_name = 'name' runlevels = ['default'] disabled_service = 'disabled' @@ -69,9 +66,9 @@ class GentooServicesTestCase(TestCase): self.assertEqual(enabled_services[service_name], runlevels) def test_get_enabled_with_multiple_runlevels(self): - """ + ''' Test for Return a list of service that are enabled on boot at more than one runlevel - """ + ''' service_name = 'name' runlevels = ['non-default', 'default'] mock = MagicMock(return_value=self.__services({service_name: runlevels})) @@ -82,9 +79,9 @@ class GentooServicesTestCase(TestCase): self.assertEqual(enabled_services[service_name][1], runlevels[0]) def test_get_disabled(self): - """ + ''' Test for Return a list of service that are installed but disabled - """ + ''' disabled_service = 'disabled' enabled_service = 'enabled' service_list = self.__services({disabled_service: [], @@ -96,11 +93,11 @@ class GentooServicesTestCase(TestCase): self.assertTrue(disabled_service in disabled_services) def test_available(self): - """ + ''' Test for Returns ``True`` if the specified service is available, otherwise returns ``False``. - """ + ''' disabled_service = 'disabled' enabled_service = 'enabled' multilevel_service = 'multilevel' @@ -119,9 +116,9 @@ class GentooServicesTestCase(TestCase): self.assertFalse(gentoo_service.available(missing_service)) def test_missing(self): - """ + ''' Test for The inverse of service.available. - """ + ''' disabled_service = 'disabled' enabled_service = 'enabled' service_list = self.__services({disabled_service: [], @@ -133,9 +130,9 @@ class GentooServicesTestCase(TestCase): self.assertTrue(gentoo_service.missing('missing')) def test_getall(self): - """ + ''' Test for Return all available boot services - """ + ''' disabled_service = 'disabled' enabled_service = 'enabled' service_list = self.__services({disabled_service: [], @@ -148,54 +145,54 @@ class GentooServicesTestCase(TestCase): self.assertTrue(enabled_service in all_services) def test_start(self): - """ + ''' Test for Start the specified service - """ + ''' mock = MagicMock(return_value=True) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}): self.assertFalse(gentoo_service.start('name')) mock.assert_called_once_with('/etc/init.d/name start', python_shell=False) def test_stop(self): - """ + ''' Test for Stop the specified service - """ + ''' mock = MagicMock(return_value=True) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}): self.assertFalse(gentoo_service.stop('name')) mock.assert_called_once_with('/etc/init.d/name stop', python_shell=False) def test_restart(self): - """ + ''' Test for Restart the named service - """ + ''' mock = MagicMock(return_value=True) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}): self.assertFalse(gentoo_service.restart('name')) mock.assert_called_once_with('/etc/init.d/name restart', python_shell=False) def test_reload_(self): - """ + ''' Test for Reload the named service - """ + ''' mock = MagicMock(return_value=True) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}): self.assertFalse(gentoo_service.reload_('name')) mock.assert_called_once_with('/etc/init.d/name reload', python_shell=False) def test_zap(self): - """ + ''' Test for Reload the named service - """ + ''' mock = MagicMock(return_value=True) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}): self.assertFalse(gentoo_service.zap('name')) mock.assert_called_once_with('/etc/init.d/name zap', python_shell=False) def test_status(self): - """ + ''' Test for Return the status for a service - """ + ''' mock = MagicMock(return_value=True) with patch.dict(gentoo_service.__salt__, {'status.pid': mock}): self.assertTrue(gentoo_service.status('name', 1)) @@ -225,9 +222,9 @@ class GentooServicesTestCase(TestCase): mock.assert_called_once_with('/etc/init.d/name status', python_shell=False) def test_enable(self): - """ + ''' Test for Enable the named service to start at boot - """ + ''' rc_update_mock = MagicMock(return_value=0) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.enable('name')) @@ -320,9 +317,9 @@ class GentooServicesTestCase(TestCase): rc_update_mock.reset_mock() def test_disable(self): - """ + ''' Test for Disable the named service to start at boot - """ + ''' rc_update_mock = MagicMock(return_value=0) with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}): self.assertTrue(gentoo_service.disable('name')) @@ -406,9 +403,9 @@ class GentooServicesTestCase(TestCase): rc_update_mock.reset_mock() def test_enabled(self): - """ + ''' Test for Return True if the named service is enabled, false otherwise - """ + ''' mock = MagicMock(return_value={'name': ['default']}) with patch.object(gentoo_service, 'get_enabled', mock): # service is enabled at any level diff --git a/tests/unit/modules/test_git.py b/tests/unit/modules/test_git.py index b1b48e2ccf..c0b35c674b 100644 --- a/tests/unit/modules/test_git.py +++ b/tests/unit/modules/test_git.py @@ -11,6 +11,7 @@ import os import subprocess # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -23,9 +24,6 @@ from tests.support.mock import ( from salt.utils.versions import LooseVersion import salt.modules.git as git_mod # Don't potentially shadow GitPython -# Globals -git_mod.__salt__ = {} -git_mod.__context__ = {} log = logging.getLogger(__name__) WORKTREE_ROOT = '/tmp/salt-tests-tmpdir/main' @@ -74,10 +72,13 @@ def _git_version(): @skipIf(NO_MOCK, NO_MOCK_REASON) -class GitTestCase(TestCase): +class GitTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.git ''' + def setup_loader_modules(self): + return {git_mod: {}} + def test_list_worktrees(self): ''' This tests git.list_worktrees diff --git a/tests/unit/modules/test_grub_legacy.py b/tests/unit/modules/test_grub_legacy.py index ddc23a4f95..0ff5c2c7e7 100644 --- a/tests/unit/modules/test_grub_legacy.py +++ b/tests/unit/modules/test_grub_legacy.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( mock_open, @@ -20,15 +21,15 @@ from tests.support.mock import ( import salt.modules.grub_legacy as grub_legacy from salt.exceptions import CommandExecutionError -# Globals -grub_legacy.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class GrublegacyTestCase(TestCase): +class GrublegacyTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.grub_legacy ''' + def setup_loader_modules(self): + return {grub_legacy: {}} + def test_version(self): ''' Test for Return server version from grub --version diff --git a/tests/unit/modules/test_libcloud_dns.py b/tests/unit/modules/test_libcloud_dns.py index baae7405f0..b9b51bdd61 100644 --- a/tests/unit/modules/test_libcloud_dns.py +++ b/tests/unit/modules/test_libcloud_dns.py @@ -7,8 +7,9 @@ from __future__ import absolute_import # Import Salt Testing Libs -from tests.support.unit import skipIf from tests.unit import ModuleTestCase, hasDependency +from tests.support.mixins import LoaderModuleMockMixin +from tests.support.unit import skipIf from tests.support.mock import ( patch, MagicMock, @@ -18,8 +19,6 @@ from tests.support.mock import ( import salt.modules.libcloud_dns as libcloud_dns SERVICE_NAME = 'libcloud_dns' -libcloud_dns.__salt__ = {} -libcloud_dns.__utils__ = {} class MockDNSDriver(object): @@ -34,7 +33,11 @@ def get_mock_driver(): @skipIf(NO_MOCK, NO_MOCK_REASON) @patch('salt.modules.libcloud_dns._get_driver', MagicMock(return_value=MockDNSDriver())) -class LibcloudDnsModuleTestCase(ModuleTestCase): +class LibcloudDnsModuleTestCase(ModuleTestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + return {libcloud_dns: {}} + def setUp(self): hasDependency('libcloud', fake_module=False) diff --git a/tests/unit/modules/test_linux_lvm.py b/tests/unit/modules/test_linux_lvm.py index 3bc5944c26..0435db7ed5 100644 --- a/tests/unit/modules/test_linux_lvm.py +++ b/tests/unit/modules/test_linux_lvm.py @@ -8,6 +8,7 @@ from __future__ import absolute_import import os.path # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -20,15 +21,14 @@ from tests.support.mock import ( import salt.modules.linux_lvm as linux_lvm from salt.exceptions import CommandExecutionError -# Globals -linux_lvm.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LinuxLVMTestCase(TestCase): +class LinuxLVMTestCase(TestCase, LoaderModuleMockMixin): ''' TestCase for the salt.modules.linux_lvm module ''' + def setup_loader_modules(self): + return {linux_lvm: {}} def test_version(self): ''' diff --git a/tests/unit/modules/test_mac_brew.py b/tests/unit/modules/test_mac_brew.py index 505f83088c..3f678bb3f2 100644 --- a/tests/unit/modules/test_mac_brew.py +++ b/tests/unit/modules/test_mac_brew.py @@ -11,24 +11,22 @@ import salt.modules.mac_brew as mac_brew from salt.exceptions import CommandExecutionError # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON -# Global Variables -mac_brew.__context__ = {} -mac_brew.__salt__ = {} -mac_brew.__opts__ = {'user': MagicMock(return_value='bar')} - TAPS_STRING = 'homebrew/dupes\nhomebrew/science\nhomebrew/x11' TAPS_LIST = ['homebrew/dupes', 'homebrew/science', 'homebrew/x11'] HOMEBREW_BIN = '/usr/local/bin/brew' @skipIf(NO_MOCK, NO_MOCK_REASON) -class BrewTestCase(TestCase): +class BrewTestCase(TestCase, LoaderModuleMockMixin): ''' TestCase for salt.modules.mac_brew module ''' + def setup_loader_modules(self): + return {mac_brew: {'__opts__': {'user': MagicMock(return_value='bar')}}} # '_list_taps' function tests: 1 diff --git a/tests/unit/modules/test_mac_desktop.py b/tests/unit/modules/test_mac_desktop.py index 2fb452a1cd..62fba43d1e 100644 --- a/tests/unit/modules/test_mac_desktop.py +++ b/tests/unit/modules/test_mac_desktop.py @@ -7,6 +7,7 @@ Unit Tests for the mac_desktop execution module. from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,15 +20,15 @@ from tests.support.mock import ( import salt.modules.mac_desktop as mac_desktop from salt.exceptions import CommandExecutionError -# Globals -mac_desktop.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class MacDesktopTestCase(TestCase): +class MacDesktopTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.mac_desktop ''' + def setup_loader_modules(self): + return {mac_desktop: {}} + # 'get_output_volume' function tests: 2 def test_get_output_volume(self): diff --git a/tests/unit/modules/test_mac_pkgutil.py b/tests/unit/modules/test_mac_pkgutil.py index 7a38e03385..7c1a218f8c 100644 --- a/tests/unit/modules/test_mac_pkgutil.py +++ b/tests/unit/modules/test_mac_pkgutil.py @@ -7,25 +7,26 @@ from __future__ import absolute_import import salt.modules.mac_pkgutil as mac_pkgutil # Import Salt Testing libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch -mac_pkgutil.__salt__ = {} - - @skipIf(NO_MOCK, NO_MOCK_REASON) -class MacPkgutilTestCase(TestCase): +class MacPkgutilTestCase(TestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + return {mac_pkgutil: {}} def test_install(self): # Given - source = "/foo/bar/fubar.pkg" - package_id = "com.foo.fubar.pkg" + source = '/foo/bar/fubar.pkg' + package_id = 'com.foo.fubar.pkg' # When - with patch("salt.modules.mac_pkgutil.is_installed", + with patch('salt.modules.mac_pkgutil.is_installed', return_value=False): - with patch("salt.modules.mac_pkgutil._install_from_path", + with patch('salt.modules.mac_pkgutil._install_from_path', return_value=True) as _install_from_path: mac_pkgutil.install(source, package_id) @@ -34,13 +35,13 @@ class MacPkgutilTestCase(TestCase): def test_install_already_there(self): # Given - source = "/foo/bar/fubar.pkg" - package_id = "com.foo.fubar.pkg" + source = '/foo/bar/fubar.pkg' + package_id = 'com.foo.fubar.pkg' # When - with patch("salt.modules.mac_pkgutil.is_installed", + with patch('salt.modules.mac_pkgutil.is_installed', return_value=True): - with patch("salt.modules.mac_pkgutil._install_from_path", + with patch('salt.modules.mac_pkgutil._install_from_path', return_value=True) as _install_from_path: mac_pkgutil.install(source, package_id) diff --git a/tests/unit/modules/test_mac_sysctl.py b/tests/unit/modules/test_mac_sysctl.py index d5f4f8e83a..453eb600d9 100644 --- a/tests/unit/modules/test_mac_sysctl.py +++ b/tests/unit/modules/test_mac_sysctl.py @@ -11,6 +11,7 @@ import salt.modules.mac_sysctl as mac_sysctl from salt.exceptions import CommandExecutionError # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( MagicMock, @@ -21,15 +22,14 @@ from tests.support.mock import ( NO_MOCK_REASON ) -# Globals -mac_sysctl.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DarwinSysctlTestCase(TestCase): +class DarwinSysctlTestCase(TestCase, LoaderModuleMockMixin): ''' TestCase for salt.modules.mac_sysctl module ''' + def setup_loader_modules(self): + return {mac_sysctl: {}} def test_get(self): ''' diff --git a/tests/unit/modules/test_openstack_config.py b/tests/unit/modules/test_openstack_config.py index 043cd9e3b7..3cc13a06b0 100644 --- a/tests/unit/modules/test_openstack_config.py +++ b/tests/unit/modules/test_openstack_config.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,15 +20,15 @@ from tests.support.mock import ( import salt.modules.openstack_config as openstack_config from salt.exceptions import CommandExecutionError -# Globals -openstack_config.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class OpenstackConfigTestCase(TestCase): +class OpenstackConfigTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.openstack_config ''' + def setup_loader_modules(self): + return {openstack_config: {}} + # 'set_' function tests: 1 @patch('salt.utils.which', MagicMock(return_value=True)) diff --git a/tests/unit/modules/test_pkg_resource.py b/tests/unit/modules/test_pkg_resource.py index b9850020b3..2e51fab6f5 100644 --- a/tests/unit/modules/test_pkg_resource.py +++ b/tests/unit/modules/test_pkg_resource.py @@ -8,6 +8,7 @@ from __future__ import absolute_import import yaml # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -21,16 +22,15 @@ import salt.utils import salt.modules.pkg_resource as pkg_resource import salt.ext.six as six -# Globals -pkg_resource.__grains__ = {} -pkg_resource.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PkgresTestCase(TestCase): +class PkgresTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.pkg_resource ''' + def setup_loader_modules(self): + return {pkg_resource: {}} + def test_pack_sources(self): ''' Test to accepts list of dicts (or a string representing a diff --git a/tests/unit/modules/test_pw_group.py b/tests/unit/modules/test_pw_group.py index d90f4c8ff7..3d21bbd43c 100644 --- a/tests/unit/modules/test_pw_group.py +++ b/tests/unit/modules/test_pw_group.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,18 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.pw_group as pw_group -# Globals -pw_group.__grains__ = {} -pw_group.__salt__ = {} -pw_group.__context__ = {} -pw_group.grinfo = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PwGroupTestCase(TestCase): +class PwGroupTestCase(TestCase, LoaderModuleMockMixin): ''' Test for salt.module.pw_group ''' + def setup_loader_modules(self): + return {pw_group: {'grinfo': {}}} + def test_add(self): ''' Tests to add the specified group diff --git a/tests/unit/modules/test_pw_user.py b/tests/unit/modules/test_pw_user.py index 881e6a05a7..02ed888166 100644 --- a/tests/unit/modules/test_pw_user.py +++ b/tests/unit/modules/test_pw_user.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -25,18 +26,15 @@ except ImportError: HAS_PWD = False -# Globals -pw_user.__grains__ = {} -pw_user.__salt__ = {} -pw_user.__context__ = {} - - @skipIf(not HAS_PWD, 'These tests can only run on systems with the python pwd module') @skipIf(NO_MOCK, NO_MOCK_REASON) -class PwUserTestCase(TestCase): +class PwUserTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.pw_user ''' + def setup_loader_modules(self): + return {pw_user: {}} + def test_add(self): ''' Test for adding a user diff --git a/tests/unit/modules/test_qemu_img.py b/tests/unit/modules/test_qemu_img.py index 5a45174728..3c7e08dddf 100644 --- a/tests/unit/modules/test_qemu_img.py +++ b/tests/unit/modules/test_qemu_img.py @@ -5,8 +5,10 @@ # Import Python Libs from __future__ import absolute_import +import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -17,17 +19,16 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.qemu_img as qemu_img -import os - -# Globals -qemu_img.__salt__ = {} @skipIf(NO_MOCK, NO_MOCK_REASON) -class QemuimgTestCase(TestCase): +class QemuimgTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.qemu_img ''' + def setup_loader_modules(self): + return {qemu_img: {}} + def test_make_image(self): ''' Test for create a blank virtual machine image file diff --git a/tests/unit/modules/test_qemu_nbd.py b/tests/unit/modules/test_qemu_nbd.py index d21da8aa20..ec6ec84587 100644 --- a/tests/unit/modules/test_qemu_nbd.py +++ b/tests/unit/modules/test_qemu_nbd.py @@ -10,6 +10,7 @@ import glob import tempfile # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -21,14 +22,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.qemu_nbd as qemu_nbd -qemu_nbd.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class QemuNbdTestCase(TestCase): +class QemuNbdTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.qemu_nbd ''' + def setup_loader_modules(self): + return {qemu_nbd: {}} + # 'connect' function tests: 1 def test_connect(self): diff --git a/tests/unit/modules/test_raet_publish.py b/tests/unit/modules/test_raet_publish.py index f2a5670f14..786c719f14 100644 --- a/tests/unit/modules/test_raet_publish.py +++ b/tests/unit/modules/test_raet_publish.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -19,15 +20,15 @@ import salt.modules.raet_publish as raet_publish import salt.transport from salt.exceptions import SaltReqTimeoutError -# Globals -raet_publish.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RaetPublishTestCase(TestCase): +class RaetPublishTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.raet_publish ''' + def setup_loader_modules(self): + return {raet_publish: {}} + def test_publish(self): ''' Test for publish a command from the minion out to other minions. diff --git a/tests/unit/modules/test_random_org.py b/tests/unit/modules/test_random_org.py index 890b4053ff..34002c8594 100644 --- a/tests/unit/modules/test_random_org.py +++ b/tests/unit/modules/test_random_org.py @@ -7,14 +7,13 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf # Import Salt Libs import salt.utils.http import salt.modules.random_org as random_org -random_org.__opts__ = {} - def check_status(): ''' @@ -28,10 +27,13 @@ def check_status(): @skipIf(not check_status(), 'random.org is not available') -class RandomOrgTestCase(TestCase): +class RandomOrgTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.random_org ''' + def setup_loader_modules(self): + return {random_org: {}} + # 'getUsage' function tests: 1 def test_getusage(self): diff --git a/tests/unit/modules/test_rh_ip.py b/tests/unit/modules/test_rh_ip.py index 9d60d912b6..08b3367a73 100644 --- a/tests/unit/modules/test_rh_ip.py +++ b/tests/unit/modules/test_rh_ip.py @@ -4,8 +4,10 @@ ''' # Import Python libs from __future__ import absolute_import +import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -15,19 +17,19 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.rh_ip as rh_ip -import jinja2.exceptions -import os -# Globals -rh_ip.__grains__ = {} -rh_ip.__salt__ = {} +# Import 3rd-party libs +import jinja2.exceptions @skipIf(NO_MOCK, NO_MOCK_REASON) -class RhipTestCase(TestCase): +class RhipTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.rh_ip ''' + def setup_loader_modules(self): + return {rh_ip: {}} + def test_build_bond(self): ''' Test to create a bond script in /etc/modprobe.d with the passed diff --git a/tests/unit/modules/test_rh_service.py b/tests/unit/modules/test_rh_service.py index dab7bc4d67..0b51f734af 100644 --- a/tests/unit/modules/test_rh_service.py +++ b/tests/unit/modules/test_rh_service.py @@ -8,6 +8,7 @@ from __future__ import absolute_import import textwrap # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,54 +20,25 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.rh_service as rh_service -# Globals -rh_service.__salt__ = {} - RET = ['hostname', 'mountall', 'network-interface', 'network-manager', 'salt-api', 'salt-master', 'salt-minion'] -HAS_UPSTART = None - - -def _m_disable(): - ''' - Mock _upstart_disable method. - ''' - if HAS_UPSTART: - return MagicMock(return_value=True) - else: - return MagicMock(return_value=False) - - -def _m_enable(): - ''' - Mock _upstart_enable method. - ''' - if HAS_UPSTART: - return MagicMock(return_value=True) - else: - return MagicMock(return_value=False) - - -def _m_isenabled(): - ''' - Mock _upstart_is_enabled method. - ''' - if HAS_UPSTART: - return MagicMock(return_value=True) - else: - return MagicMock(return_value=False) - -rh_service._upstart_disable = _m_disable() -rh_service._upstart_enable = _m_enable() -rh_service._upstart_is_enabled = _m_isenabled() - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RhServiceTestCase(TestCase): +class RhServiceTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.rh_service ''' + + def setup_loader_modules(self): + return { + rh_service: { + '_upstart_disable': None, + '_upstart_enable': None, + '_upstart_is_enabled': None + } + } + @staticmethod def _m_lst(): ''' @@ -125,9 +97,8 @@ class RhServiceTestCase(TestCase): param to restrict results to services of that type. ''' with patch.object(rh_service, '_upstart_services', self._m_ret()): - global HAS_UPSTART - HAS_UPSTART = True - self.assertListEqual(rh_service.get_enabled('upstart'), []) + with patch.object(rh_service, '_upstart_is_enabled', MagicMock(return_value=False)): + self.assertListEqual(rh_service.get_enabled('upstart'), []) mock_run = MagicMock(return_value='salt stack') with patch.dict(rh_service.__salt__, {'cmd.run': mock_run}): @@ -137,10 +108,9 @@ class RhServiceTestCase(TestCase): self.assertListEqual(rh_service.get_enabled('sysvinit'), RET) - with patch.object(rh_service, '_upstart_services', - self._m_lst()): - HAS_UPSTART = True - self.assertListEqual(rh_service.get_enabled(), RET) + with patch.object(rh_service, '_upstart_services', self._m_lst()): + with patch.object(rh_service, '_upstart_is_enabled', MagicMock(return_value=True)): + self.assertListEqual(rh_service.get_enabled(), RET) # 'get_disabled' function tests: 1 @@ -150,9 +120,8 @@ class RhServiceTestCase(TestCase): param to restrict results to services of that type. ''' with patch.object(rh_service, '_upstart_services', self._m_ret()): - global HAS_UPSTART - HAS_UPSTART = False - self.assertListEqual(rh_service.get_disabled('upstart'), RET) + with patch.object(rh_service, '_upstart_is_enabled', MagicMock(return_value=False)): + self.assertListEqual(rh_service.get_disabled('upstart'), RET) mock_run = MagicMock(return_value='salt stack') with patch.dict(rh_service.__salt__, {'cmd.run': mock_run}): @@ -164,8 +133,8 @@ class RhServiceTestCase(TestCase): with patch.object(rh_service, '_upstart_services', self._m_lst()): - HAS_UPSTART = False - self.assertListEqual(rh_service.get_disabled(), RET) + with patch.object(rh_service, '_upstart_is_enabled', MagicMock(return_value=False)): + self.assertListEqual(rh_service.get_disabled(), RET) # 'get_all' function tests: 1 @@ -292,11 +261,13 @@ class RhServiceTestCase(TestCase): ''' Test if it enable the named service to start at boot. ''' - mock_bool = MagicMock(side_effect=[True, False]) + mock_bool = MagicMock(side_effect=[True, True, False]) with patch.object(rh_service, '_service_is_upstart', mock_bool): - global HAS_UPSTART - HAS_UPSTART = True - self.assertFalse(rh_service.enable('salt-api')) + with patch.object(rh_service, '_upstart_is_enabled', MagicMock(return_value=True)): + with patch.object(rh_service, '_upstart_enable', MagicMock(return_value=False)): + self.assertFalse(rh_service.enable('salt-api')) + with patch.object(rh_service, '_upstart_enable', MagicMock(return_value=True)): + self.assertTrue(rh_service.enable('salt-api')) with patch.object(rh_service, '_sysv_enable', self._m_bool()): self.assertTrue(rh_service.enable('salt-api')) @@ -307,11 +278,13 @@ class RhServiceTestCase(TestCase): ''' Test if it disable the named service to start at boot. ''' - mock_bool = MagicMock(side_effect=[True, False]) + mock_bool = MagicMock(side_effect=[True, True, False]) with patch.object(rh_service, '_service_is_upstart', mock_bool): - global HAS_UPSTART - HAS_UPSTART = True - self.assertFalse(rh_service.disable('salt-api')) + with patch.object(rh_service, '_upstart_is_enabled', MagicMock(return_value=True)): + with patch.object(rh_service, '_upstart_disable', MagicMock(return_value=False)): + self.assertFalse(rh_service.disable('salt-api')) + with patch.object(rh_service, '_upstart_disable', MagicMock(return_value=True)): + self.assertTrue(rh_service.disable('salt-api')) with patch.object(rh_service, '_sysv_disable', self._m_bool()): self.assertTrue(rh_service.disable('salt-api')) @@ -325,9 +298,8 @@ class RhServiceTestCase(TestCase): ''' mock_bool = MagicMock(side_effect=[True, False]) with patch.object(rh_service, '_service_is_upstart', mock_bool): - global HAS_UPSTART - HAS_UPSTART = True - self.assertFalse(rh_service.enabled('salt-api')) + with patch.object(rh_service, '_upstart_is_enabled', MagicMock(return_value=False)): + self.assertFalse(rh_service.enabled('salt-api')) with patch.object(rh_service, '_sysv_is_enabled', self._m_bool()): self.assertTrue(rh_service.enabled('salt-api')) @@ -341,9 +313,8 @@ class RhServiceTestCase(TestCase): ''' mock_bool = MagicMock(side_effect=[True, False]) with patch.object(rh_service, '_service_is_upstart', mock_bool): - global HAS_UPSTART - HAS_UPSTART = False - self.assertTrue(rh_service.disabled('salt-api')) + with patch.object(rh_service, '_upstart_is_enabled', MagicMock(return_value=False)): + self.assertTrue(rh_service.disabled('salt-api')) with patch.object(rh_service, '_sysv_is_enabled', self._m_bool(False)): diff --git a/tests/unit/modules/test_serverdensity_device.py b/tests/unit/modules/test_serverdensity_device.py index 04e54125ac..4061f80db6 100644 --- a/tests/unit/modules/test_serverdensity_device.py +++ b/tests/unit/modules/test_serverdensity_device.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,10 +20,6 @@ from tests.support.mock import ( import salt.modules.serverdensity_device as serverdensity_device from salt.exceptions import CommandExecutionError -serverdensity_device.__salt__ = {} -serverdensity_device.__pillar__ = {} -serverdensity_device.__opts__ = {} - class MockJson(Exception): ''' @@ -100,15 +97,19 @@ class MockRequests(object): return self.return_request(url, data, **kwargs) -serverdensity_device.requests = MockRequests() -serverdensity_device.json = MockJson() - - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ServerdensityDeviceTestCase(TestCase): +class ServerdensityDeviceTestCase(TestCase, LoaderModuleMockMixin): ''' TestCase for salt.modules.serverdensity_device ''' + def setup_loader_modules(self): + return { + serverdensity_device: { + 'json': MockJson(), + 'requests': MockRequests() + } + } + # 'get_sd_auth' function tests: 1 def test_get_sd_auth(self): diff --git a/tests/unit/modules/test_shadow.py b/tests/unit/modules/test_shadow.py index c11c9c728e..4a764a5345 100644 --- a/tests/unit/modules/test_shadow.py +++ b/tests/unit/modules/test_shadow.py @@ -8,6 +8,7 @@ from __future__ import absolute_import # Import Salt Testing libs from salt.utils import is_linux +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf # Import salt libs @@ -41,7 +42,10 @@ _HASHES = dict( @skipIf(not is_linux(), 'minion is not Linux') -class LinuxShadowTest(TestCase): +class LinuxShadowTest(TestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + return {shadow: {}} def test_gen_password(self): ''' diff --git a/tests/unit/modules/test_syslog_ng.py b/tests/unit/modules/test_syslog_ng.py index 0ba50258dd..0d75df579a 100644 --- a/tests/unit/modules/test_syslog_ng.py +++ b/tests/unit/modules/test_syslog_ng.py @@ -8,6 +8,7 @@ from __future__ import absolute_import from textwrap import dedent # Import Salt Testing libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch @@ -15,9 +16,6 @@ from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch import salt import salt.modules.syslog_ng as syslog_ng -syslog_ng.__salt__ = {} -syslog_ng.__opts__ = {} - _VERSION = "3.6.0alpha0" _MODULES = ("syslogformat,json-plugin,basicfuncs,afstomp,afsocket,cryptofuncs," "afmongodb,dbparser,system-source,affile,pseudofile,afamqp," @@ -58,7 +56,10 @@ _SYSLOG_NG_CTL_NOT_INSTALLED_RETURN_VALUE = { @skipIf(NO_MOCK, NO_MOCK_REASON) -class SyslogNGTestCase(TestCase): +class SyslogNGTestCase(TestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + return {syslog_ng: {}} def test_statement_without_options(self): s = syslog_ng.Statement("source", "s_local", options=[]) diff --git a/tests/unit/modules/test_virtualenv.py b/tests/unit/modules/test_virtualenv.py index 5a7093c41b..83baae1e81 100644 --- a/tests/unit/modules/test_virtualenv.py +++ b/tests/unit/modules/test_virtualenv.py @@ -12,6 +12,7 @@ from __future__ import absolute_import import sys # Import Salt Testing libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.helpers import TestsLoggingHandler, ForceImportErrorOn from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch @@ -20,16 +21,18 @@ from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch import salt.modules.virtualenv_mod as virtualenv_mod from salt.exceptions import CommandExecutionError -virtualenv_mod.__salt__ = {} -virtualenv_mod.__opts__['venv_bin'] = 'virtualenv' -base_virtualenv_mock = MagicMock() -base_virtualenv_mock.__version__ = '1.9.1' - @skipIf(NO_MOCK, NO_MOCK_REASON) @patch('salt.utils.which', lambda bin_name: bin_name) -@patch.dict('sys.modules', {'virtualenv': base_virtualenv_mock}) -class VirtualenvTestCase(TestCase): +class VirtualenvTestCase(TestCase, LoaderModuleMockMixin): + + def setup_loader_modules(self): + base_virtualenv_mock = MagicMock() + base_virtualenv_mock.__version__ = '1.9.1' + sys_modules_patcher = patch.dict('sys.modules', {'virtualenv': base_virtualenv_mock}) + sys_modules_patcher.start() + self.addCleanup(sys_modules_patcher.stop) + return {virtualenv_mod: {'__opts__': {'venv_bin': 'virtualenv'}}} def test_issue_6029_deprecated_distribute(self): mock = MagicMock(return_value={'retcode': 0, 'stdout': ''}) diff --git a/tests/unit/modules/test_win_dns_client.py b/tests/unit/modules/test_win_dns_client.py index c48ba8bee6..4cd0ae131d 100644 --- a/tests/unit/modules/test_win_dns_client.py +++ b/tests/unit/modules/test_win_dns_client.py @@ -5,10 +5,10 @@ # Import Python Libs from __future__ import absolute_import -import sys import types # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,26 +18,9 @@ from tests.support.mock import ( NO_MOCK_REASON ) -# wmi and pythoncom modules are platform specific... -wmi = types.ModuleType('wmi') -sys.modules['wmi'] = wmi - -pythoncom = types.ModuleType('pythoncom') -sys.modules['pythoncom'] = pythoncom - -if NO_MOCK is False: - WMI = Mock() - wmi.WMI = Mock(return_value=WMI) - pythoncom.CoInitialize = Mock() - pythoncom.CoUninitialize = Mock() - # Import Salt Libs import salt.modules.win_dns_client as win_dns_client -# Globals -win_dns_client.__salt__ = {} -win_dns_client.__context__ = {} - class Mockwmi(object): ''' @@ -76,10 +59,25 @@ class Mockwinapi(object): @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinDnsClientTestCase(TestCase): +class WinDnsClientTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.win_dns_client ''' + + def setup_loader_modules(self): + # wmi and pythoncom modules are platform specific... + wmi = types.ModuleType('wmi') + pythoncom = types.ModuleType('pythoncom') + sys_modules_patcher = patch.dict('sys.modules', {'wmi': wmi, 'pythoncom': pythoncom}) + sys_modules_patcher.start() + self.addCleanup(sys_modules_patcher.stop) + self.WMI = Mock() + self.addCleanup(delattr, self, 'WMI') + wmi.WMI = Mock(return_value=self.WMI) + pythoncom.CoInitialize = Mock() + pythoncom.CoUninitialize = Mock() + return {win_dns_client: {'wmi': wmi}} + # 'get_dns_servers' function tests: 1 @patch('salt.utils', Mockwinapi) @@ -89,9 +87,9 @@ class WinDnsClientTestCase(TestCase): of the specified interface. ''' with patch('salt.utils.winapi.Com', MagicMock()): - with patch.object(WMI, 'Win32_NetworkAdapter', + with patch.object(self.WMI, 'Win32_NetworkAdapter', return_value=[Mockwmi()]): - with patch.object(WMI, 'Win32_NetworkAdapterConfiguration', + with patch.object(self.WMI, 'Win32_NetworkAdapterConfiguration', return_value=[Mockwmi()]): self.assertListEqual(win_dns_client.get_dns_servers ('Local Area Connection'), @@ -116,9 +114,9 @@ class WinDnsClientTestCase(TestCase): Test if it add the DNS server to the network interface. ''' with patch('salt.utils.winapi.Com', MagicMock()): - with patch.object(WMI, 'Win32_NetworkAdapter', + with patch.object(self.WMI, 'Win32_NetworkAdapter', return_value=[Mockwmi()]): - with patch.object(WMI, 'Win32_NetworkAdapterConfiguration', + with patch.object(self.WMI, 'Win32_NetworkAdapterConfiguration', return_value=[Mockwmi()]): self.assertFalse(win_dns_client.add_dns('10.1.1.10', 'Ethernet')) @@ -151,8 +149,8 @@ class WinDnsClientTestCase(TestCase): Test if it get the type of DNS configuration (dhcp / static) ''' with patch('salt.utils.winapi.Com', MagicMock()): - with patch.object(WMI, 'Win32_NetworkAdapter', + with patch.object(self.WMI, 'Win32_NetworkAdapter', return_value=[Mockwmi()]): - with patch.object(WMI, 'Win32_NetworkAdapterConfiguration', + with patch.object(self.WMI, 'Win32_NetworkAdapterConfiguration', return_value=[Mockwmi()]): self.assertTrue(win_dns_client.get_dns_config()) diff --git a/tests/unit/modules/test_win_ip.py b/tests/unit/modules/test_win_ip.py index e860b5c89e..eccbd41379 100644 --- a/tests/unit/modules/test_win_ip.py +++ b/tests/unit/modules/test_win_ip.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,9 +20,6 @@ from tests.support.mock import ( import salt.modules.win_ip as win_ip from salt.exceptions import CommandExecutionError, SaltInvocationError -# Globals -win_ip.__salt__ = {} - ETHERNET_CONFIG = ('Configuration for interface "Ethernet"\n' 'DHCP enabled: Yes\n' 'IP Address: 1.2.3.74\n' @@ -40,10 +38,13 @@ ETHERNET_ENABLE = ('Ethernet\n' @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinShadowTestCase(TestCase): +class WinShadowTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.win_ip ''' + def setup_loader_modules(self): + return {win_ip: {}} + # 'raw_interface_configs' function tests: 1 def test_raw_interface_configs(self): diff --git a/tests/unit/modules/test_win_network.py b/tests/unit/modules/test_win_network.py index acf4bd8fb7..b0a15a940a 100644 --- a/tests/unit/modules/test_win_network.py +++ b/tests/unit/modules/test_win_network.py @@ -5,11 +5,10 @@ # Import Python Libs from __future__ import absolute_import -import salt.utils -import sys import types # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,19 +18,10 @@ from tests.support.mock import ( NO_MOCK_REASON ) -# wmi modules are platform specific... -wmi = types.ModuleType('wmi') -sys.modules['wmi'] = wmi - -if NO_MOCK is False: - WMI = Mock() - wmi.WMI = Mock(return_value=WMI) - # Import Salt Libs +import salt.utils import salt.modules.win_network as win_network -win_network.__salt__ = {} - class Mockwmi(object): ''' @@ -66,10 +56,18 @@ class Mockwinapi(object): @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinNetworkTestCase(TestCase): +class WinNetworkTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.win_network ''' + def setup_loader_modules(self): + # wmi modules are platform specific... + wmi = types.ModuleType('wmi') + self.WMI = Mock() + self.addCleanup(delattr, self, 'WMI') + wmi.WMI = Mock(return_value=self.WMI) + return {win_network: {'wmi': wmi}} + # 'ping' function tests: 1 def test_ping(self): @@ -160,9 +158,9 @@ class WinNetworkTestCase(TestCase): ''' Test if it return a list of all the interfaces names ''' - WMI.Win32_NetworkAdapter = MagicMock(return_value=Mockwmi) + self.WMI.Win32_NetworkAdapter = MagicMock(return_value=Mockwmi) with patch('salt.utils.winapi.Com', MagicMock()): - with patch.object(WMI, 'Win32_NetworkAdapter', + with patch.object(self.WMI, 'Win32_NetworkAdapter', return_value=[Mockwmi()]): self.assertListEqual(win_network.interfaces_names(), ['Ethernet']) diff --git a/tests/unit/modules/test_win_path.py b/tests/unit/modules/test_win_path.py index 45d6953093..c77338e958 100644 --- a/tests/unit/modules/test_win_path.py +++ b/tests/unit/modules/test_win_path.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,9 +19,6 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.win_path as win_path -# Globals -win_path.__salt__ = {} - class MockWin32Gui(object): ''' @@ -47,15 +45,15 @@ class MockWin32Con(object): def __init__(self): pass -win_path.win32gui = MockWin32Gui -win_path.win32con = MockWin32Con - @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinPathTestCase(TestCase): +class WinPathTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.win_path ''' + def setup_loader_modules(self): + return {win_path: {'win32gui': MockWin32Gui, 'win32con': MockWin32Con}} + def test_rehash(self): ''' Test to rehash the Environment variables diff --git a/tests/unit/modules/test_win_pki.py b/tests/unit/modules/test_win_pki.py index b9ef19bff5..a7818ddd3c 100644 --- a/tests/unit/modules/test_win_pki.py +++ b/tests/unit/modules/test_win_pki.py @@ -13,6 +13,7 @@ from __future__ import absolute_import import salt.modules.win_pki as win_pki # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -21,9 +22,6 @@ from tests.support.mock import ( NO_MOCK_REASON, ) -# Globals -win_pki.__salt__ = {} - CERT_PATH = r'C:\certs\testdomain.local.cer' THUMBPRINT = '9988776655443322111000AAABBBCCCDDDEEEFFF' @@ -90,10 +88,12 @@ JSON_STORES = [{ @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinPkiTestCase(TestCase): +class WinPkiTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.win_pki ''' + def setup_loader_modules(self): + return {win_pki: {}} @patch('salt.modules.win_pki._cmd_run', MagicMock(return_value=JSON_STORES)) diff --git a/tests/unit/modules/test_win_service.py b/tests/unit/modules/test_win_service.py index 2ed95835f0..54c5c465bd 100644 --- a/tests/unit/modules/test_win_service.py +++ b/tests/unit/modules/test_win_service.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -25,14 +26,15 @@ try: except ImportError: WINAPI = False -win_service.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinServiceTestCase(TestCase): +class WinServiceTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.win_service ''' + def setup_loader_modules(self): + return {win_service: {}} + def test_get_enabled(self): ''' Test to return the enabled services diff --git a/tests/unit/modules/test_win_shadow.py b/tests/unit/modules/test_win_shadow.py index a116d9376c..3917aba8b5 100644 --- a/tests/unit/modules/test_win_shadow.py +++ b/tests/unit/modules/test_win_shadow.py @@ -7,7 +7,8 @@ from __future__ import absolute_import # Import Salt Testing Libs -from tests.support.unit import TestCase, skipIf +from tests.support.mixins import LoaderModuleMockMixin +from tests.support.unit import TestCase from tests.support.mock import ( MagicMock, patch @@ -15,31 +16,40 @@ from tests.support.mock import ( # Import Salt Libs import salt.modules.win_shadow as win_shadow -import salt.utils - -# Globals -win_shadow.__salt__ = {} -@skipIf(not salt.utils.is_windows(), 'This test case runs only on Windows systems') -class WinShadowTestCase(TestCase): +class WinShadowTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.win_shadow ''' + def setup_loader_modules(self): + return { + win_shadow: { + '__salt__': { +# 'user.info': MagicMock(return_value=True), + 'user.update': MagicMock(return_value=True) + } + } + } + # 'info' function tests: 1 def test_info(self): ''' Test if it return information for the specified user ''' - self.assertDictEqual(win_shadow.info('SALT'), {'name': 'SALT', - 'passwd': '', - 'lstchg': '', - 'min': '', - 'max': '', - 'warn': '', - 'inact': '', - 'expire': ''}) + mock_user_info = MagicMock(return_value={'name': 'SALT', + 'password_changed': '', + 'expiration_date': ''}) + with patch.dict(win_shadow.__salt__, {'user.info': mock_user_info}): + self.assertDictEqual(win_shadow.info('SALT'), {'name': 'SALT', + 'passwd': 'Unavailable', + 'lstchg': '', + 'min': '', + 'max': '', + 'warn': '', + 'inact': '', + 'expire': ''}) # 'set_password' function tests: 1 @@ -48,5 +58,9 @@ class WinShadowTestCase(TestCase): Test if it set the password for a named user. ''' mock_cmd = MagicMock(return_value={'retcode': False}) - with patch.dict(win_shadow.__salt__, {'cmd.run_all': mock_cmd}): + mock_user_info = MagicMock(return_value={'name': 'SALT', + 'password_changed': '', + 'expiration_date': ''}) + with patch.dict(win_shadow.__salt__, {'cmd.run_all': mock_cmd, + 'user.info': mock_user_info}): self.assertTrue(win_shadow.set_password('root', 'mysecretpassword')) diff --git a/tests/unit/runners/test_queue.py b/tests/unit/runners/test_queue.py index b41519e99f..8b6b6aca64 100644 --- a/tests/unit/runners/test_queue.py +++ b/tests/unit/runners/test_queue.py @@ -5,8 +5,11 @@ unit tests for the cache runner # Import Python Libs from __future__ import absolute_import +import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin +from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -18,15 +21,21 @@ from tests.support.mock import ( # Import Salt Libs import salt.runners.queue as queue_mod -queue_mod.__opts__ = {'sock_dir': '/var/run/salt/master', 'transport': 'zeromq'} -queue_mod.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class QueueTest(TestCase): +class QueueTest(TestCase, LoaderModuleMockMixin): ''' Validate the queue runner ''' + def setup_loader_modules(self): + return { + queue_mod: { + '__opts__': { + 'sock_dir': os.path.join(TMP, 'queue-runner-sock-dir'), + 'transport': 'zeromq' + } + } + } def test_insert_runner(self): queue_insert = MagicMock(return_value=True) diff --git a/tests/unit/states/test_apache_module.py b/tests/unit/states/test_apache_module.py index 15c17d55cb..14a6e68d01 100644 --- a/tests/unit/states/test_apache_module.py +++ b/tests/unit/states/test_apache_module.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.apache_module as apache_module -apache_module.__opts__ = {} -apache_module.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ApacheModuleTestCase(TestCase): +class ApacheModuleTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.apache_module ''' + def setup_loader_modules(self): + return {apache_module: {}} + # 'enabled' function tests: 1 def test_enabled(self): diff --git a/tests/unit/states/test_apache_site.py b/tests/unit/states/test_apache_site.py index c5800abfa0..30cb2309b0 100644 --- a/tests/unit/states/test_apache_site.py +++ b/tests/unit/states/test_apache_site.py @@ -3,6 +3,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -14,15 +15,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.apache_site as apache_site -apache_site.__opts__ = {} -apache_site.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ApacheSiteTestCase(TestCase): +class ApacheSiteTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.apache_site ''' + def setup_loader_modules(self): + return {apache_site: {}} + # 'enabled' function tests: 1 def test_enabled(self): diff --git a/tests/unit/states/test_apt.py b/tests/unit/states/test_apt.py index 3725a92644..361d971a42 100644 --- a/tests/unit/states/test_apt.py +++ b/tests/unit/states/test_apt.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.aptpkg as aptpkg -aptpkg.__opts__ = {} -aptpkg.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class AptTestCase(TestCase): +class AptTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.aptpkg ''' + def setup_loader_modules(self): + return {aptpkg: {}} + # 'held' function tests: 1 def test_held(self): diff --git a/tests/unit/states/test_artifactory.py b/tests/unit/states/test_artifactory.py index fe415ad225..ac8ecce0b6 100644 --- a/tests/unit/states/test_artifactory.py +++ b/tests/unit/states/test_artifactory.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,14 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.artifactory as artifactory -artifactory.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ArtifactoryTestCase(TestCase): +class ArtifactoryTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.artifactory ''' + def setup_loader_modules(self): + return {artifactory: {}} + # 'downloaded' function tests: 1 def test_downloaded(self): diff --git a/tests/unit/states/test_at.py b/tests/unit/states/test_at.py index 73218fae83..d7e61b7d58 100644 --- a/tests/unit/states/test_at.py +++ b/tests/unit/states/test_at.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,16 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.at as at -at.__salt__ = {} -at.__opts__ = {} -at.__grains__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class AtTestCase(TestCase): +class AtTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.at ''' + def setup_loader_modules(self): + return {at: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_aws_sqs.py b/tests/unit/states/test_aws_sqs.py index 7bee43670d..74da1de8a6 100644 --- a/tests/unit/states/test_aws_sqs.py +++ b/tests/unit/states/test_aws_sqs.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.aws_sqs as aws_sqs -aws_sqs.__salt__ = {} -aws_sqs.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class AwsSqsTestCase(TestCase): +class AwsSqsTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.aws_sqs ''' + def setup_loader_modules(self): + return {aws_sqs: {}} + # 'exists' function tests: 1 def test_exists(self): diff --git a/tests/unit/states/test_blockdev.py b/tests/unit/states/test_blockdev.py index ecc6855c0d..e5899f1c70 100644 --- a/tests/unit/states/test_blockdev.py +++ b/tests/unit/states/test_blockdev.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -18,15 +19,15 @@ from tests.support.mock import ( import salt.states.blockdev as blockdev import salt.utils -blockdev.__salt__ = {} -blockdev.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class BlockdevTestCase(TestCase): +class BlockdevTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.blockdev ''' + def setup_loader_modules(self): + return {blockdev: {}} + # 'tuned' function tests: 1 def test_tuned(self): diff --git a/tests/unit/states/test_chef.py b/tests/unit/states/test_chef.py index 027aa2259e..e9660606fb 100644 --- a/tests/unit/states/test_chef.py +++ b/tests/unit/states/test_chef.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.chef as chef -chef.__salt__ = {} -chef.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ChefTestCase(TestCase): +class ChefTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.chef ''' + def setup_loader_modules(self): + return {chef: {}} + # 'client' function tests: 1 def test_client(self): diff --git a/tests/unit/states/test_cloud.py b/tests/unit/states/test_cloud.py index b1615618f1..3b92b00c1d 100644 --- a/tests/unit/states/test_cloud.py +++ b/tests/unit/states/test_cloud.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( import salt.states.cloud as cloud import salt.utils.cloud -cloud.__salt__ = {} -cloud.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class CloudTestCase(TestCase): +class CloudTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.cloud ''' + def setup_loader_modules(self): + return {cloud: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_cmd.py b/tests/unit/states/test_cmd.py index 493426cd46..29607be5c0 100644 --- a/tests/unit/states/test_cmd.py +++ b/tests/unit/states/test_cmd.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import os.path # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -19,17 +20,15 @@ from salt.exceptions import CommandExecutionError # Import Salt Libs import salt.states.cmd as cmd -cmd.__salt__ = {} -cmd.__opts__ = {} -cmd.__grains__ = {} -cmd.__env__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class CmdTestCase(TestCase): +class CmdTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.cmd ''' + def setup_loader_modules(self): + return {cmd: {'__env__': 'base'}} + # 'mod_run_check' function tests: 1 def test_mod_run_check(self): diff --git a/tests/unit/states/test_composer.py b/tests/unit/states/test_composer.py index f50f6855dd..20bd733eaf 100644 --- a/tests/unit/states/test_composer.py +++ b/tests/unit/states/test_composer.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -18,15 +19,15 @@ from salt.exceptions import SaltException # Import Salt Libs import salt.states.composer as composer -composer.__salt__ = {} -composer.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ComposerTestCase(TestCase): +class ComposerTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.composer ''' + def setup_loader_modules(self): + return {composer: {}} + # 'installed' function tests: 1 def test_installed(self): diff --git a/tests/unit/states/test_ddns.py b/tests/unit/states/test_ddns.py index f5dc6bb0d0..3f25e68cf9 100644 --- a/tests/unit/states/test_ddns.py +++ b/tests/unit/states/test_ddns.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.ddns as ddns -ddns.__salt__ = {} -ddns.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DdnsTestCase(TestCase): +class DdnsTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ddns ''' + def setup_loader_modules(self): + return {ddns: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_debconfmod.py b/tests/unit/states/test_debconfmod.py index bd6d4c1ead..054be78e19 100644 --- a/tests/unit/states/test_debconfmod.py +++ b/tests/unit/states/test_debconfmod.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.debconfmod as debconfmod -debconfmod.__salt__ = {} -debconfmod.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DebconfmodTestCase(TestCase): +class DebconfmodTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.debconfmod ''' + def setup_loader_modules(self): + return {debconfmod: {}} + # 'set_file' function tests: 1 def test_set_file(self): diff --git a/tests/unit/states/test_disk.py b/tests/unit/states/test_disk.py index 5eb594845c..c09d5b6c95 100644 --- a/tests/unit/states/test_disk.py +++ b/tests/unit/states/test_disk.py @@ -6,6 +6,7 @@ Tests for disk state from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,18 +17,13 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.disk as disk -disk.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DiskTestCase(TestCase): +class DiskTestCase(TestCase, LoaderModuleMockMixin): ''' Test disk state ''' - def setUp(self): - ''' - setup common test info - ''' + def setup_loader_modules(self): self.mock_data = { '/': { '1K-blocks': '41147472', @@ -54,9 +50,8 @@ class DiskTestCase(TestCase): 'filesystem': 'tmpfs', 'used': '0'} } - self.__salt__ = { - 'disk.usage': MagicMock(return_value=self.mock_data), - } + self.addCleanup(delattr, self, 'mock_data') + return {disk: {'__salt__': {'disk.usage': MagicMock(return_value=self.mock_data)}}} def test_status_missing(self): ''' @@ -69,9 +64,8 @@ class DiskTestCase(TestCase): 'changes': {}, 'data': {}} - with patch.dict(disk.__salt__, self.__salt__): - ret = disk.status(mock_fs) - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs) + self.assertEqual(ret, mock_ret) def test_status_type_error(self): ''' @@ -84,15 +78,13 @@ class DiskTestCase(TestCase): 'changes': {}, 'data': {}} - with patch.dict(disk.__salt__, self.__salt__): - mock_ret['comment'] = 'maximum must be an integer ' - ret = disk.status(mock_fs, maximum=r'e^{i\pi}') - self.assertEqual(ret, mock_ret) + mock_ret['comment'] = 'maximum must be an integer ' + ret = disk.status(mock_fs, maximum=r'e^{i\pi}') + self.assertEqual(ret, mock_ret) - with patch.dict(disk.__salt__, self.__salt__): - mock_ret['comment'] = 'minimum must be an integer ' - ret = disk.status(mock_fs, minimum=r'\cos\pi + i\sin\pi') - self.assertEqual(ret, mock_ret) + mock_ret['comment'] = 'minimum must be an integer ' + ret = disk.status(mock_fs, minimum=r'\cos\pi + i\sin\pi') + self.assertEqual(ret, mock_ret) def test_status_range_error(self): ''' @@ -105,15 +97,13 @@ class DiskTestCase(TestCase): 'changes': {}, 'data': {}} - with patch.dict(disk.__salt__, self.__salt__): - mock_ret['comment'] = 'maximum must be in the range [0, 100] ' - ret = disk.status(mock_fs, maximum='-1') - self.assertEqual(ret, mock_ret) + mock_ret['comment'] = 'maximum must be in the range [0, 100] ' + ret = disk.status(mock_fs, maximum='-1') + self.assertEqual(ret, mock_ret) - with patch.dict(disk.__salt__, self.__salt__): - mock_ret['comment'] = 'minimum must be in the range [0, 100] ' - ret = disk.status(mock_fs, minimum='101') - self.assertEqual(ret, mock_ret) + mock_ret['comment'] = 'minimum must be in the range [0, 100] ' + ret = disk.status(mock_fs, minimum='101') + self.assertEqual(ret, mock_ret) def test_status_inverted_range(self): ''' @@ -126,9 +116,8 @@ class DiskTestCase(TestCase): 'changes': {}, 'data': {}} - with patch.dict(disk.__salt__, self.__salt__): - ret = disk.status(mock_fs, maximum='0', minimum='1') - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, maximum='0', minimum='1') + self.assertEqual(ret, mock_ret) def test_status_threshold(self): ''' @@ -144,21 +133,19 @@ class DiskTestCase(TestCase): 'changes': {}, 'data': self.mock_data[mock_fs]} - with patch.dict(disk.__salt__, self.__salt__): - mock_ret['comment'] = 'Disk used space is below minimum of {0} % at {1} %'.format( - mock_min, - mock_used - ) - ret = disk.status(mock_fs, minimum=mock_min) - self.assertEqual(ret, mock_ret) + mock_ret['comment'] = 'Disk used space is below minimum of {0} % at {1} %'.format( + mock_min, + mock_used + ) + ret = disk.status(mock_fs, minimum=mock_min) + self.assertEqual(ret, mock_ret) - with patch.dict(disk.__salt__, self.__salt__): - mock_ret['comment'] = 'Disk used space is above maximum of {0} % at {1} %'.format( - mock_max, - mock_used - ) - ret = disk.status(mock_fs, maximum=mock_max) - self.assertEqual(ret, mock_ret) + mock_ret['comment'] = 'Disk used space is above maximum of {0} % at {1} %'.format( + mock_max, + mock_used + ) + ret = disk.status(mock_fs, maximum=mock_max) + self.assertEqual(ret, mock_ret) def test_status_strip(self): ''' @@ -171,24 +158,23 @@ class DiskTestCase(TestCase): 'changes': {}, 'data': self.mock_data[mock_fs]} - with patch.dict(disk.__salt__, self.__salt__): - ret = disk.status(mock_fs, minimum='0%') - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, minimum='0%') + self.assertEqual(ret, mock_ret) - ret = disk.status(mock_fs, minimum='0 %') - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, minimum='0 %') + self.assertEqual(ret, mock_ret) - ret = disk.status(mock_fs, maximum='100%') - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, maximum='100%') + self.assertEqual(ret, mock_ret) - ret = disk.status(mock_fs, minimum='1024K', absolute=True) - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, minimum='1024K', absolute=True) + self.assertEqual(ret, mock_ret) - ret = disk.status(mock_fs, minimum='1024KB', absolute=True) - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, minimum='1024KB', absolute=True) + self.assertEqual(ret, mock_ret) - ret = disk.status(mock_fs, maximum='4194304 KB', absolute=True) - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, maximum='4194304 KB', absolute=True) + self.assertEqual(ret, mock_ret) def test_status(self): ''' @@ -203,13 +189,11 @@ class DiskTestCase(TestCase): 'changes': {}, 'data': self.mock_data[mock_fs]} - with patch.dict(disk.__salt__, self.__salt__): - ret = disk.status(mock_fs, minimum=mock_min) - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, minimum=mock_min) + self.assertEqual(ret, mock_ret) - with patch.dict(disk.__salt__, self.__salt__): - ret = disk.status(mock_fs, maximum=mock_max) - self.assertEqual(ret, mock_ret) + ret = disk.status(mock_fs, maximum=mock_max) + self.assertEqual(ret, mock_ret) # Reset mock because it's an iterator to run the tests with the # absolute flag diff --git a/tests/unit/states/test_docker_image.py b/tests/unit/states/test_docker_image.py index d6ac0f9366..4d94c2e239 100644 --- a/tests/unit/states/test_docker_image.py +++ b/tests/unit/states/test_docker_image.py @@ -7,6 +7,7 @@ Unit tests for the docker state from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( Mock, @@ -20,17 +21,22 @@ from salt.exceptions import CommandExecutionError import salt.modules.dockermod as docker_mod import salt.states.docker_image as docker_state -docker_mod.__context__ = {'docker.docker_version': ''} -docker_mod.__salt__ = {} -docker_state.__context__ = {} -docker_state.__opts__ = {'test': False} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DockerImageTestCase(TestCase): +class DockerImageTestCase(TestCase, LoaderModuleMockMixin): ''' Test docker_image states ''' + def setup_loader_modules(self): + return { + docker_mod: { + '__context__': {'docker.docker_version': ''} + }, + docker_state: { + '__opts__': {'test': False} + } + } + def test_present_already_local(self): ''' According following sls, diff --git a/tests/unit/states/test_docker_network.py b/tests/unit/states/test_docker_network.py index 8897b3929c..7b0037a7d4 100644 --- a/tests/unit/states/test_docker_network.py +++ b/tests/unit/states/test_docker_network.py @@ -7,6 +7,7 @@ Unit tests for the docker state from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( Mock, @@ -19,17 +20,22 @@ from tests.support.mock import ( import salt.modules.dockermod as docker_mod import salt.states.docker_network as docker_state -docker_mod.__context__ = {'docker.docker_version': ''} -docker_mod.__salt__ = {} -docker_state.__context__ = {} -docker_state.__opts__ = {'test': False} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DockerNetworkTestCase(TestCase): +class DockerNetworkTestCase(TestCase, LoaderModuleMockMixin): ''' Test docker_network states ''' + def setup_loader_modules(self): + return { + docker_mod: { + '__context__': {'docker.docker_version': ''} + }, + docker_state: { + '__opts__': {'test': False} + } + } + def test_present(self): ''' Test docker_network.present diff --git a/tests/unit/states/test_docker_volume.py b/tests/unit/states/test_docker_volume.py index 33a6942c04..c5c10c78b5 100644 --- a/tests/unit/states/test_docker_volume.py +++ b/tests/unit/states/test_docker_volume.py @@ -7,6 +7,7 @@ Unit tests for the docker state from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( Mock, @@ -19,17 +20,22 @@ from tests.support.mock import ( import salt.modules.dockermod as docker_mod import salt.states.docker_volume as docker_state -docker_mod.__context__ = {'docker.docker_version': ''} -docker_mod.__salt__ = {} -docker_state.__context__ = {} -docker_state.__opts__ = {'test': False} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DockerVolumeTestCase(TestCase): +class DockerVolumeTestCase(TestCase, LoaderModuleMockMixin): ''' Test docker_volume states ''' + def setup_loader_modules(self): + return { + docker_mod: { + '__context__': {'docker.docker_version': ''} + }, + docker_state: { + '__opts__': {'test': False} + } + } + def test_present(self): ''' Test docker_volume.present diff --git a/tests/unit/states/test_drac.py b/tests/unit/states/test_drac.py index fae08f653f..b72e9f8828 100644 --- a/tests/unit/states/test_drac.py +++ b/tests/unit/states/test_drac.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.drac as drac -drac.__salt__ = {} -drac.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class DracTestCase(TestCase): +class DracTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.drac ''' + def setup_loader_modules(self): + return {drac: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_eselect.py b/tests/unit/states/test_eselect.py index b818873ece..0844202c9e 100644 --- a/tests/unit/states/test_eselect.py +++ b/tests/unit/states/test_eselect.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,14 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.eselect as eselect -eselect.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class EselectTestCase(TestCase): +class EselectTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.eselect ''' + def setup_loader_modules(self): + return {eselect: {}} + # 'set_' function tests: 1 def test_set_(self): diff --git a/tests/unit/states/test_event.py b/tests/unit/states/test_event.py index 14f851640d..a6bfb00219 100644 --- a/tests/unit/states/test_event.py +++ b/tests/unit/states/test_event.py @@ -9,6 +9,7 @@ from __future__ import absolute_import import salt.states.event as event # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( patch ) -event.__opts__ = {} -event.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class EventTestCase(TestCase): +class EventTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the event state ''' + def setup_loader_modules(self): + return {event: {}} + def test_send(self): ''' Test to send an event to the Salt Master diff --git a/tests/unit/states/test_grafana.py b/tests/unit/states/test_grafana.py index 930e498273..4718fddd00 100644 --- a/tests/unit/states/test_grafana.py +++ b/tests/unit/states/test_grafana.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import json # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -19,15 +20,15 @@ from tests.support.mock import ( import salt.states.grafana as grafana from salt.exceptions import SaltInvocationError -grafana.__opts__ = {} -grafana.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class GrafanaTestCase(TestCase): +class GrafanaTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.grafana ''' + def setup_loader_modules(self): + return {grafana: {}} + # 'dashboard_present' function tests: 1 def test_dashboard_present(self): diff --git a/tests/unit/states/test_grafana_datasource.py b/tests/unit/states/test_grafana_datasource.py index d6cea25838..b57dc98245 100644 --- a/tests/unit/states/test_grafana_datasource.py +++ b/tests/unit/states/test_grafana_datasource.py @@ -3,6 +3,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -15,9 +16,6 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.grafana_datasource as grafana_datasource -grafana_datasource.__opts__ = {} -grafana_datasource.__salt__ = {} - profile = { 'grafana_url': 'http://grafana', 'grafana_token': 'token', @@ -31,7 +29,10 @@ def mock_json_response(data): @skipIf(NO_MOCK, NO_MOCK_REASON) -class GrafanaDatasourceTestCase(TestCase): +class GrafanaDatasourceTestCase(TestCase, LoaderModuleMockMixin): + def setup_loader_modules(self): + return {grafana_datasource: {}} + def test_present(self): with patch('requests.get', mock_json_response([])): with patch('requests.post') as rpost: diff --git a/tests/unit/states/test_group.py b/tests/unit/states/test_group.py index 0adef644bd..938de213ca 100644 --- a/tests/unit/states/test_group.py +++ b/tests/unit/states/test_group.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -20,16 +21,14 @@ import salt.states.group as group from salt.utils.odict import OrderedDict -# Globals -group.__salt__ = {} -group.__opts__ = {} - - @skipIf(NO_MOCK, NO_MOCK_REASON) -class GroupTestCase(TestCase): +class GroupTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the group state ''' + def setup_loader_modules(self): + return {group: {}} + def test_present(self): ''' Test to ensure that a group is present diff --git a/tests/unit/states/test_hg.py b/tests/unit/states/test_hg.py index f9539c3f82..366fba5653 100644 --- a/tests/unit/states/test_hg.py +++ b/tests/unit/states/test_hg.py @@ -10,6 +10,7 @@ import os import salt.states.hg as hg # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -18,15 +19,15 @@ from tests.support.mock import ( patch ) -hg.__opts__ = {} -hg.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class HgTestCase(TestCase): +class HgTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the svn state ''' + def setup_loader_modules(self): + return {hg: {}} + def test_latest(self): ''' Test to Make sure the repository is cloned to diff --git a/tests/unit/states/test_hipchat.py b/tests/unit/states/test_hipchat.py index e60e6de9a8..243d9d82a0 100644 --- a/tests/unit/states/test_hipchat.py +++ b/tests/unit/states/test_hipchat.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.hipchat as hipchat -hipchat.__salt__ = {} -hipchat.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class HipchatTestCase(TestCase): +class HipchatTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.hipchat ''' + def setup_loader_modules(self): + return {hipchat: {}} + # 'send_message' function tests: 1 def test_send_message(self): diff --git a/tests/unit/states/test_host.py b/tests/unit/states/test_host.py index 3a9e7c2fc6..124e696325 100644 --- a/tests/unit/states/test_host.py +++ b/tests/unit/states/test_host.py @@ -9,6 +9,7 @@ from __future__ import absolute_import import salt.states.host as host # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( patch ) -host.__salt__ = {} -host.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class HostTestCase(TestCase): +class HostTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the host state ''' + def setup_loader_modules(self): + return {host: {}} + def test_present(self): ''' Test to ensures that the named host is present with the given ip diff --git a/tests/unit/states/test_http.py b/tests/unit/states/test_http.py index 419be2c126..d0c962f3d2 100644 --- a/tests/unit/states/test_http.py +++ b/tests/unit/states/test_http.py @@ -9,6 +9,7 @@ from __future__ import absolute_import import salt.states.http as http # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( patch ) -http.__salt__ = {} -http.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class HttpTestCase(TestCase): +class HttpTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the HTTP state ''' + def setup_loader_modules(self): + return {http: {}} + def test_query(self): ''' Test to perform an HTTP query and statefully return the result diff --git a/tests/unit/states/test_incron.py b/tests/unit/states/test_incron.py index e9bd4ce44a..d9c43a725a 100644 --- a/tests/unit/states/test_incron.py +++ b/tests/unit/states/test_incron.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.incron as incron -incron.__salt__ = {} -incron.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class IncronTestCase(TestCase): +class IncronTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.incron ''' + def setup_loader_modules(self): + return {incron: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_influxdb08_database.py b/tests/unit/states/test_influxdb08_database.py index 15e3db38b6..b91b515a24 100644 --- a/tests/unit/states/test_influxdb08_database.py +++ b/tests/unit/states/test_influxdb08_database.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.influxdb08_database as influxdb08_database -influxdb08_database.__salt__ = {} -influxdb08_database.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class InfluxdbDatabaseTestCase(TestCase): +class InfluxdbDatabaseTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.influxdb08_database ''' + def setup_loader_modules(self): + return {influxdb08_database: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_influxdb08_user.py b/tests/unit/states/test_influxdb08_user.py index 47cec79d8f..c59b1f371c 100644 --- a/tests/unit/states/test_influxdb08_user.py +++ b/tests/unit/states/test_influxdb08_user.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.influxdb08_user as influxdb08_user -influxdb08_user.__salt__ = {} -influxdb08_user.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class InfluxdbUserTestCase(TestCase): +class InfluxdbUserTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.influxdb08_user ''' + def setup_loader_modules(self): + return {influxdb08_user: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_ini_manage.py b/tests/unit/states/test_ini_manage.py index 45f3c5da4f..c4b0cdc0aa 100644 --- a/tests/unit/states/test_ini_manage.py +++ b/tests/unit/states/test_ini_manage.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( MagicMock, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.ini_manage as ini_manage -ini_manage.__salt__ = {} -ini_manage.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class IniManageTestCase(TestCase): +class IniManageTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ini_manage ''' + def setup_loader_modules(self): + return {ini_manage: {}} + # 'options_present' function tests: 1 def test_options_present(self): diff --git a/tests/unit/states/test_ipmi.py b/tests/unit/states/test_ipmi.py index eedfcca9df..37c355fac1 100644 --- a/tests/unit/states/test_ipmi.py +++ b/tests/unit/states/test_ipmi.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.ipmi as ipmi -ipmi.__salt__ = {} -ipmi.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class IpmiTestCase(TestCase): +class IpmiTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ipmi ''' + def setup_loader_modules(self): + return {ipmi: {}} + # 'boot_device' function tests: 1 def test_boot_device(self): diff --git a/tests/unit/states/test_ipset.py b/tests/unit/states/test_ipset.py index 0761984672..8d95fece85 100644 --- a/tests/unit/states/test_ipset.py +++ b/tests/unit/states/test_ipset.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,12 +18,9 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.ipset as ipset -ipset.__salt__ = {} -ipset.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class IpsetSetPresentTestCase(TestCase): +class IpsetSetPresentTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ipset.present ''' @@ -30,6 +28,9 @@ class IpsetSetPresentTestCase(TestCase): fake_name = 'fake_ipset' fake_set_type = {'bitmap': '192.168.0.3'} + def setup_loader_modules(self): + return {ipset: {}} + def _runner(self, expected_ret, test=False, check_set=False, new_set=None, new_set_assertion=True): mock_check_set = MagicMock(return_value=check_set) @@ -82,7 +83,7 @@ class IpsetSetPresentTestCase(TestCase): @skipIf(NO_MOCK, NO_MOCK_REASON) -class IpsetSetAbsentTestCase(TestCase): +class IpsetSetAbsentTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ipset.present ''' @@ -90,6 +91,9 @@ class IpsetSetAbsentTestCase(TestCase): fake_name = 'fake_ipset' fake_set_type = {'bitmap': '192.168.0.3'} + def setup_loader_modules(self): + return {ipset: {}} + def _runner(self, expected_ret, test=False, check_set=True, delete_set='', flush_assertion=False, delete_set_assertion=False): mock_check_set = MagicMock(return_value=check_set) @@ -141,7 +145,7 @@ class IpsetSetAbsentTestCase(TestCase): @skipIf(NO_MOCK, NO_MOCK_REASON) -class IpsetPresentTestCase(TestCase): +class IpsetPresentTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ipset.present ''' @@ -149,6 +153,9 @@ class IpsetPresentTestCase(TestCase): fake_name = 'fake_ipset' fake_entries = ['192.168.0.3', '192.168.1.3'] + def setup_loader_modules(self): + return {ipset: {}} + def _runner(self, expected_ret, test=False, check=False, add=False, add_assertion=False): mock_check = MagicMock(return_value=check) @@ -215,7 +222,7 @@ class IpsetPresentTestCase(TestCase): @skipIf(NO_MOCK, NO_MOCK_REASON) -class IpsetAbsentTestCase(TestCase): +class IpsetAbsentTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ipset.present ''' @@ -223,6 +230,9 @@ class IpsetAbsentTestCase(TestCase): fake_name = 'fake_ipset' fake_entries = ['192.168.0.3', '192.168.1.3'] + def setup_loader_modules(self): + return {ipset: {}} + def _runner(self, expected_ret, test=False, check=False, delete=False, delete_assertion=False): mock_check = MagicMock(return_value=check) @@ -287,13 +297,16 @@ class IpsetAbsentTestCase(TestCase): @skipIf(NO_MOCK, NO_MOCK_REASON) -class IpsetFlushTestCase(TestCase): +class IpsetFlushTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ipset.present ''' fake_name = 'fake_ipset' + def setup_loader_modules(self): + return {ipset: {}} + def _runner(self, expected_ret, test=False, check_set=True, flush=True, flush_assertion=True): mock_check_set = MagicMock(return_value=check_set) diff --git a/tests/unit/states/test_iptables.py b/tests/unit/states/test_iptables.py index 23ff45ad7b..9393a69cf9 100644 --- a/tests/unit/states/test_iptables.py +++ b/tests/unit/states/test_iptables.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.iptables as iptables -# Globals -iptables.__salt__ = {} -iptables.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class IptablesTestCase(TestCase): +class IptablesTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the iptables state ''' + def setup_loader_modules(self): + return {iptables: {}} + def test_chain_present(self): ''' Test to verify the chain is exist. diff --git a/tests/unit/states/test_keyboard.py b/tests/unit/states/test_keyboard.py index 42f6708d1c..f55c375ccd 100644 --- a/tests/unit/states/test_keyboard.py +++ b/tests/unit/states/test_keyboard.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.keyboard as keyboard -keyboard.__salt__ = {} -keyboard.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class KeyboardTestCase(TestCase): +class KeyboardTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.keyboard ''' + def setup_loader_modules(self): + return {keyboard: {}} + # 'system' function tests: 1 def test_system(self): diff --git a/tests/unit/states/test_keystone.py b/tests/unit/states/test_keystone.py index a82b386719..3702f3269d 100644 --- a/tests/unit/states/test_keystone.py +++ b/tests/unit/states/test_keystone.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.keystone as keystone -keystone.__opts__ = {} -keystone.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class KeystoneTestCase(TestCase): +class KeystoneTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.keystone ''' + def setup_loader_modules(self): + return {keystone: {}} + # 'user_present' function tests: 1 def test_user_present(self): diff --git a/tests/unit/states/test_kmod.py b/tests/unit/states/test_kmod.py index f8c668ddaa..6a380bc260 100644 --- a/tests/unit/states/test_kmod.py +++ b/tests/unit/states/test_kmod.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.kmod as kmod -kmod.__salt__ = {} -kmod.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class KmodTestCase(TestCase): +class KmodTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.kmod ''' + def setup_loader_modules(self): + return {kmod: {}} + # 'present' function tests: 2 def test_present(self): diff --git a/tests/unit/states/test_layman.py b/tests/unit/states/test_layman.py index cf6efda94e..cb45e7b812 100644 --- a/tests/unit/states/test_layman.py +++ b/tests/unit/states/test_layman.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.layman as layman -layman.__salt__ = {} -layman.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LaymanTestCase(TestCase): +class LaymanTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.layman ''' + def setup_loader_modules(self): + return {layman: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_libcloud_dns.py b/tests/unit/states/test_libcloud_dns.py index 5138e734b9..83e4c60929 100644 --- a/tests/unit/states/test_libcloud_dns.py +++ b/tests/unit/states/test_libcloud_dns.py @@ -7,17 +7,14 @@ from __future__ import absolute_import # Import Salt Testing Libs -from tests.support.unit import skipIf -from tests.unit import ModuleTestCase, hasDependency +from tests.support.mixins import LoaderModuleMockMixin +from tests.support.unit import TestCase, skipIf from tests.support.mock import ( NO_MOCK, NO_MOCK_REASON ) import salt.states.libcloud_dns as libcloud_dns -SERVICE_NAME = 'libcloud_dns' -libcloud_dns.__utils__ = {} - class TestZone(object): def __init__(self, id, domain): @@ -43,12 +40,12 @@ def get_mock_driver(): test_records = { - "zone1": [TestRecord(0, "www", "A", "127.0.0.1")] + 'zone1': [TestRecord(0, 'www', 'A', '127.0.0.1')] } def list_zones(profile): - return [TestZone("zone1", "test.com")] + return [TestZone('zone1', 'test.com')] def list_records(zone_id, profile): @@ -71,103 +68,91 @@ def delete_zone(*args): return True -libcloud_dns.__salt__ = { - 'libcloud_dns.list_zones': list_zones, - 'libcloud_dns.list_records': list_records, - 'libcloud_dns.create_record': create_record, - 'libcloud_dns.delete_record': delete_record, - 'libcloud_dns.create_zone': create_zone, - 'libcloud_dns.delete_zone': delete_zone -} - - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LibcloudDnsModuleTestCase(ModuleTestCase): - def setUp(self): - hasDependency('libcloud', fake_module=False) +class LibcloudDnsModuleTestCase(TestCase, LoaderModuleMockMixin): - def get_config(service): - if service == SERVICE_NAME: - return { - 'test': { - 'driver': 'test', - 'key': '2orgk34kgk34g' - } + def setup_loader_modules(self): + return { + libcloud_dns: { + '__salt__': { + 'libcloud_dns.list_zones': list_zones, + 'libcloud_dns.list_records': list_records, + 'libcloud_dns.create_record': create_record, + 'libcloud_dns.delete_record': delete_record, + 'libcloud_dns.create_zone': create_zone, + 'libcloud_dns.delete_zone': delete_zone } - else: - raise KeyError("service name invalid") - - self.setup_loader() - self.loader.set_result(libcloud_dns, 'config.option', get_config) + } + } def test_present_record_exists(self): - """ + ''' Try and create a record that already exists - """ - result = libcloud_dns.record_present("www", "test.com", "A", "127.0.0.1", "test") + ''' + result = libcloud_dns.record_present('www', 'test.com', 'A', '127.0.0.1', 'test') self.assertTrue(result) def test_present_record_does_not_exist(self): - """ + ''' Try and create a record that already exists - """ - result = libcloud_dns.record_present("mail", "test.com", "A", "127.0.0.1", "test") + ''' + result = libcloud_dns.record_present('mail', 'test.com', 'A', '127.0.0.1', 'test') self.assertTrue(result) def test_absent_record_exists(self): - """ + ''' Try and deny a record that already exists - """ - result = libcloud_dns.record_absent("www", "test.com", "A", "127.0.0.1", "test") + ''' + result = libcloud_dns.record_absent('www', 'test.com', 'A', '127.0.0.1', 'test') self.assertTrue(result) def test_absent_record_does_not_exist(self): - """ + ''' Try and deny a record that already exists - """ - result = libcloud_dns.record_absent("mail", "test.com", "A", "127.0.0.1", "test") + ''' + result = libcloud_dns.record_absent('mail', 'test.com', 'A', '127.0.0.1', 'test') self.assertTrue(result) def test_present_zone_not_found(self): - """ + ''' Assert that when you try and ensure present state for a record to a zone that doesn't exist it fails gracefully - """ - result = libcloud_dns.record_present("mail", "notatest.com", "A", "127.0.0.1", "test") + ''' + result = libcloud_dns.record_present('mail', 'notatest.com', 'A', '127.0.0.1', 'test') self.assertFalse(result['result']) def test_absent_zone_not_found(self): - """ + ''' Assert that when you try and ensure absent state for a record to a zone that doesn't exist it fails gracefully - """ - result = libcloud_dns.record_absent("mail", "notatest.com", "A", "127.0.0.1", "test") + ''' + result = libcloud_dns.record_absent('mail', 'notatest.com', 'A', '127.0.0.1', 'test') self.assertFalse(result['result']) def test_zone_present(self): - """ + ''' Assert that a zone is present (that did not exist) - """ + ''' result = libcloud_dns.zone_present('testing.com', 'master', 'test1') self.assertTrue(result) def test_zone_already_present(self): - """ + ''' Assert that a zone is present (that did exist) - """ + ''' result = libcloud_dns.zone_present('test.com', 'master', 'test1') self.assertTrue(result) def test_zone_absent(self): - """ + ''' Assert that a zone that did exist is absent - """ + ''' result = libcloud_dns.zone_absent('test.com', 'test1') self.assertTrue(result) def test_zone_already_absent(self): - """ + ''' Assert that a zone that did not exist is absent - """ + ''' result = libcloud_dns.zone_absent('testing.com', 'test1') self.assertTrue(result) diff --git a/tests/unit/states/test_libvirt.py b/tests/unit/states/test_libvirt.py index e07cb7f7f0..2ef9a10fa2 100644 --- a/tests/unit/states/test_libvirt.py +++ b/tests/unit/states/test_libvirt.py @@ -4,9 +4,12 @@ ''' # Import Python libs from __future__ import absolute_import -import os +import tempfile +import shutil # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin +from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -19,18 +22,26 @@ from tests.support.mock import ( import salt.states.virt as virt import salt.utils -virt.__salt__ = {} -virt.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LibvirtTestCase(TestCase): +class LibvirtTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.libvirt ''' + def setup_loader_modules(self): + return {virt: {}} + + @classmethod + def setUpClass(cls): + cls.pki_dir = tempfile.mkdtemp(dir=TMP) + + @classmethod + def tearDownClass(cls): + shutil.rmtree(cls.pki_dir) + del cls.pki_dir + # 'keys' function tests: 1 - @skipIf(os.geteuid() != 0, 'you must be root to run this test') @patch('os.path.isfile', MagicMock(return_value=False)) def test_keys(self): ''' @@ -48,16 +59,16 @@ class LibvirtTestCase(TestCase): with patch.dict(virt.__salt__, {'pillar.ext': mock}): comt = ('All keys are correct') ret.update({'comment': comt}) - self.assertDictEqual(virt.keys(name), ret) + self.assertDictEqual(virt.keys(name, basepath=self.pki_dir), ret) with patch.dict(virt.__opts__, {'test': True}): comt = ('Libvirt keys are set to be updated') ret.update({'comment': comt, 'result': None}) - self.assertDictEqual(virt.keys(name), ret) + self.assertDictEqual(virt.keys(name, basepath=self.pki_dir), ret) with patch.dict(virt.__opts__, {'test': False}): with patch.object(salt.utils, 'fopen', MagicMock(mock_open())): comt = ('Updated libvirt certs and keys') ret.update({'comment': comt, 'result': True, 'changes': {'servercert': 'new'}}) - self.assertDictEqual(virt.keys(name), ret) + self.assertDictEqual(virt.keys(name, basepath=self.pki_dir), ret) diff --git a/tests/unit/states/test_linux_acl.py b/tests/unit/states/test_linux_acl.py index d02ccbb20c..3ade701b82 100644 --- a/tests/unit/states/test_linux_acl.py +++ b/tests/unit/states/test_linux_acl.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import sys # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,16 +18,16 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.linux_acl as linux_acl -linux_acl.__salt__ = {} -linux_acl.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) @skipIf(not sys.platform.startswith('linux'), 'Test for Linux only') -class LinuxAclTestCase(TestCase): +class LinuxAclTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.linux_acl ''' + def setup_loader_modules(self): + return {linux_acl: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_locale.py b/tests/unit/states/test_locale.py index 554bfc7018..8742541e2c 100644 --- a/tests/unit/states/test_locale.py +++ b/tests/unit/states/test_locale.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.locale as locale -# Globals -locale.__salt__ = {} -locale.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LocaleTestCase(TestCase): +class LocaleTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the locale state ''' + def setup_loader_modules(self): + return {locale: {}} + def test_system(self): ''' Test to set the locale for the system diff --git a/tests/unit/states/test_lvm.py b/tests/unit/states/test_lvm.py index 423f8012bd..46d0cc532d 100644 --- a/tests/unit/states/test_lvm.py +++ b/tests/unit/states/test_lvm.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.lvm as lvm -lvm.__opts__ = {} -lvm.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LvmTestCase(TestCase): +class LvmTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.lvm ''' + def setup_loader_modules(self): + return {lvm: {}} + # 'pv_present' function tests: 1 def test_pv_present(self): diff --git a/tests/unit/states/test_lvs_server.py b/tests/unit/states/test_lvs_server.py index 32f562c939..3332136748 100644 --- a/tests/unit/states/test_lvs_server.py +++ b/tests/unit/states/test_lvs_server.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.lvs_server as lvs_server -lvs_server.__salt__ = {} -lvs_server.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LvsServerTestCase(TestCase): +class LvsServerTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.lvs_server ''' + def setup_loader_modules(self): + return {lvs_server: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_lvs_service.py b/tests/unit/states/test_lvs_service.py index cd15640dd1..8611b67881 100644 --- a/tests/unit/states/test_lvs_service.py +++ b/tests/unit/states/test_lvs_service.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.lvs_service as lvs_service -lvs_service.__salt__ = {} -lvs_service.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LvsServiceTestCase(TestCase): +class LvsServiceTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.lvs_service ''' + def setup_loader_modules(self): + return {lvs_service: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_lxc.py b/tests/unit/states/test_lxc.py index 05175a6ae7..868636d196 100644 --- a/tests/unit/states/test_lxc.py +++ b/tests/unit/states/test_lxc.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( import salt.states.lxc as lxc import salt.utils -lxc.__salt__ = {} -lxc.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class LxcTestCase(TestCase): +class LxcTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.lxc ''' + def setup_loader_modules(self): + return {lxc: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_mac_assistive.py b/tests/unit/states/test_mac_assistive.py index 9fb5dcd971..2af0914647 100644 --- a/tests/unit/states/test_mac_assistive.py +++ b/tests/unit/states/test_mac_assistive.py @@ -7,16 +7,17 @@ from __future__ import absolute_import import salt.states.mac_assistive as assistive # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase from tests.support.mock import ( MagicMock, patch ) -assistive.__salt__ = {} - -class AssistiveTestCase(TestCase): +class AssistiveTestCase(TestCase, LoaderModuleMockMixin): + def setup_loader_modules(self): + return {assistive: {}} def test_installed(self): ''' diff --git a/tests/unit/states/test_mac_defaults.py b/tests/unit/states/test_mac_defaults.py index b8b0001922..811637c8eb 100644 --- a/tests/unit/states/test_mac_defaults.py +++ b/tests/unit/states/test_mac_defaults.py @@ -7,16 +7,17 @@ from __future__ import absolute_import import salt.states.mac_defaults as macdefaults # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase from tests.support.mock import ( MagicMock, patch ) -macdefaults.__salt__ = {} - -class MacDefaultsTestCase(TestCase): +class MacDefaultsTestCase(TestCase, LoaderModuleMockMixin): + def setup_loader_modules(self): + return {macdefaults: {}} def test_write(self): ''' diff --git a/tests/unit/states/test_mac_keychain.py b/tests/unit/states/test_mac_keychain.py index cdba8c706d..b21a7dda28 100644 --- a/tests/unit/states/test_mac_keychain.py +++ b/tests/unit/states/test_mac_keychain.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import salt.states.mac_keychain as keychain # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase from tests.support.mock import ( MagicMock, @@ -14,10 +15,10 @@ from tests.support.mock import ( call ) -keychain.__salt__ = {} - -class KeychainTestCase(TestCase): +class KeychainTestCase(TestCase, LoaderModuleMockMixin): + def setup_loader_modules(self): + return {keychain: {}} def test_install_cert(self): ''' diff --git a/tests/unit/states/test_mac_package.py b/tests/unit/states/test_mac_package.py index e4f4b27482..e72950cb9e 100644 --- a/tests/unit/states/test_mac_package.py +++ b/tests/unit/states/test_mac_package.py @@ -7,17 +7,17 @@ from __future__ import absolute_import import salt.states.mac_package as macpackage # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase from tests.support.mock import ( MagicMock, patch ) -macpackage.__salt__ = {} -macpackage.__grains__ = {} - -class MacPackageTestCase(TestCase): +class MacPackageTestCase(TestCase, LoaderModuleMockMixin): + def setup_loader_modules(self): + return {macpackage: {}} @patch('salt.states.mac_package._mod_run_check') def test_installed_pkg(self, _mod_run_check_mock): diff --git a/tests/unit/states/test_mac_xattr.py b/tests/unit/states/test_mac_xattr.py index 59f688343c..3581891539 100644 --- a/tests/unit/states/test_mac_xattr.py +++ b/tests/unit/states/test_mac_xattr.py @@ -7,16 +7,18 @@ from __future__ import absolute_import import salt.states.mac_xattr as xattr # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase from tests.support.mock import ( MagicMock, patch ) -xattr.__salt__ = {} +class XAttrTestCase(TestCase, LoaderModuleMockMixin): -class XAttrTestCase(TestCase): + def setup_loader_modules(self): + return {xattr: {}} @patch('os.path.exists') def test_exists_not(self, exists_mock): diff --git a/tests/unit/states/test_makeconf.py b/tests/unit/states/test_makeconf.py index d172f20e9d..69620f8021 100644 --- a/tests/unit/states/test_makeconf.py +++ b/tests/unit/states/test_makeconf.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,14 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.makeconf as makeconf -makeconf.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class MakeconfTestCase(TestCase): +class MakeconfTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.makeconf ''' + def setup_loader_modules(self): + return {makeconf: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_mdadm.py b/tests/unit/states/test_mdadm.py index e587aed312..9095a1926d 100644 --- a/tests/unit/states/test_mdadm.py +++ b/tests/unit/states/test_mdadm.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.mdadm as mdadm -# Globals -mdadm.__salt__ = {} -mdadm.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class MdadmTestCase(TestCase): +class MdadmTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the mdadm state ''' + def setup_loader_modules(self): + return {mdadm: {}} + def test_present(self): ''' Test to verify that the raid is present diff --git a/tests/unit/states/test_memcached.py b/tests/unit/states/test_memcached.py index 34f852a42d..adb4b368cb 100644 --- a/tests/unit/states/test_memcached.py +++ b/tests/unit/states/test_memcached.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -18,15 +19,15 @@ from salt.exceptions import CommandExecutionError # Import Salt Libs import salt.states.memcached as memcached -memcached.__salt__ = {} -memcached.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class MemcachedTestCase(TestCase): +class MemcachedTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.memcached ''' + def setup_loader_modules(self): + return {memcached: {}} + # 'managed' function tests: 1 def test_managed(self): diff --git a/tests/unit/states/test_modjk_worker.py b/tests/unit/states/test_modjk_worker.py index 91a8e5b644..8d64d336e5 100644 --- a/tests/unit/states/test_modjk_worker.py +++ b/tests/unit/states/test_modjk_worker.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,14 +17,14 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.modjk_worker as modjk_worker -modjk_worker.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ModjkWorkerTestCase(TestCase): +class ModjkWorkerTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.modjk_worker ''' + def setup_loader_modules(self): + return {modjk_worker: {}} # 'stop' function tests: 1 def test_stop(self): diff --git a/tests/unit/states/test_mongodb_database.py b/tests/unit/states/test_mongodb_database.py index 5d174d7507..f91406fdec 100644 --- a/tests/unit/states/test_mongodb_database.py +++ b/tests/unit/states/test_mongodb_database.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.mongodb_database as mongodb_database -mongodb_database.__salt__ = {} -mongodb_database.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class MongodbDatabaseTestCase(TestCase): +class MongodbDatabaseTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.mongodb_database ''' + def setup_loader_modules(self): + return {mongodb_database: {}} + # 'absent' function tests: 1 def test_absent(self): diff --git a/tests/unit/states/test_mongodb_user.py b/tests/unit/states/test_mongodb_user.py index 515de40ebe..b569ecbf1e 100644 --- a/tests/unit/states/test_mongodb_user.py +++ b/tests/unit/states/test_mongodb_user.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.mongodb_user as mongodb_user -mongodb_user.__salt__ = {} -mongodb_user.__opts__ = {'test': True} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class MongodbUserTestCase(TestCase): +class MongodbUserTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.mongodb_user ''' + def setup_loader_modules(self): + return {mongodb_user: {'__opts__': {'test': True}}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_mount.py b/tests/unit/states/test_mount.py index 1c05bcdcd6..65173ea698 100644 --- a/tests/unit/states/test_mount.py +++ b/tests/unit/states/test_mount.py @@ -4,8 +4,10 @@ ''' # Import Python libs from __future__ import absolute_import +import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -15,18 +17,16 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.mount as mount -import os - -mount.__salt__ = {} -mount.__opts__ = {} -mount.__grains__ = {} @skipIf(NO_MOCK, NO_MOCK_REASON) -class MountTestCase(TestCase): +class MountTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.mount ''' + def setup_loader_modules(self): + return {mount: {}} + # 'mounted' function tests: 1 def test_mounted(self): diff --git a/tests/unit/states/test_mysql_grants.py b/tests/unit/states/test_mysql_grants.py index 92c7610921..05c1ff4cb5 100644 --- a/tests/unit/states/test_mysql_grants.py +++ b/tests/unit/states/test_mysql_grants.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.mysql_grants as mysql_grants -mysql_grants.__salt__ = {} -mysql_grants.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class MysqlGrantsTestCase(TestCase): +class MysqlGrantsTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.mysql_grants ''' + def setup_loader_modules(self): + return {mysql_grants: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_mysql_query.py b/tests/unit/states/test_mysql_query.py index 495e241181..9e56792bd7 100644 --- a/tests/unit/states/test_mysql_query.py +++ b/tests/unit/states/test_mysql_query.py @@ -4,8 +4,10 @@ ''' # Import Python libs from __future__ import absolute_import +import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -15,17 +17,16 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.mysql_query as mysql_query -import os - -mysql_query.__salt__ = {} -mysql_query.__opts__ = {} @skipIf(NO_MOCK, NO_MOCK_REASON) -class MysqlQueryTestCase(TestCase): +class MysqlQueryTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.mysql_query ''' + def setup_loader_modules(self): + return {mysql_query: {}} + # 'run' function tests: 1 def test_run(self): diff --git a/tests/unit/states/test_mysql_user.py b/tests/unit/states/test_mysql_user.py index 9dd9ae2c1d..862e165c18 100644 --- a/tests/unit/states/test_mysql_user.py +++ b/tests/unit/states/test_mysql_user.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -15,17 +16,17 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.mysql_user as mysql_user -import salt - -mysql_user.__salt__ = {} -mysql_user.__opts__ = {} +import salt.utils @skipIf(NO_MOCK, NO_MOCK_REASON) -class MysqlUserTestCase(TestCase): +class MysqlUserTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.mysql_user ''' + def setup_loader_modules(self): + return {mysql_user: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_network.py b/tests/unit/states/test_network.py index 473be9bcef..44efa8e382 100644 --- a/tests/unit/states/test_network.py +++ b/tests/unit/states/test_network.py @@ -8,6 +8,7 @@ from __future__ import absolute_import import sys # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,11 +20,6 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.network as network -# Globals -network.__salt__ = {} -network.__grains__ = {} -network.__opts__ = {} - class MockNetwork(object): ''' @@ -57,10 +53,13 @@ class MockGrains(object): @skipIf(sys.version_info < (2, 7), 'This needs to be refactored to work with Python 2.6') @skipIf(NO_MOCK, NO_MOCK_REASON) -class NetworkTestCase(TestCase): +class NetworkTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the network state ''' + def setup_loader_modules(self): + return {network: {}} + @patch('salt.states.network.salt.utils.network', MockNetwork()) @patch('salt.states.network.salt.loader', MockGrains()) def test_managed(self): diff --git a/tests/unit/states/test_nftables.py b/tests/unit/states/test_nftables.py index 655c76599e..69a762d78a 100644 --- a/tests/unit/states/test_nftables.py +++ b/tests/unit/states/test_nftables.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.nftables as nftables -# Globals -nftables.__salt__ = {} -nftables.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class NftablesTestCase(TestCase): +class NftablesTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the nftables state ''' + def setup_loader_modules(self): + return {nftables: {}} + def test_chain_present(self): ''' Test to verify the chain is exist. diff --git a/tests/unit/states/test_ntp.py b/tests/unit/states/test_ntp.py index f72b214f77..ebd2fdeded 100644 --- a/tests/unit/states/test_ntp.py +++ b/tests/unit/states/test_ntp.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.ntp as ntp -ntp.__salt__ = {} -ntp.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class NtpTestCase(TestCase): +class NtpTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ntp ''' + def setup_loader_modules(self): + return {ntp: {}} + # 'managed' function tests: 1 def test_managed(self): diff --git a/tests/unit/states/test_openstack_config.py b/tests/unit/states/test_openstack_config.py index 12db61613e..553ce78ebd 100644 --- a/tests/unit/states/test_openstack_config.py +++ b/tests/unit/states/test_openstack_config.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -18,15 +19,15 @@ from salt.exceptions import CommandExecutionError # Import Salt Libs import salt.states.openstack_config as openstack_config -openstack_config.__salt__ = {} -openstack_config.__opts__ = {'test': False} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class OpenstackConfigTestCase(TestCase): +class OpenstackConfigTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.openstack_config ''' + def setup_loader_modules(self): + return {openstack_config: {'__opts__': {'test': False}}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_openvswitch_port.py b/tests/unit/states/test_openvswitch_port.py index 70076b423d..095dcb45eb 100644 --- a/tests/unit/states/test_openvswitch_port.py +++ b/tests/unit/states/test_openvswitch_port.py @@ -3,6 +3,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( MagicMock, @@ -13,15 +14,14 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.openvswitch_port as openvswitch_port -openvswitch_port.__salt__ = {} -openvswitch_port.__opts__ = {'test': False} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class OpenvswitchPortTestCase(TestCase): +class OpenvswitchPortTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.openvswitch_port ''' + def setup_loader_modules(self): + return {openvswitch_port: {'__opts__': {'test': False}}} # 'present' function tests: 1 diff --git a/tests/unit/states/test_pagerduty.py b/tests/unit/states/test_pagerduty.py index 087b464764..bcb5cf6c3d 100644 --- a/tests/unit/states/test_pagerduty.py +++ b/tests/unit/states/test_pagerduty.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.pagerduty as pagerduty -pagerduty.__salt__ = {} -pagerduty.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PagerdutyTestCase(TestCase): +class PagerdutyTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.pagerduty ''' + def setup_loader_modules(self): + return {pagerduty: {}} + # 'create_event' function tests: 1 def test_create_event(self): diff --git a/tests/unit/states/test_pecl.py b/tests/unit/states/test_pecl.py index 029e271023..24ff692ffa 100644 --- a/tests/unit/states/test_pecl.py +++ b/tests/unit/states/test_pecl.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.pecl as pecl -pecl.__salt__ = {} -pecl.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PeclTestCase(TestCase): +class PeclTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.pecl ''' + def setup_loader_modules(self): + return {pecl: {}} + # 'installed' function tests: 1 def test_installed(self): diff --git a/tests/unit/states/test_pkgng.py b/tests/unit/states/test_pkgng.py index 1962d58f68..98f507e6fb 100644 --- a/tests/unit/states/test_pkgng.py +++ b/tests/unit/states/test_pkgng.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,14 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.pkgng as pkgng -pkgng.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PkgngTestCase(TestCase): +class PkgngTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.pkgng ''' + def setup_loader_modules(self): + return {pkgng: {}} + # 'update_packaging_site' function tests: 1 def test_update_packaging_site(self): diff --git a/tests/unit/states/test_portage_config.py b/tests/unit/states/test_portage_config.py index 243077681b..7496733a2d 100644 --- a/tests/unit/states/test_portage_config.py +++ b/tests/unit/states/test_portage_config.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,15 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.portage_config as portage_config -portage_config.__salt__ = {} -portage_config.__opts__ = {'test': True} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PortageConfigTestCase(TestCase): +class PortageConfigTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.portage_config ''' + def setup_loader_modules(self): + return {portage_config: {'__opts__': {'test': True}}} + # 'mod_init' function tests: 1 def test_mod_init(self): diff --git a/tests/unit/states/test_ports.py b/tests/unit/states/test_ports.py index d0b13fb612..cdf51ff450 100644 --- a/tests/unit/states/test_ports.py +++ b/tests/unit/states/test_ports.py @@ -4,8 +4,10 @@ ''' # Import Python libs from __future__ import absolute_import +import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,10 +19,6 @@ from salt.exceptions import SaltInvocationError # Import Salt Libs import salt.states.ports as ports -import os - -ports.__salt__ = {} -ports.__opts__ = {} class MockModule(object): @@ -44,14 +42,15 @@ class MockSys(object): def __init__(self): self.modules = {'A': MockContext()} -ports.sys = MockSys() - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PortsTestCase(TestCase): +class PortsTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ports ''' + def setup_loader_modules(self): + return {ports: {'sys': MockSys()}} + # 'installed' function tests: 1 def test_installed(self): diff --git a/tests/unit/states/test_postgres_cluster.py b/tests/unit/states/test_postgres_cluster.py index 35868d265b..7f30535119 100644 --- a/tests/unit/states/test_postgres_cluster.py +++ b/tests/unit/states/test_postgres_cluster.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.postgres_cluster as postgres_cluster -postgres_cluster.__opts__ = {} -postgres_cluster.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PostgresClusterTestCase(TestCase): +class PostgresClusterTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.postgres_cluster ''' + def setup_loader_modules(self): + return {postgres_cluster: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_postgres_database.py b/tests/unit/states/test_postgres_database.py index 9f05cae58c..f87467c742 100644 --- a/tests/unit/states/test_postgres_database.py +++ b/tests/unit/states/test_postgres_database.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.postgres_database as postgres_database -postgres_database.__opts__ = {} -postgres_database.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PostgresDatabaseTestCase(TestCase): +class PostgresDatabaseTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.postgres_database ''' + def setup_loader_modules(self): + return {postgres_database: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_postgres_extension.py b/tests/unit/states/test_postgres_extension.py index 98337dcce2..5a7f13b6e3 100644 --- a/tests/unit/states/test_postgres_extension.py +++ b/tests/unit/states/test_postgres_extension.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.postgres_extension as postgres_extension -postgres_extension.__opts__ = {} -postgres_extension.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PostgresExtensionTestCase(TestCase): +class PostgresExtensionTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.postgres_extension ''' + def setup_loader_modules(self): + return {postgres_extension: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_postgres_group.py b/tests/unit/states/test_postgres_group.py index 0a1bcea08e..e50183453f 100644 --- a/tests/unit/states/test_postgres_group.py +++ b/tests/unit/states/test_postgres_group.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.postgres_group as postgres_group -postgres_group.__opts__ = {} -postgres_group.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PostgresGroupTestCase(TestCase): +class PostgresGroupTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.postgres_group ''' + def setup_loader_modules(self): + return {postgres_group: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_postgres_schema.py b/tests/unit/states/test_postgres_schema.py index d4a4009eb8..df31d2c547 100644 --- a/tests/unit/states/test_postgres_schema.py +++ b/tests/unit/states/test_postgres_schema.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.postgres_schema as postgres_schema -postgres_schema.__opts__ = {} -postgres_schema.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PostgresSchemaTestCase(TestCase): +class PostgresSchemaTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.postgres_schema ''' + def setup_loader_modules(self): + return {postgres_schema: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_postgres_user.py b/tests/unit/states/test_postgres_user.py index ba68f0bdcc..7497b41dac 100644 --- a/tests/unit/states/test_postgres_user.py +++ b/tests/unit/states/test_postgres_user.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.postgres_user as postgres_user -postgres_user.__opts__ = {} -postgres_user.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PostgresUserTestCase(TestCase): +class PostgresUserTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.postgres_user ''' + def setup_loader_modules(self): + return {postgres_user: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_powerpath.py b/tests/unit/states/test_powerpath.py index b2a76027fc..df3096425f 100644 --- a/tests/unit/states/test_powerpath.py +++ b/tests/unit/states/test_powerpath.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.powerpath as powerpath -powerpath.__opts__ = {} -powerpath.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PowerpathTestCase(TestCase): +class PowerpathTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.powerpath ''' + def setup_loader_modules(self): + return {powerpath: {}} + # 'license_present' function tests: 1 def test_license_present(self): diff --git a/tests/unit/states/test_process.py b/tests/unit/states/test_process.py index f83b07033b..db1adc686b 100644 --- a/tests/unit/states/test_process.py +++ b/tests/unit/states/test_process.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.process as process -process.__opts__ = {} -process.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ProcessTestCase(TestCase): +class ProcessTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.process ''' + def setup_loader_modules(self): + return {process: {}} + # 'absent' function tests: 1 def test_absent(self): diff --git a/tests/unit/states/test_pyenv.py b/tests/unit/states/test_pyenv.py index f1b386c03f..88e3dd48e5 100644 --- a/tests/unit/states/test_pyenv.py +++ b/tests/unit/states/test_pyenv.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.pyenv as pyenv -pyenv.__opts__ = {} -pyenv.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PyenvTestCase(TestCase): +class PyenvTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.pyenv ''' + def setup_loader_modules(self): + return {pyenv: {}} + # 'installed' function tests: 1 def test_installed(self): diff --git a/tests/unit/states/test_pyrax_queues.py b/tests/unit/states/test_pyrax_queues.py index be42fa0408..ceead0ed1d 100644 --- a/tests/unit/states/test_pyrax_queues.py +++ b/tests/unit/states/test_pyrax_queues.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.pyrax_queues as pyrax_queues -pyrax_queues.__opts__ = {} -pyrax_queues.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PyraxQueuesTestCase(TestCase): +class PyraxQueuesTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.pyrax_queues ''' + def setup_loader_modules(self): + return {pyrax_queues: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_quota.py b/tests/unit/states/test_quota.py index 90ab4fb2c0..1030dca425 100644 --- a/tests/unit/states/test_quota.py +++ b/tests/unit/states/test_quota.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.quota as quota -quota.__opts__ = {} -quota.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class QuotaTestCase(TestCase): +class QuotaTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.quota ''' + def setup_loader_modules(self): + return {quota: {}} + # 'mode' function tests: 1 def test_mode(self): diff --git a/tests/unit/states/test_rabbitmq_cluster.py b/tests/unit/states/test_rabbitmq_cluster.py index dfedf8bac6..738ec070cc 100644 --- a/tests/unit/states/test_rabbitmq_cluster.py +++ b/tests/unit/states/test_rabbitmq_cluster.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.rabbitmq_cluster as rabbitmq_cluster -# Globals -rabbitmq_cluster.__salt__ = {} -rabbitmq_cluster.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RabbitmqClusterTestCase(TestCase): +class RabbitmqClusterTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the rabbitmq_cluster state ''' + def setup_loader_modules(self): + return {rabbitmq_cluster: {}} + def test_joined(self): ''' Test to ensure the current node joined diff --git a/tests/unit/states/test_rabbitmq_plugin.py b/tests/unit/states/test_rabbitmq_plugin.py index 820c7e538a..d40d46ec10 100644 --- a/tests/unit/states/test_rabbitmq_plugin.py +++ b/tests/unit/states/test_rabbitmq_plugin.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.rabbitmq_plugin as rabbitmq_plugin -rabbitmq_plugin.__opts__ = {} -rabbitmq_plugin.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RabbitmqPluginTestCase(TestCase): +class RabbitmqPluginTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.rabbitmq_plugin ''' + def setup_loader_modules(self): + return {rabbitmq_plugin: {}} + # 'enabled' function tests: 1 def test_enabled(self): diff --git a/tests/unit/states/test_rabbitmq_policy.py b/tests/unit/states/test_rabbitmq_policy.py index ae25ba1fad..d67de6fadf 100644 --- a/tests/unit/states/test_rabbitmq_policy.py +++ b/tests/unit/states/test_rabbitmq_policy.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.rabbitmq_policy as rabbitmq_policy -rabbitmq_policy.__opts__ = {} -rabbitmq_policy.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RabbitmqPolicyTestCase(TestCase): +class RabbitmqPolicyTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.rabbitmq_policy ''' + def setup_loader_modules(self): + return {rabbitmq_policy: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_rabbitmq_vhost.py b/tests/unit/states/test_rabbitmq_vhost.py index c70d2ebfb1..5ef396409d 100644 --- a/tests/unit/states/test_rabbitmq_vhost.py +++ b/tests/unit/states/test_rabbitmq_vhost.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.rabbitmq_vhost as rabbitmq_vhost -rabbitmq_vhost.__opts__ = {} -rabbitmq_vhost.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RabbitmqVhostTestCase(TestCase): +class RabbitmqVhostTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.rabbitmq_vhost ''' + def setup_loader_modules(self): + return {rabbitmq_vhost: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_rbenv.py b/tests/unit/states/test_rbenv.py index 9a435d1b09..d368a54e52 100644 --- a/tests/unit/states/test_rbenv.py +++ b/tests/unit/states/test_rbenv.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.rbenv as rbenv -rbenv.__opts__ = {} -rbenv.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RbenvTestCase(TestCase): +class RbenvTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.rbenv ''' + def setup_loader_modules(self): + return {rbenv: {}} + # 'installed' function tests: 1 def test_installed(self): diff --git a/tests/unit/states/test_rdp.py b/tests/unit/states/test_rdp.py index 56e16ae942..0d8366f8af 100644 --- a/tests/unit/states/test_rdp.py +++ b/tests/unit/states/test_rdp.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.rdp as rdp -rdp.__opts__ = {} -rdp.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RdpTestCase(TestCase): +class RdpTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.rdp ''' + def setup_loader_modules(self): + return {rdp: {}} + # 'enabled' function tests: 1 def test_enabled(self): diff --git a/tests/unit/states/test_redismod.py b/tests/unit/states/test_redismod.py index 80b73ac4c5..e7da448181 100644 --- a/tests/unit/states/test_redismod.py +++ b/tests/unit/states/test_redismod.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,14 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.redismod as redismod -redismod.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RedismodTestCase(TestCase): +class RedismodTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.redismod ''' + def setup_loader_modules(self): + return {redismod: {}} + # 'string' function tests: 1 def test_string(self): diff --git a/tests/unit/states/test_reg.py b/tests/unit/states/test_reg.py index b8111a84ab..887908be0f 100644 --- a/tests/unit/states/test_reg.py +++ b/tests/unit/states/test_reg.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.reg as reg -reg.__opts__ = {} -reg.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class RegTestCase(TestCase): +class RegTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.reg ''' + def setup_loader_modules(self): + return {reg: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_schedule.py b/tests/unit/states/test_schedule.py index bb8c05a6fb..fdc32ab122 100644 --- a/tests/unit/states/test_schedule.py +++ b/tests/unit/states/test_schedule.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.schedule as schedule -schedule.__opts__ = {} -schedule.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ScheduleTestCase(TestCase): +class ScheduleTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.schedule ''' + def setup_loader_modules(self): + return {schedule: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_selinux.py b/tests/unit/states/test_selinux.py index 1cedb9459e..36474b95c4 100644 --- a/tests/unit/states/test_selinux.py +++ b/tests/unit/states/test_selinux.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.selinux as selinux -selinux.__opts__ = {} -selinux.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class SelinuxTestCase(TestCase): +class SelinuxTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.selinux ''' + def setup_loader_modules(self): + return {selinux: {}} + # 'mode' function tests: 1 def test_mode(self): diff --git a/tests/unit/states/test_serverdensity_device.py b/tests/unit/states/test_serverdensity_device.py index e42551ebdd..17d9f16238 100644 --- a/tests/unit/states/test_serverdensity_device.py +++ b/tests/unit/states/test_serverdensity_device.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,14 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.serverdensity_device as serverdensity_device -serverdensity_device.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ServerdensityDeviceTestCase(TestCase): +class ServerdensityDeviceTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.serverdensity_device ''' + def setup_loader_modules(self): + return {serverdensity_device: {}} + # 'monitored' function tests: 1 def test_monitored(self): diff --git a/tests/unit/states/test_splunk_search.py b/tests/unit/states/test_splunk_search.py index 9a93cbe233..a9d5884aab 100644 --- a/tests/unit/states/test_splunk_search.py +++ b/tests/unit/states/test_splunk_search.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.splunk_search as splunk_search -splunk_search.__salt__ = {} -splunk_search.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class SplunkSearchTestCase(TestCase): +class SplunkSearchTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.splunk_search ''' + def setup_loader_modules(self): + return {splunk_search: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_ssh_auth.py b/tests/unit/states/test_ssh_auth.py index 37787733be..52ba8e1352 100644 --- a/tests/unit/states/test_ssh_auth.py +++ b/tests/unit/states/test_ssh_auth.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -17,15 +18,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.ssh_auth as ssh_auth -ssh_auth.__salt__ = {} -ssh_auth.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class SshAuthTestCase(TestCase): +class SshAuthTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ssh_auth ''' + def setup_loader_modules(self): + return {ssh_auth: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_ssh_known_hosts.py b/tests/unit/states/test_ssh_known_hosts.py index 15a3ef9a6a..88bee8963c 100644 --- a/tests/unit/states/test_ssh_known_hosts.py +++ b/tests/unit/states/test_ssh_known_hosts.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -18,15 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.ssh_known_hosts as ssh_known_hosts -ssh_known_hosts.__salt__ = {} -ssh_known_hosts.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class SshKnownHostsTestCase(TestCase): +class SshKnownHostsTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.ssh_known_hosts ''' + def setup_loader_modules(self): + return {ssh_known_hosts: {}} + # 'present' function tests: 1 def test_present(self): diff --git a/tests/unit/states/test_syslog_ng.py b/tests/unit/states/test_syslog_ng.py index 3fec62dc6e..8a2924779f 100644 --- a/tests/unit/states/test_syslog_ng.py +++ b/tests/unit/states/test_syslog_ng.py @@ -5,11 +5,12 @@ Test module for syslog_ng state # Import python libs from __future__ import absolute_import -import yaml +import os import re import tempfile -import os +import yaml +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch @@ -17,10 +18,6 @@ import salt.utils import salt.states.syslog_ng as syslog_ng import salt.modules.syslog_ng as syslog_ng_module -syslog_ng.__salt__ = {} -syslog_ng_module.__salt__ = {} -syslog_ng_module.__opts__ = {'test': False} - SOURCE_1_CONFIG = { "id": "s_tail", "config": ( @@ -299,8 +296,13 @@ def remove_whitespaces(source): @skipIf(NO_MOCK, NO_MOCK_REASON) -# @skipIf(syslog_ng.__virtual__() is False, 'Syslog-ng must be installed') -class SyslogNGTestCase(TestCase): +class SyslogNGTestCase(TestCase, LoaderModuleMockMixin): + def setup_loader_modules(self): + return { + syslog_ng: {}, + syslog_ng_module: {'__opts__': {'test': False}} + } + def test_generate_source_config(self): self._config_generator_template(SOURCE_1_CONFIG, SOURCE_1_EXPECTED) diff --git a/tests/unit/states/test_vbox_guest.py b/tests/unit/states/test_vbox_guest.py index c9e47e17fa..c9c983313a 100644 --- a/tests/unit/states/test_vbox_guest.py +++ b/tests/unit/states/test_vbox_guest.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.vbox_guest as vbox_guest -# Globals -vbox_guest.__salt__ = {} -vbox_guest.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class VboxGuestTestCase(TestCase): +class VboxGuestTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the vbox_guest state ''' + def setup_loader_modules(self): + return {vbox_guest: {}} + def test_additions_installed(self): ''' Test to ensure that the VirtualBox Guest Additions are installed diff --git a/tests/unit/states/test_virtualenv_mod.py b/tests/unit/states/test_virtualenv_mod.py index 088da07c47..4b7029dbb9 100644 --- a/tests/unit/states/test_virtualenv_mod.py +++ b/tests/unit/states/test_virtualenv_mod.py @@ -8,6 +8,7 @@ from __future__ import absolute_import import os # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,20 +20,18 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.virtualenv_mod as virtualenv_mod -# Globals -virtualenv_mod.__salt__ = {} -virtualenv_mod.__opts__ = {} -virtualenv_mod.__env__ = {} - @patch('salt.states.virtualenv_mod.salt.utils.is_windows', MagicMock(return_value=True)) @patch('salt.states.virtualenv_mod.os.path.join', MagicMock(return_value=True)) @skipIf(NO_MOCK, NO_MOCK_REASON) -class VirtualenvModTestCase(TestCase): +class VirtualenvModTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the virtualenv_mod state ''' + def setup_loader_modules(self): + return {virtualenv_mod: {'__env__': 'base'}} + def test_managed(self): ''' Test to create a virtualenv and optionally manage it with pip diff --git a/tests/unit/states/test_win_dism.py b/tests/unit/states/test_win_dism.py index 9eb2f04814..cfac99a188 100644 --- a/tests/unit/states/test_win_dism.py +++ b/tests/unit/states/test_win_dism.py @@ -7,17 +7,18 @@ from __future__ import absolute_import import salt.states.win_dism as dism # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase from tests.support.mock import ( MagicMock, patch ) -dism.__salt__ = {} -dism.__opts__ = {} +class WinDismTestCase(TestCase, LoaderModuleMockMixin): -class WinDismTestCase(TestCase): + def setup_loader_modules(self): + return {dism: {}} def test_capability_installed(self): ''' diff --git a/tests/unit/states/test_win_dns_client.py b/tests/unit/states/test_win_dns_client.py index d7f82adc78..2ca7bb34d7 100644 --- a/tests/unit/states/test_win_dns_client.py +++ b/tests/unit/states/test_win_dns_client.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.win_dns_client as win_dns_client -# Globals -win_dns_client.__salt__ = {} -win_dns_client.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinDnsClientTestCase(TestCase): +class WinDnsClientTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the win_dns_client state ''' + def setup_loader_modules(self): + return {win_dns_client: {}} + def test_dns_exists(self): ''' Test to configure the DNS server list in the specified interface diff --git a/tests/unit/states/test_win_license.py b/tests/unit/states/test_win_license.py index a52872112a..70b395f78b 100644 --- a/tests/unit/states/test_win_license.py +++ b/tests/unit/states/test_win_license.py @@ -4,19 +4,21 @@ from __future__ import absolute_import # Import Salt Libs -import salt.states.win_license as license +import salt.states.win_license as win_license # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase from tests.support.mock import ( MagicMock, patch ) -license.__salt__ = {} +class LicenseTestCase(TestCase, LoaderModuleMockMixin): -class LicenseTestCase(TestCase): + def setup_loader_modules(self): + return {win_license: {}} def test_activate(self): ''' @@ -39,10 +41,10 @@ class LicenseTestCase(TestCase): info_mock = MagicMock(return_value=info) install_mock = MagicMock(return_value='Installed successfully') activate_mock = MagicMock(return_value='Activated successfully') - with patch.dict(license.__salt__, {'license.info': info_mock, - 'license.install': install_mock, - 'license.activate': activate_mock}): - out = license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') + with patch.dict(win_license.__salt__, {'license.info': info_mock, + 'license.install': install_mock, + 'license.activate': activate_mock}): + out = win_license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') info_mock.assert_called_once_with() install_mock.assert_called_once_with('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') activate_mock.assert_called_once_with() @@ -69,10 +71,10 @@ class LicenseTestCase(TestCase): info_mock = MagicMock(return_value=info) install_mock = MagicMock(return_value='Installed successfully') activate_mock = MagicMock(return_value='Activated successfully') - with patch.dict(license.__salt__, {'license.info': info_mock, - 'license.install': install_mock, - 'license.activate': activate_mock}): - out = license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') + with patch.dict(win_license.__salt__, {'license.info': info_mock, + 'license.install': install_mock, + 'license.activate': activate_mock}): + out = win_license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') info_mock.assert_called_once_with() assert not install_mock.called activate_mock.assert_called_once_with() @@ -99,10 +101,10 @@ class LicenseTestCase(TestCase): info_mock = MagicMock(return_value=info) install_mock = MagicMock(return_value='Installed successfully') activate_mock = MagicMock(return_value='Activated successfully') - with patch.dict(license.__salt__, {'license.info': info_mock, - 'license.install': install_mock, - 'license.activate': activate_mock}): - out = license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') + with patch.dict(win_license.__salt__, {'license.info': info_mock, + 'license.install': install_mock, + 'license.activate': activate_mock}): + out = win_license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') info_mock.assert_called_once_with() assert not install_mock.called assert not activate_mock.called @@ -129,10 +131,10 @@ class LicenseTestCase(TestCase): info_mock = MagicMock(return_value=info) install_mock = MagicMock(return_value='Failed') activate_mock = MagicMock() - with patch.dict(license.__salt__, {'license.info': info_mock, - 'license.install': install_mock, - 'license.activate': activate_mock}): - out = license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') + with patch.dict(win_license.__salt__, {'license.info': info_mock, + 'license.install': install_mock, + 'license.activate': activate_mock}): + out = win_license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') info_mock.assert_called_once_with() install_mock.assert_called_once_with('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') assert not activate_mock.called @@ -159,10 +161,10 @@ class LicenseTestCase(TestCase): info_mock = MagicMock(return_value=info) install_mock = MagicMock() activate_mock = MagicMock(return_value='Failed to activate') - with patch.dict(license.__salt__, {'license.info': info_mock, - 'license.install': install_mock, - 'license.activate': activate_mock}): - out = license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') + with patch.dict(win_license.__salt__, {'license.info': info_mock, + 'license.install': install_mock, + 'license.activate': activate_mock}): + out = win_license.activate('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE') info_mock.assert_called_once_with() assert not install_mock.called activate_mock.assert_called_once_with() diff --git a/tests/unit/states/test_win_network.py b/tests/unit/states/test_win_network.py index 18dbe21086..ebd8912636 100644 --- a/tests/unit/states/test_win_network.py +++ b/tests/unit/states/test_win_network.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.win_network as win_network -# Globals -win_network.__salt__ = {} -win_network.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinNetworkTestCase(TestCase): +class WinNetworkTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the nftables state ''' + def setup_loader_modules(self): + return {win_network: {}} + def test_managed(self): ''' Test to ensure that the named interface is configured properly. diff --git a/tests/unit/states/test_win_path.py b/tests/unit/states/test_win_path.py index ab770d85ff..83faa1bed7 100644 --- a/tests/unit/states/test_win_path.py +++ b/tests/unit/states/test_win_path.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.win_path as win_path -# Globals -win_path.__salt__ = {} -win_path.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinPathTestCase(TestCase): +class WinPathTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the win_path state ''' + def setup_loader_modules(self): + return {win_path: {}} + def test_absent(self): ''' Test to remove the directory from the SYSTEM path diff --git a/tests/unit/states/test_win_pki.py b/tests/unit/states/test_win_pki.py index eeeb60f1ce..13bdc164dd 100644 --- a/tests/unit/states/test_win_pki.py +++ b/tests/unit/states/test_win_pki.py @@ -13,6 +13,7 @@ from __future__ import absolute_import import salt.states.win_pki as win_pki # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -21,10 +22,6 @@ from tests.support.mock import ( NO_MOCK_REASON, ) -# Globals -win_pki.__salt__ = {} -win_pki.__opts__ = {} - CERT_PATH = r'C:\certs\testdomain.local.cer' THUMBPRINT = '9988776655443322111000AAABBBCCCDDDEEEFFF' STORE_PATH = r'Cert:\LocalMachine\My' @@ -41,10 +38,12 @@ CERTS = { @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinPkiTestCase(TestCase): +class WinPkiTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.states.win_pki ''' + def setup_loader_modules(self): + return {win_pki: {}} def test_import_cert(self): ''' diff --git a/tests/unit/states/test_win_powercfg.py b/tests/unit/states/test_win_powercfg.py index ebfd8c8029..1aa50e4386 100644 --- a/tests/unit/states/test_win_powercfg.py +++ b/tests/unit/states/test_win_powercfg.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import salt.states.win_powercfg as powercfg # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -15,14 +16,15 @@ from tests.support.mock import ( patch ) -powercfg.__salt__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class PowerCfgTestCase(TestCase): +class PowerCfgTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the powercfg state ''' + def setup_loader_modules(self): + return {powercfg: {}} + def test_set_monitor(self): ''' Test to make sure we can set the monitor timeout value diff --git a/tests/unit/states/test_win_servermanager.py b/tests/unit/states/test_win_servermanager.py index 654439ad5b..8f55809bcb 100644 --- a/tests/unit/states/test_win_servermanager.py +++ b/tests/unit/states/test_win_servermanager.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.win_servermanager as win_servermanager -# Globals -win_servermanager.__salt__ = {} -win_servermanager.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinServermanagerTestCase(TestCase): +class WinServermanagerTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the win_servermanager state ''' + def setup_loader_modules(self): + return {win_servermanager: {}} + def test_installed(self): ''' Test to install the windows feature diff --git a/tests/unit/states/test_win_snmp.py b/tests/unit/states/test_win_snmp.py index a8a6f1e9e3..c4753f82d9 100644 --- a/tests/unit/states/test_win_snmp.py +++ b/tests/unit/states/test_win_snmp.py @@ -14,6 +14,7 @@ import salt.states.win_snmp as win_snmp import salt.ext.six as six # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -22,16 +23,14 @@ from tests.support.mock import ( NO_MOCK_REASON, ) -# Globals -win_snmp.__salt__ = {} -win_snmp.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinSnmpTestCase(TestCase): +class WinSnmpTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.win_snmp ''' + def setup_loader_modules(self): + return {win_snmp: {}} def test_agent_settings(self): ''' diff --git a/tests/unit/states/test_win_system.py b/tests/unit/states/test_win_system.py index ae4b75ad20..62df23fb8b 100644 --- a/tests/unit/states/test_win_system.py +++ b/tests/unit/states/test_win_system.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.win_system as win_system -# Globals -win_system.__salt__ = {} -win_system.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinSystemTestCase(TestCase): +class WinSystemTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the win_system state ''' + def setup_loader_modules(self): + return {win_system: {}} + def test_computer_desc(self): ''' Test to manage the computer's description field diff --git a/tests/unit/states/test_winrepo.py b/tests/unit/states/test_winrepo.py index 3e740b20b0..83de6585ce 100644 --- a/tests/unit/states/test_winrepo.py +++ b/tests/unit/states/test_winrepo.py @@ -8,8 +8,7 @@ from __future__ import absolute_import import os # Import Salt Testing Libs -import salt.config -from salt.syspaths import BASE_FILE_ROOTS_DIR +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -19,12 +18,10 @@ from tests.support.mock import ( ) # Import Salt Libs +import salt.config +from salt.syspaths import BASE_FILE_ROOTS_DIR import salt.states.winrepo as winrepo -# Globals -winrepo.__salt__ = {} -winrepo.__opts__ = {} - class MockRunnerClient(object): ''' @@ -53,10 +50,13 @@ class MockRunnerClient(object): @patch('salt.states.winrepo.salt.runner', MockRunnerClient) @skipIf(NO_MOCK, NO_MOCK_REASON) -class WinrepoTestCase(TestCase): +class WinrepoTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the winrepo state ''' + def setup_loader_modules(self): + return {winrepo: {}} + def test_genrepo(self): ''' Test to refresh the winrepo.p file of the repository diff --git a/tests/unit/states/test_xmpp.py b/tests/unit/states/test_xmpp.py index 4a02978946..d9c6d6a97c 100644 --- a/tests/unit/states/test_xmpp.py +++ b/tests/unit/states/test_xmpp.py @@ -7,6 +7,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -18,16 +19,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.xmpp as xmpp -# Globals -xmpp.__salt__ = {} -xmpp.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class XmppTestCase(TestCase): +class XmppTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the xmpp state ''' + def setup_loader_modules(self): + return {xmpp: {}} + def test_send_msg(self): ''' Test to send a message to an XMPP user diff --git a/tests/unit/states/test_zk_concurrency.py b/tests/unit/states/test_zk_concurrency.py index ede0f0e3fa..329f2cb189 100644 --- a/tests/unit/states/test_zk_concurrency.py +++ b/tests/unit/states/test_zk_concurrency.py @@ -6,6 +6,7 @@ from __future__ import absolute_import # Import Salt Testing Libs +from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -16,16 +17,15 @@ from tests.support.mock import ( # Import Salt Libs import salt.states.zk_concurrency as zk_concurrency -# Globals -zk_concurrency.__salt__ = {} -zk_concurrency.__opts__ = {} - @skipIf(NO_MOCK, NO_MOCK_REASON) -class ZkConcurrencyTestCase(TestCase): +class ZkConcurrencyTestCase(TestCase, LoaderModuleMockMixin): ''' Validate the zk_concurrency state ''' + def setup_loader_modules(self): + return {zk_concurrency: {}} + def test_lock(self): ''' Test to block state execution until you are able to get the lock