mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #45714 from isbm/isbm-oxygen-unicode-S3170
Move to Unicode (3rd tier, tests)
This commit is contained in:
commit
50af1d0641
@ -2,7 +2,7 @@
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
@ -12,6 +12,7 @@ from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||
# Import Salt libs
|
||||
import salt.states.jboss7 as jboss7
|
||||
from salt.exceptions import CommandExecutionError
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@ -55,10 +56,12 @@ class JBoss7StateTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'jboss7.update_datasource': update_mock}):
|
||||
|
||||
# when
|
||||
result = jboss7.datasource_exists(name='appDS', jboss_config={}, datasource_properties=datasource_properties, profile=None)
|
||||
result = jboss7.datasource_exists(name='appDS', jboss_config={},
|
||||
datasource_properties=datasource_properties, profile=None)
|
||||
|
||||
# then
|
||||
create_mock.assert_called_with(name='appDS', jboss_config={}, datasource_properties=datasource_properties, profile=None)
|
||||
create_mock.assert_called_with(name='appDS', jboss_config={},
|
||||
datasource_properties=datasource_properties, profile=None)
|
||||
|
||||
self.assertFalse(update_mock.called)
|
||||
self.assertEqual(result['comment'], 'Datasource created.')
|
||||
@ -82,9 +85,13 @@ class JBoss7StateTestCase(TestCase, LoaderModuleMockMixin):
|
||||
with patch.dict(jboss7.__salt__, {'jboss7.read_datasource': read_mock,
|
||||
'jboss7.create_datasource': create_mock,
|
||||
'jboss7.update_datasource': update_mock}):
|
||||
result = jboss7.datasource_exists(name='appDS', jboss_config={}, datasource_properties={'connection-url': 'jdbc:/new-connection-url'}, profile=None)
|
||||
result = jboss7.datasource_exists(name='appDS', jboss_config={},
|
||||
datasource_properties={'connection-url': 'jdbc:/new-connection-url'},
|
||||
profile=None)
|
||||
|
||||
update_mock.assert_called_with(name='appDS', jboss_config={}, new_properties={'connection-url': 'jdbc:/new-connection-url'}, profile=None)
|
||||
update_mock.assert_called_with(name='appDS', jboss_config={},
|
||||
new_properties={'connection-url': 'jdbc:/new-connection-url'},
|
||||
profile=None)
|
||||
self.assertTrue(read_mock.called)
|
||||
self.assertEqual(result['comment'], 'Datasource updated.')
|
||||
|
||||
@ -99,10 +106,14 @@ class JBoss7StateTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'jboss7.remove_datasource': remove_mock,
|
||||
'jboss7.update_datasource': update_mock}):
|
||||
|
||||
result = jboss7.datasource_exists(name='appDS', jboss_config={}, datasource_properties={'connection-url': 'jdbc:/same-connection-url'}, recreate=True)
|
||||
result = jboss7.datasource_exists(name='appDS', jboss_config={},
|
||||
datasource_properties={'connection-url': 'jdbc:/same-connection-url'},
|
||||
recreate=True)
|
||||
|
||||
remove_mock.assert_called_with(name='appDS', jboss_config={}, profile=None)
|
||||
create_mock.assert_called_with(name='appDS', jboss_config={}, datasource_properties={'connection-url': 'jdbc:/same-connection-url'}, profile=None)
|
||||
create_mock.assert_called_with(name='appDS', jboss_config={},
|
||||
datasource_properties={'connection-url': 'jdbc:/same-connection-url'},
|
||||
profile=None)
|
||||
self.assertEqual(result['changes']['removed'], 'appDS')
|
||||
self.assertEqual(result['changes']['created'], 'appDS')
|
||||
|
||||
@ -118,9 +129,11 @@ class JBoss7StateTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'jboss7.remove_datasource': remove_mock,
|
||||
'jboss7.update_datasource': update_mock}):
|
||||
|
||||
result = jboss7.datasource_exists(name='appDS', jboss_config={}, datasource_properties={'connection-url': 'jdbc:/old-connection-url'})
|
||||
result = jboss7.datasource_exists(name='appDS', jboss_config={},
|
||||
datasource_properties={'connection-url': 'jdbc:/old-connection-url'})
|
||||
|
||||
update_mock.assert_called_with(name='appDS', jboss_config={}, new_properties={'connection-url': 'jdbc:/old-connection-url'}, profile=None)
|
||||
update_mock.assert_called_with(name='appDS', jboss_config={},
|
||||
new_properties={'connection-url': 'jdbc:/old-connection-url'}, profile=None)
|
||||
self.assertFalse(create_mock.called)
|
||||
self.assertEqual(result['comment'], 'Datasource not changed.')
|
||||
|
||||
@ -222,7 +235,7 @@ class JBoss7StateTestCase(TestCase, LoaderModuleMockMixin):
|
||||
jboss7.bindings_exist(name='bindings', jboss_config={}, bindings={'env': 'DEV2'}, profile=None)
|
||||
self.fail('An exception should be thrown')
|
||||
except CommandExecutionError as e:
|
||||
self.assertEqual(str(e), 'Incorrect binding name.')
|
||||
self.assertEqual(six.text_type(e), 'Incorrect binding name.')
|
||||
|
||||
def test_should_raise_exception_if_cannot_update_binding(self):
|
||||
def read_func(jboss_config, binding_name, profile):
|
||||
@ -241,7 +254,9 @@ class JBoss7StateTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
# when
|
||||
try:
|
||||
jboss7.bindings_exist(name='bindings', jboss_config={}, bindings={'env': '!@#!///some weird value'}, profile=None)
|
||||
jboss7.bindings_exist(name='bindings', jboss_config={},
|
||||
bindings={'env': '!@#!///some weird value'},
|
||||
profile=None)
|
||||
self.fail('An exception should be thrown')
|
||||
except CommandExecutionError as e:
|
||||
self.assertEqual(str(e), 'Incorrect binding name.')
|
||||
self.assertEqual(six.text_type(e), 'Incorrect binding name.')
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -9,7 +9,7 @@ I'm leaving it for now, but this should really be gutted and replaced
|
||||
with something sensible.
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import copy
|
||||
from salt.ext import six
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
import sys
|
||||
|
||||
# Import Salt Testing Libs
|
||||
@ -169,17 +169,14 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'comment': '',
|
||||
'changes': {}}
|
||||
|
||||
mock = MagicMock(side_effect=[{name: {acl_type: [{acl_name:
|
||||
{'octal': 'A'}}]}},
|
||||
mock = MagicMock(side_effect=[{name: {acl_type: [{acl_name: {'octal': 'A'}}]}},
|
||||
{name: {acl_type: ''}}])
|
||||
with patch.dict(linux_acl.__salt__, {'acl.getfacl': mock}):
|
||||
with patch.dict(linux_acl.__opts__, {'test': True}):
|
||||
comt = ('Removing permissions')
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(linux_acl.absent(name, acl_type, acl_name,
|
||||
perms), ret)
|
||||
self.assertDictEqual(linux_acl.absent(name, acl_type, acl_name, perms), ret)
|
||||
|
||||
comt = ('ACL Type does not exist')
|
||||
ret.update({'comment': comt, 'result': False})
|
||||
self.assertDictEqual(linux_acl.absent(name, acl_type, acl_name,
|
||||
perms), ret)
|
||||
self.assertDictEqual(linux_acl.absent(name, acl_type, acl_name, perms), ret)
|
||||
|
@ -4,7 +4,7 @@
|
||||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
@ -64,7 +64,7 @@ class LxcTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertDictEqual(lxc.present(name, running=True,
|
||||
clone_from=True), ret)
|
||||
|
||||
comt = ('Container \'{0}\' would be stopped'.format(name))
|
||||
comt = ("Container '{0}' would be stopped".format(name))
|
||||
ret.update({'comment': comt, 'result': None})
|
||||
self.assertDictEqual(lxc.present(name, running=False,
|
||||
clone_from=True), ret)
|
||||
@ -96,17 +96,17 @@ class LxcTestCase(TestCase, LoaderModuleMockMixin):
|
||||
mock_des = MagicMock(return_value={'state': True})
|
||||
with patch.dict(lxc.__salt__, {'lxc.exists': mock,
|
||||
'lxc.destroy': mock_des}):
|
||||
comt = ('Container \'{0}\' does not exist'.format(name))
|
||||
comt = ("Container '{0}' does not exist".format(name))
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(lxc.absent(name), ret)
|
||||
|
||||
with patch.dict(lxc.__opts__, {'test': True}):
|
||||
comt = ('Container \'{0}\' would be destroyed'.format(name))
|
||||
comt = ("Container '{0}' would be destroyed".format(name))
|
||||
ret.update({'comment': comt, 'result': None})
|
||||
self.assertDictEqual(lxc.absent(name), ret)
|
||||
|
||||
with patch.dict(lxc.__opts__, {'test': False}):
|
||||
comt = ('Container \'{0}\' was destroyed'.format(name))
|
||||
comt = ("Container '{0}' was destroyed".format(name))
|
||||
ret.update({'comment': comt, 'result': True,
|
||||
'changes': {'state': True}})
|
||||
self.assertDictEqual(lxc.absent(name), ret)
|
||||
@ -129,7 +129,7 @@ class LxcTestCase(TestCase, LoaderModuleMockMixin):
|
||||
with patch.dict(lxc.__salt__, {'lxc.exists': mock,
|
||||
'lxc.state': mock_t,
|
||||
'lxc.start': mock}):
|
||||
comt = ('Container \'{0}\' does not exist'.format(name))
|
||||
comt = ("Container '{0}' does not exist".format(name))
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(lxc.running(name), ret)
|
||||
|
||||
@ -165,7 +165,7 @@ class LxcTestCase(TestCase, LoaderModuleMockMixin):
|
||||
mock_t = MagicMock(side_effect=['frozen', 'stopped', 'stopped'])
|
||||
with patch.dict(lxc.__salt__, {'lxc.freeze': mock,
|
||||
'lxc.state': mock_t}):
|
||||
comt = ('Container \'{0}\' is already frozen'.format(name))
|
||||
comt = ("Container '{0}' is already frozen".format(name))
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(lxc.frozen(name), ret)
|
||||
|
||||
@ -197,11 +197,11 @@ class LxcTestCase(TestCase, LoaderModuleMockMixin):
|
||||
mock_t = MagicMock(side_effect=[None, 'stopped', 'frozen', 'frozen'])
|
||||
with patch.dict(lxc.__salt__, {'lxc.stop': mock,
|
||||
'lxc.state': mock_t}):
|
||||
comt = ('Container \'{0}\' does not exist'.format(name))
|
||||
comt = ("Container '{0}' does not exist".format(name))
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(lxc.stopped(name), ret)
|
||||
|
||||
comt = ('Container \'{0}\' is already stopped'.format(name))
|
||||
comt = ("Container '{0}' is already stopped".format(name))
|
||||
ret.update({'comment': comt, 'result': True})
|
||||
self.assertDictEqual(lxc.stopped(name), ret)
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
@ -41,7 +41,7 @@ class ModjkWorkerTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'comment': '',
|
||||
'changes': {}}
|
||||
|
||||
comt = ('no servers answered the published command modjk.worker_status')
|
||||
comt = 'no servers answered the published command modjk.worker_status'
|
||||
mock = MagicMock(return_value=False)
|
||||
with patch.dict(modjk_worker.__salt__, {'publish.publish': mock}):
|
||||
ret.update({'comment': comt})
|
||||
@ -63,7 +63,7 @@ class ModjkWorkerTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'comment': '',
|
||||
'changes': {}}
|
||||
|
||||
comt = ('no servers answered the published command modjk.worker_status')
|
||||
comt = 'no servers answered the published command modjk.worker_status'
|
||||
mock = MagicMock(return_value=False)
|
||||
with patch.dict(modjk_worker.__salt__, {'publish.publish': mock}):
|
||||
ret.update({'comment': comt})
|
||||
@ -85,7 +85,7 @@ class ModjkWorkerTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'comment': '',
|
||||
'changes': {}}
|
||||
|
||||
comt = ('no servers answered the published command modjk.worker_status')
|
||||
comt = 'no servers answered the published command modjk.worker_status'
|
||||
mock = MagicMock(return_value=False)
|
||||
with patch.dict(modjk_worker.__salt__, {'publish.publish': mock}):
|
||||
ret.update({'comment': comt})
|
||||
|
@ -4,7 +4,7 @@
|
||||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
from inspect import ArgSpec
|
||||
import logging
|
||||
|
||||
@ -94,8 +94,7 @@ class ModuleStateTest(TestCase, LoaderModuleMockMixin):
|
||||
with patch.dict(module.__salt__, {}, clear=True):
|
||||
with patch.dict(module.__opts__, {'use_superseded': ['module.run']}):
|
||||
ret = module.run(**{CMD: None})
|
||||
if ret['comment'] != "Unavailable function: {0}.".format(CMD) \
|
||||
or ret['result']:
|
||||
if ret['comment'] != "Unavailable function: {0}.".format(CMD) or ret['result']:
|
||||
self.fail('module.run did not fail as expected: {0}'.format(ret))
|
||||
|
||||
def test_module_run_hidden_varargs(self):
|
||||
@ -115,8 +114,7 @@ class ModuleStateTest(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
with patch.dict(module.__opts__, {'test': True, 'use_superseded': ['module.run']}):
|
||||
ret = module.run(**{CMD: None})
|
||||
if ret['comment'] != "Function {0} to be executed.".format(CMD) \
|
||||
or not ret['result']:
|
||||
if ret['comment'] != "Function {0} to be executed.".format(CMD) or not ret['result']:
|
||||
self.fail('module.run failed: {0}'.format(ret))
|
||||
|
||||
def test_run_missing_arg(self):
|
||||
@ -127,8 +125,7 @@ class ModuleStateTest(TestCase, LoaderModuleMockMixin):
|
||||
with patch.dict(module.__salt__, {CMD: _mocked_func_named}):
|
||||
with patch.dict(module.__opts__, {'use_superseded': ['module.run']}):
|
||||
ret = module.run(**{CMD: None})
|
||||
expected_comment = \
|
||||
"'{0}' failed: Function expects 1 parameters, got only 0".format(CMD)
|
||||
expected_comment = "'{0}' failed: Function expects 1 parameters, got only 0".format(CMD)
|
||||
if ret['comment'] != expected_comment:
|
||||
self.fail('module.run did not fail as expected: {0}'.format(ret))
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
|
||||
# Import Salt Testing Libs
|
||||
@ -176,8 +176,7 @@ class MountTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'group.info': mock_group}):
|
||||
with patch.dict(mount.__opts__, {'test': True}):
|
||||
with patch.object(os.path, 'exists', mock_t):
|
||||
comt = 'Target was already mounted. ' + \
|
||||
'Entry already exists in the fstab.'
|
||||
comt = 'Target was already mounted. Entry already exists in the fstab.'
|
||||
ret.update({'name': name2, 'result': True})
|
||||
ret.update({'comment': comt, 'changes': {}})
|
||||
self.assertDictEqual(mount.mounted(name2, device2,
|
||||
@ -299,9 +298,7 @@ class MountTestCase(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
ret = {'name': name,
|
||||
'result': True,
|
||||
'comment': '',
|
||||
'comment': 'Watch not supported in unmount at this time',
|
||||
'changes': {}}
|
||||
|
||||
comt = ('Watch not supported in unmount at this time')
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(mount.mod_watch(name, sfun='unmount'), ret)
|
||||
|
@ -3,7 +3,7 @@
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
Loading…
Reference in New Issue
Block a user