mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Proper mocking.
This commit is contained in:
parent
14db38979c
commit
99bc71dc4e
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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])
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
'''
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
'''
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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.
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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)):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
'''
|
||||
|
@ -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=[])
|
||||
|
@ -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': ''})
|
||||
|
@ -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())
|
||||
|
@ -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):
|
||||
|
@ -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'])
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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'))
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
'''
|
||||
|
@ -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):
|
||||
'''
|
||||
|
@ -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):
|
||||
'''
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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.
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user