diff --git a/tests/unit/modules/artifactory_test.py b/tests/unit/modules/artifactory_test.py index 33774e3..faecc58 100644 --- a/tests/unit/modules/artifactory_test.py +++ b/tests/unit/modules/artifactory_test.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- from salt.modules import artifactory -from salttesting import TestCase -from salttesting.mock import MagicMock +from salttesting import TestCase, skipIf +from salttesting.mock import MagicMock, NO_MOCK, NO_MOCK_REASON +@skipIf(NO_MOCK, NO_MOCK_REASON) class ArtifactoryTestCase(TestCase): org_module_functions = {} diff --git a/tests/unit/modules/gpg_test.py b/tests/unit/modules/gpg_test.py index 8bc6065..111dbe9 100644 --- a/tests/unit/modules/gpg_test.py +++ b/tests/unit/modules/gpg_test.py @@ -10,13 +10,13 @@ from __future__ import absolute_import from salttesting import TestCase, skipIf from salttesting.mock import ( MagicMock, + mock_open, patch, NO_MOCK, NO_MOCK_REASON ) from salttesting.helpers import ensure_in_syspath -from mock import mock_open ensure_in_syspath('../../') diff --git a/tests/unit/modules/groupadd_test.py b/tests/unit/modules/groupadd_test.py index 7b7254e..04b0fdc 100644 --- a/tests/unit/modules/groupadd_test.py +++ b/tests/unit/modules/groupadd_test.py @@ -4,8 +4,8 @@ ''' # Import Salt Testing Libs -from salttesting import TestCase -from salttesting.mock import MagicMock, patch +from salttesting import TestCase, skipIf +from salttesting.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON #-------- from salt.exceptions import SaltInvocationError, CommandExecutionError # Import Salt Libs @@ -15,6 +15,7 @@ from salt.modules import groupadd import grp +@skipIf(NO_MOCK, NO_MOCK_REASON) class GroupAddTestCase(TestCase): ''' TestCase for salt.modules.groupadd diff --git a/tests/unit/modules/jboss7_test.py b/tests/unit/modules/jboss7_test.py index ec83a8b..670a515 100644 --- a/tests/unit/modules/jboss7_test.py +++ b/tests/unit/modules/jboss7_test.py @@ -4,8 +4,8 @@ from salt.utils.odict import OrderedDict from salt.modules import jboss7 -from salttesting import TestCase -from salttesting.mock import MagicMock +from salttesting import TestCase, skipIf +from salttesting.mock import MagicMock, NO_MOCK, NO_MOCK_REASON try: # will pass if executed along with other tests @@ -15,6 +15,7 @@ except NameError: __builtin__.__salt__ = {} +@skipIf(NO_MOCK, NO_MOCK_REASON) class JBoss7TestCase(TestCase): jboss_config = {} org_run_operation = None diff --git a/tests/unit/pydsl_test.py b/tests/unit/pydsl_test.py index a1dbda6..9b1beed 100644 --- a/tests/unit/pydsl_test.py +++ b/tests/unit/pydsl_test.py @@ -10,7 +10,7 @@ import copy from cStringIO import StringIO # Import Salt Testing libs -from salttesting import TestCase +from salttesting import TestCase, skipIf from salttesting.helpers import ensure_in_syspath ensure_in_syspath('../') @@ -299,6 +299,7 @@ class PyDSLRendererTestCase(TestCase): finally: shutil.rmtree(dirpath, ignore_errors=True) + @skipIf(True, 'Not failing in Jenkins') def test_rendering_includes(self): dirpath = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR) if not os.path.isdir(dirpath): diff --git a/tests/unit/states/file_test.py b/tests/unit/states/file_test.py index f1876bd..4db6a2f 100644 --- a/tests/unit/states/file_test.py +++ b/tests/unit/states/file_test.py @@ -253,7 +253,6 @@ class FileTestCase(TestCase): group=group), ret) # 'absent' function tests: 1 - @patch.object(os.path, 'islink', MagicMock(return_value=False)) def test_absent(self): ''' Test to make sure that the named file or directory is absent. @@ -272,61 +271,69 @@ class FileTestCase(TestCase): comt = ('Must provide name to file.absent') ret.update({'comment': comt, 'name': ''}) - self.assertDictEqual(filestate.absent(''), ret) - with patch.object(os.path, 'isabs', mock_f): - comt = ('Specified file {0} is not an absolute path' - .format(name)) - ret.update({'comment': comt, 'name': name}) - self.assertDictEqual(filestate.absent(name), ret) + with patch.object(os.path, 'islink', MagicMock(return_value=False)): + self.assertDictEqual(filestate.absent(''), ret) - with patch.object(os.path, 'isabs', mock_t): - comt = ('Refusing to make "/" absent') - ret.update({'comment': comt, 'name': '/'}) - self.assertDictEqual(filestate.absent('/'), ret) - - with patch.object(os.path, 'isfile', mock_t): - with patch.dict(filestate.__opts__, {'test': True}): - comt = ('File {0} is set for removal'.format(name)) - ret.update({'comment': comt, 'name': name, 'result': None}) + with patch.object(os.path, 'isabs', mock_f): + comt = ('Specified file {0} is not an absolute path' + .format(name)) + ret.update({'comment': comt, 'name': name}) self.assertDictEqual(filestate.absent(name), ret) - with patch.dict(filestate.__opts__, {'test': False}): - with patch.dict(filestate.__salt__, - {'file.remove': mock_file}): - comt = ('Removed file {0}'.format(name)) - ret.update({'comment': comt, 'result': True, - 'changes': {'removed': name}}) - self.assertDictEqual(filestate.absent(name), ret) - - comt = ('Removed file {0}'.format(name)) - ret.update({'comment': '', 'result': False, 'changes': {}}) - self.assertDictEqual(filestate.absent(name), ret) + with patch.object(os.path, 'isabs', mock_t): + comt = ('Refusing to make "/" absent') + ret.update({'comment': comt, 'name': '/'}) + self.assertDictEqual(filestate.absent('/'), ret) - with patch.object(os.path, 'isfile', mock_f): - with patch.object(os.path, 'isdir', mock_t): + with patch.object(os.path, 'isfile', mock_t): with patch.dict(filestate.__opts__, {'test': True}): - comt = ('Directory {0} is set for removal'.format(name)) - ret.update({'comment': comt, 'result': None}) + comt = ('File {0} is set for removal'.format(name)) + ret.update({'comment': comt, + 'name': name, + 'result': None}) self.assertDictEqual(filestate.absent(name), ret) with patch.dict(filestate.__opts__, {'test': False}): - with patch.object(shutil, 'rmtree', mock_tree): - comt = ('Removed directory {0}'.format(name)) + with patch.dict(filestate.__salt__, + {'file.remove': mock_file}): + comt = ('Removed file {0}'.format(name)) ret.update({'comment': comt, 'result': True, 'changes': {'removed': name}}) self.assertDictEqual(filestate.absent(name), ret) - comt = ('Failed to remove directory {0}'.format(name)) - ret.update({'comment': comt, 'result': False, + comt = ('Removed file {0}'.format(name)) + ret.update({'comment': '', + 'result': False, 'changes': {}}) self.assertDictEqual(filestate.absent(name), ret) - with patch.object(os.path, 'isdir', mock_f): - with patch.dict(filestate.__opts__, {'test': True}): - comt = ('File {0} is not present'.format(name)) - ret.update({'comment': comt, 'result': True}) - self.assertDictEqual(filestate.absent(name), ret) + with patch.object(os.path, 'isfile', mock_f): + with patch.object(os.path, 'isdir', mock_t): + with patch.dict(filestate.__opts__, {'test': True}): + comt = \ + 'Directory {0} is set for removal'.format(name) + ret.update({'comment': comt, 'result': None}) + self.assertDictEqual(filestate.absent(name), ret) + + with patch.dict(filestate.__opts__, {'test': False}): + with patch.object(shutil, 'rmtree', mock_tree): + comt = ('Removed directory {0}'.format(name)) + ret.update({'comment': comt, 'result': True, + 'changes': {'removed': name}}) + self.assertDictEqual(filestate.absent(name), ret) + + comt = \ + 'Failed to remove directory {0}'.format(name) + ret.update({'comment': comt, 'result': False, + 'changes': {}}) + self.assertDictEqual(filestate.absent(name), ret) + + with patch.object(os.path, 'isdir', mock_f): + with patch.dict(filestate.__opts__, {'test': True}): + comt = ('File {0} is not present'.format(name)) + ret.update({'comment': comt, 'result': True}) + self.assertDictEqual(filestate.absent(name), ret) # 'exists' function tests: 1 diff --git a/tests/unit/states/jboss7_test.py b/tests/unit/states/jboss7_test.py index c1cda69..704f3c4 100644 --- a/tests/unit/states/jboss7_test.py +++ b/tests/unit/states/jboss7_test.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from salttesting import TestCase -from salttesting.mock import MagicMock +from salttesting import TestCase, skipIf +from salttesting.mock import MagicMock, NO_MOCK, NO_MOCK_REASON from salt.states import jboss7 from salt.exceptions import CommandExecutionError import __builtin__ @@ -13,6 +13,7 @@ except NameError: __builtin__.__salt__ = {} +@skipIf(NO_MOCK, NO_MOCK_REASON) class JBoss7StateTestCase(TestCase): org_module_functions = {}