desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Test create a new logical volume, with option
for which physical volume to be used'
| def test_lvcreate(self):
| self.assertEqual(linux_lvm.lvcreate(None, None, 1, 1), 'Error: Please specify only one of size or extents')
self.assertEqual(linux_lvm.lvcreate(None, None, None, None), 'Error: Either size or extents must be specified')
self.assertEqual(linux_lvm.lvcreate(None, None, thinvolume=True, thinpool=True), 'Error: Please set only one of thinvolume or thinpool to True')
self.assertEqual(linux_lvm.lvcreate(None, None, thinvolume=True, extents=1), 'Error: Thin volume size cannot be specified as extents')
mock = MagicMock(return_value='A\nB')
with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
with patch.object(linux_lvm, 'lvdisplay', return_value={}):
self.assertDictEqual(linux_lvm.lvcreate(None, None, None, 1), {'Output from lvcreate': 'A'})
|
'Test create a new logical volume, with option
for which physical volume to be used'
| def test_lvcreate_with_force(self):
| mock = MagicMock(return_value='A\nB')
with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
with patch.object(linux_lvm, 'lvdisplay', return_value={}):
self.assertDictEqual(linux_lvm.lvcreate(None, None, None, 1, force=True), {'Output from lvcreate': 'A'})
|
'Tests to remove an LVM volume group'
| def test_vgremove(self):
| mock = MagicMock(return_value='A')
with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
self.assertEqual(linux_lvm.vgremove('A'), 'A')
|
'Test to remove a given existing logical volume
from a named existing volume group'
| def test_lvremove(self):
| mock = MagicMock(return_value='A')
with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
self.assertEqual(linux_lvm.lvremove('', ''), 'A')
|
'Test to return information about the logical volume(s)'
| def test_lvresize(self):
| mock = MagicMock(return_value={'retcode': 1})
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(linux_lvm.lvresize(1, 'a'), {})
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(linux_lvm.lvresize(1, 'a'), {})
|
'Test if _render_filenames fails upon getting a template not in
TEMPLATE_REGISTRY.'
| def test__render_filenames_undefined_template(self):
| path = '/srv/salt/saltines'
dest = '/srv/salt/cheese'
saltenv = 'base'
template = 'biscuits'
ret = (path, dest)
self.assertRaises(CommandExecutionError, cp._render_filenames, path, dest, saltenv, template)
|
'Test if _render_filenames fails when template rendering fails.'
| def test__render_filenames_render_failed(self):
| path = 'salt://saltines'
dest = '/srv/salt/cheese'
saltenv = 'base'
template = 'jinja'
file_data = 'Remember to keep your files well salted.'
mock_jinja = (lambda *args, **kwargs: {'result': False, 'data': file_data})
with patch.dict(templates.TEMPLATE_REGISTRY, {'jinja': mock_jinja}):
with patch('salt.utils.files.fopen', mock_open(read_data=file_data)):
self.assertRaises(CommandExecutionError, cp._render_filenames, path, dest, saltenv, template)
|
'Test if _render_filenames succeeds.'
| def test__render_filenames_success(self):
| path = 'salt://saltines'
dest = '/srv/salt/cheese'
saltenv = 'base'
template = 'jinja'
file_data = '/srv/salt/biscuits'
mock_jinja = (lambda *args, **kwargs: {'result': True, 'data': file_data})
ret = (file_data, file_data)
with patch.dict(templates.TEMPLATE_REGISTRY, {'jinja': mock_jinja}):
with patch('salt.utils.files.fopen', mock_open(read_data=file_data)):
self.assertEqual(cp._render_filenames(path, dest, saltenv, template), ret)
|
'Test if get_file can\'t find the file.'
| def test_get_file_not_found(self):
| with patch('salt.modules.cp.hash_file', MagicMock(return_value=False)):
path = 'salt://saltines'
dest = '/srv/salt/cheese'
ret = ''
self.assertEqual(cp.get_file(path, dest), ret)
|
'Test if get_file_str succeeds.'
| def test_get_file_str_success(self):
| path = 'salt://saltines'
dest = '/srv/salt/cheese/saltines'
file_data = 'Remember to keep your files well salted.'
saltenv = 'base'
ret = file_data
with patch('salt.utils.files.fopen', mock_open(read_data=file_data)):
with patch('salt.modules.cp.cache_file', MagicMock(return_value=dest)):
self.assertEqual(cp.get_file_str(path, dest), ret)
|
'Test if push fails on a non absolute path.'
| def test_push_non_absolute_path(self):
| path = '../saltines'
ret = False
self.assertEqual(cp.push(path), ret)
|
'Test if push_dir fails on a non absolute path.'
| def test_push_dir_non_absolute_path(self):
| path = '../saltines'
ret = False
self.assertEqual(cp.push_dir(path), ret)
|
'Test if push works with good posix path.'
| def test_push(self):
| with patch('salt.modules.cp.os.path', MagicMock(isfile=Mock(return_value=True), wraps=cp.os.path)):
with patch.multiple('salt.modules.cp', _auth=MagicMock(**{'return_value.gen_token.return_value': 'token'}), __opts__={'id': 'abc', 'file_buffer_size': 10}):
with patch('salt.utils.files.fopen', mock_open(read_data='content')):
with patch('salt.transport.Channel.factory', MagicMock()):
response = cp.push('/saltines/test.file')
self.assertEqual(response, True)
self.assertEqual(salt.utils.files.fopen().read.call_count, 2)
salt.transport.Channel.factory({}).send.assert_called_once_with(dict(loc=salt.utils.files.fopen().tell(), cmd='_file_recv', tok='token', path=['saltines', 'test.file'], data='', id='abc'))
|
'Test if it add the specified group'
| def test_add(self):
| self.assertDictEqual(win_groupadd.add('foo'), {'changes': [], 'name': 'foo', 'result': None, 'comment': 'The group foo already exists.'})
|
'Test if it remove the specified group'
| def test_delete(self):
| self.assertDictEqual(win_groupadd.delete('foo'), {'changes': [], 'name': 'foo', 'result': None, 'comment': 'The group foo does not exists.'})
|
'Test if it return information about a group.'
| def test_info(self):
| with patch(win_groupadd.win32.client, 'flag', None):
self.assertDictEqual(win_groupadd.info('dc=salt'), {'gid': None, 'members': ['dc=\\user1'], 'passwd': None, 'name': 'WinNT://./dc=salt,group'})
with patch(win_groupadd.win32.client, 'flag', 1):
self.assertFalse(win_groupadd.info('dc=salt'))
with patch(win_groupadd.win32.client, 'flag', 2):
self.assertFalse(win_groupadd.info('dc=salt'))
|
'Test if it return info on all groups'
| def test_getent(self):
| with patch.dict(win_groupadd.__context__, {'group.getent': True}):
self.assertTrue(win_groupadd.getent())
|
'Test if it add a user to a group'
| def test_adduser(self):
| with patch(win_groupadd.win32.client, 'flag', None):
self.assertDictEqual(win_groupadd.adduser('dc=foo', 'dc=\\username'), {'changes': {'Users Added': ['dc=\\username']}, 'comment': '', 'name': 'dc=foo', 'result': True})
with patch(win_groupadd.win32.client, 'flag', 1):
comt = 'Failed to add dc=\\username to group dc=foo. C'
self.assertDictEqual(win_groupadd.adduser('dc=foo', 'dc=\\username'), {'changes': {'Users Added': []}, 'name': 'dc=foo', 'comment': comt, 'result': False})
|
'Test if it remove a user to a group'
| def test_deluser(self):
| ret = {'changes': {'Users Removed': []}, 'comment': 'User dc=\\username is not a member of dc=foo', 'name': 'dc=foo', 'result': None}
self.assertDictEqual(win_groupadd.deluser('dc=foo', 'dc=\\username'), ret)
|
'Test if it remove a user to a group'
| def test_members(self):
| comment = ['Failure accessing group dc=foo. C']
ret = {'name': 'dc=foo', 'result': False, 'comment': comment, 'changes': {'Users Added': [], 'Users Removed': []}}
with patch(win_groupadd.win32.client, 'flag', 2):
self.assertDictEqual(win_groupadd.members('dc=foo', 'dc=\\user1,dc=\\user2,dc=\\user3'), ret)
with patch(win_groupadd.win32.client, 'flag', 1):
comment = ['Failed to add dc=\\user2 to dc=foo. C', 'Failed to remove dc=\\user1 from dc=foo. C']
ret.update({'comment': comment, 'result': False})
self.assertDictEqual(win_groupadd.members('dc=foo', 'dc=\\user2'), ret)
with patch(win_groupadd.win32.client, 'flag', None):
comment = ['dc=foo membership is correct']
ret.update({'comment': comment, 'result': None})
self.assertDictEqual(win_groupadd.members('dc=foo', 'dc=\\user1'), ret)
|
'Test for set a single salt process environment variable. Returns True
on success.'
| def test_setval(self):
| mock = MagicMock(return_value=None)
with patch.dict(os.environ, {}):
self.assertEqual(environ.setval('key', False, True), None)
mock = MagicMock(side_effect=Exception())
with patch.dict(os.environ, {}):
self.assertFalse(environ.setval('key', False, True))
mock_environ = {}
with patch.dict(os.environ, mock_environ):
self.assertEqual(environ.setval('key', False), '')
with patch.dict(os.environ, mock_environ):
self.assertFalse(environ.setval('key', True))
|
'Set multiple salt process environment variables from a dict.
Returns a dict.'
| def test_setenv(self):
| mock_environ = {'key': 'value'}
with patch.dict(os.environ, mock_environ):
self.assertFalse(environ.setenv('environ'))
with patch.dict(os.environ, mock_environ):
self.assertFalse(environ.setenv({'A': True}, False, True, False))
with patch.dict(os.environ, mock_environ):
mock_setval = MagicMock(return_value=None)
with patch.object(environ, 'setval', mock_setval):
self.assertEqual(environ.setenv({}, False, True, False)['key'], None)
|
'Get a single salt process environment variable.'
| def test_get(self):
| self.assertFalse(environ.get(True))
self.assertEqual(environ.get('key'), '')
|
'Determine whether the key exists in the current salt process
environment dictionary. Optionally compare the current value
of the environment against the supplied value string.'
| def test_has_value(self):
| mock_environ = {}
with patch.dict(os.environ, mock_environ):
self.assertFalse(environ.has_value(True))
os.environ['salty'] = 'yes'
self.assertTrue(environ.has_value('salty', 'yes'))
os.environ['too_salty'] = 'no'
self.assertFalse(environ.has_value('too_salty', 'yes'))
self.assertFalse(environ.has_value('key', 'value'))
os.environ['key'] = 'value'
self.assertTrue(environ.has_value('key'))
|
'Get one or more salt process environment variables.
Returns a dict.'
| def test_item(self):
| self.assertEqual(environ.item(None), {})
|
'Return a dict of the entire environment set for the salt process'
| def test_items(self):
| self.assertNotEqual(list(environ.items()), [])
|
'Mock returner functions'
| def returners(self, opts, lst):
| return sysmod.__salt__
|
'Mock renderers'
| def render(self, opts, lst):
| return sysmod.__salt__
|
'Test if it returns the docstrings for all modules.'
| def test_doc(self):
| self.assertDictEqual(sysmod.doc(), self._docstrings)
self.assertDictEqual(sysmod.doc('sys.doc'), {'sys.doc': 'docstring for sys.doc'})
|
'Test if it returns the docstrings for all states.'
| def test_state_doc(self):
| self.assertDictEqual(sysmod.state_doc(), self._statedocstrings)
self.assertDictEqual(sysmod.state_doc('sys.doc'), {'sys': 'docstring for sys', 'sys.doc': 'docstring for sys.doc'})
|
'Test if it returns the docstrings for all runners.'
| def test_runner_doc(self):
| self.assertDictEqual(sysmod.runner_doc(), self._docstrings)
self.assertDictEqual(sysmod.runner_doc('sys.doc'), {'sys.doc': 'docstring for sys.doc'})
|
'Test if it returns the docstrings for all returners.'
| def test_returner_doc(self):
| self.assertDictEqual(sysmod.returner_doc(), self._docstrings)
self.assertDictEqual(sysmod.returner_doc('sys.doc'), {'sys.doc': 'docstring for sys.doc'})
|
'Test if it returns the docstrings for all renderers.'
| def test_renderer_doc(self):
| self.assertDictEqual(sysmod.renderer_doc(), self._docstrings)
self.assertDictEqual(sysmod.renderer_doc('sys.doc'), {'sys.doc': 'docstring for sys.doc'})
|
'Test if it lists the functions for all modules.'
| def test_list_functions(self):
| self.assertListEqual(sysmod.list_functions(), self._functions)
self.assertListEqual(sysmod.list_functions('nonexist'), [])
self.assertListEqual(sysmod.list_functions('sys'), ['sys.doc', 'sys.list_functions', 'sys.list_modules'])
self.assertListEqual(sysmod.list_functions('sys*'), ['sys.doc', 'sys.list_functions', 'sys.list_modules', 'sysctl.get', 'sysctl.show', 'system.halt', 'system.reboot'])
self.assertListEqual(sysmod.list_functions('sys.list*'), ['sys.list_functions', 'sys.list_modules'])
self.assertListEqual(sysmod.list_functions('sys.list'), [])
self.assertListEqual(sysmod.list_functions('exist.exist'), ['exist.exist'])
|
'Test if it lists the modules loaded on the minion'
| def test_list_modules(self):
| self.assertListEqual(sysmod.list_modules(), self._modules)
self.assertListEqual(sysmod.list_modules('nonexist'), [])
self.assertListEqual(sysmod.list_modules('user'), ['user'])
self.assertListEqual(sysmod.list_modules('s*'), ['sys', 'sysctl', 'system'])
|
'Test if it tell the minion to reload the execution modules'
| def test_reload_modules(self):
| self.assertTrue(sysmod.reload_modules())
|
'Test if it return the argument specification
of functions in Salt execution modules.'
| def test_argspec(self):
| self.assertDictEqual(sysmod.argspec(), {})
|
'Test if it return the argument specification
of functions in Salt state modules.'
| def test_state_argspec(self):
| self.assertDictEqual(sysmod.state_argspec(), {})
|
'Test if it return the argument specification
of functions in Salt returner modules.'
| def test_returner_argspec(self):
| self.assertDictEqual(sysmod.returner_argspec(), {})
|
'Test if it return the argument specification of functions in Salt runner
modules.'
| def test_runner_argspec(self):
| self.assertDictEqual(sysmod.runner_argspec(), {})
|
'Test if it lists the functions for all state modules.'
| def test_list_state_functions(self):
| self.assertListEqual(sysmod.list_state_functions(), self._functions)
self.assertListEqual(sysmod.list_state_functions('nonexist'), [])
self.assertListEqual(sysmod.list_state_functions('sys'), ['sys.doc', 'sys.list_functions', 'sys.list_modules'])
self.assertListEqual(sysmod.list_state_functions('sys*'), ['sys.doc', 'sys.list_functions', 'sys.list_modules', 'sysctl.get', 'sysctl.show', 'system.halt', 'system.reboot'])
self.assertListEqual(sysmod.list_state_functions('sys.list*'), ['sys.list_functions', 'sys.list_modules'])
self.assertListEqual(sysmod.list_state_functions('sys.list'), [])
self.assertListEqual(sysmod.list_state_functions('exist.exist'), ['exist.exist'])
|
'Test if it lists the modules loaded on the minion.'
| def test_list_state_modules(self):
| self.assertListEqual(sysmod.list_state_modules(), self._modules)
self.assertListEqual(sysmod.list_state_modules('nonexist'), [])
self.assertListEqual(sysmod.list_state_modules('user'), ['user'])
self.assertListEqual(sysmod.list_state_modules('s*'), ['sys', 'sysctl', 'system'])
|
'Test if it list the runners loaded on the minion.'
| def test_list_runners(self):
| self.assertListEqual(sysmod.list_runners(), self._modules)
self.assertListEqual(sysmod.list_runners('nonexist'), [])
self.assertListEqual(sysmod.list_runners('user'), ['user'])
self.assertListEqual(sysmod.list_runners('s*'), ['sys', 'sysctl', 'system'])
|
'Test if it lists the functions for all runner modules.'
| def test_list_runner_functions(self):
| self.assertListEqual(sysmod.list_runner_functions(), self._functions)
self.assertListEqual(sysmod.list_runner_functions('nonexist'), [])
self.assertListEqual(sysmod.list_runner_functions('sys'), ['sys.doc', 'sys.list_functions', 'sys.list_modules'])
self.assertListEqual(sysmod.list_runner_functions('sys*'), ['sys.doc', 'sys.list_functions', 'sys.list_modules', 'sysctl.get', 'sysctl.show', 'system.halt', 'system.reboot'])
self.assertListEqual(sysmod.list_runner_functions('sys.list*'), ['sys.list_functions', 'sys.list_modules'])
self.assertListEqual(sysmod.list_runner_functions('sys.list'), [])
self.assertListEqual(sysmod.list_runner_functions('exist.exist'), ['exist.exist'])
|
'Test if it lists the returners loaded on the minion'
| def test_list_returners(self):
| self.assertListEqual(sysmod.list_returners(), self._modules)
self.assertListEqual(sysmod.list_returners('nonexist'), [])
self.assertListEqual(sysmod.list_returners('user'), ['user'])
self.assertListEqual(sysmod.list_returners('s*'), ['sys', 'sysctl', 'system'])
|
'Test if it lists the functions for all returner modules.'
| def test_list_returner_functions(self):
| self.assertListEqual(sysmod.list_returner_functions(), self._functions)
self.assertListEqual(sysmod.list_returner_functions('nonexist'), [])
self.assertListEqual(sysmod.list_returner_functions('sys'), ['sys.doc', 'sys.list_functions', 'sys.list_modules'])
self.assertListEqual(sysmod.list_returner_functions('sys*'), ['sys.doc', 'sys.list_functions', 'sys.list_modules', 'sysctl.get', 'sysctl.show', 'system.halt', 'system.reboot'])
self.assertListEqual(sysmod.list_returner_functions('sys.list*'), ['sys.list_functions', 'sys.list_modules'])
self.assertListEqual(sysmod.list_returner_functions('sys.list'), [])
self.assertListEqual(sysmod.list_returner_functions('exist.exist'), ['exist.exist'])
|
'Test if it list the renderers loaded on the minion.'
| def test_list_renderers(self):
| self.assertListEqual(sysmod.list_renderers(), self._functions)
self.assertListEqual(sysmod.list_renderers('nonexist'), [])
self.assertListEqual(sysmod.list_renderers('user.info'), ['user.info'])
self.assertListEqual(sysmod.list_renderers('syst*'), ['system.halt', 'system.reboot'])
|
'Test to make sure we can set the monitor timeout value'
| def test_set_monitor_timeout(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
powercfg.set_monitor_timeout(0, 'dc')
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_VIDEO VIDEOIDLE 0', python_shell=False)]
mock.assert_has_calls(calls)
|
'Test to make sure we can set the disk timeout value'
| def test_set_disk_timeout(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
powercfg.set_disk_timeout(0, 'dc')
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_DISK DISKIDLE 0', python_shell=False)]
mock.assert_has_calls(calls)
|
'Test to make sure we can set the standby timeout value'
| def test_set_standby_timeout(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
powercfg.set_standby_timeout(0, 'dc')
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP STANDBYIDLE 0', python_shell=False)]
mock.assert_has_calls(calls)
|
'Test to make sure we can set the hibernate timeout value'
| def test_set_hibernate_timeout(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
powercfg.set_hibernate_timeout(0, 'dc')
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP HIBERNATEIDLE 0', python_shell=False)]
mock.assert_has_calls(calls)
|
'Test to make sure we can get the monitor timeout value'
| def test_get_monitor_timeout(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
ret = powercfg.get_monitor_timeout()
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_VIDEO VIDEOIDLE', python_shell=False)]
mock.assert_has_calls(calls)
self.assertEqual({'ac': 30, 'dc': 15}, ret)
|
'Test to make sure we can get the disk timeout value'
| def test_get_disk_timeout(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
ret = powercfg.get_disk_timeout()
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_DISK DISKIDLE', python_shell=False)]
mock.assert_has_calls(calls)
self.assertEqual({'ac': 30, 'dc': 15}, ret)
|
'Test to make sure we can get the standby timeout value'
| def test_get_standby_timeout(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
ret = powercfg.get_standby_timeout()
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP STANDBYIDLE', python_shell=False)]
mock.assert_has_calls(calls)
self.assertEqual({'ac': 30, 'dc': 15}, ret)
|
'Test to make sure we can get the hibernate timeout value'
| def test_get_hibernate_timeout(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
ret = powercfg.get_hibernate_timeout()
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP HIBERNATEIDLE', python_shell=False)]
mock.assert_has_calls(calls)
self.assertEqual({'ac': 30, 'dc': 15}, ret)
|
'Test to make sure we can get the hibernate timeout value on windows 7'
| def test_windows_7(self):
| mock = MagicMock()
mock.side_effect = ['Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)', self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
with patch.dict(powercfg.__grains__, {'osrelease': '7'}):
ret = powercfg.get_hibernate_timeout()
calls = [call('powercfg /getactivescheme', python_shell=False), call('powercfg /q 381b4222-f694-41f0-9685-ff5bb260df2e SUB_SLEEP', python_shell=False)]
mock.assert_has_calls(calls)
self.assertEqual({'ac': 30, 'dc': 15}, ret)
|
'Test to make sure we can set the hibernate timeout value'
| def test_set_hibernate_timeout_scheme(self):
| mock = MagicMock()
mock.side_effect = [self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
powercfg.set_hibernate_timeout(0, 'dc', scheme='SCHEME_MIN')
calls = [call('powercfg /setdcvalueindex SCHEME_MIN SUB_SLEEP HIBERNATEIDLE 0', python_shell=False)]
mock.assert_has_calls(calls)
|
'Test to make sure we can get the hibernate timeout value with a specified scheme'
| def test_get_hibernate_timeout_scheme(self):
| mock = MagicMock()
mock.side_effect = [self.query_output]
with patch.dict(powercfg.__salt__, {'cmd.run': mock}):
ret = powercfg.get_hibernate_timeout(scheme='SCHEME_MIN')
calls = [call('powercfg /q SCHEME_MIN SUB_SLEEP HIBERNATEIDLE', python_shell=False)]
mock.assert_has_calls(calls)
self.assertEqual({'ac': 30, 'dc': 15}, ret)
|
'Tests checking domain existence when the domain already exists'
| def test_that_when_checking_if_a_domain_exists_and_a_domain_exists_the_domain_exists_method_returns_true(self):
| result = boto_elasticsearch_domain.exists(DomainName='testdomain', **conn_parameters)
self.assertTrue(result['exists'])
|
'Tests checking domain existence when the domain does not exist'
| def test_that_when_checking_if_a_domain_exists_and_a_domain_does_not_exist_the_domain_exists_method_returns_false(self):
| self.conn.describe_elasticsearch_domain.side_effect = not_found_error
result = boto_elasticsearch_domain.exists(DomainName='mydomain', **conn_parameters)
self.assertFalse(result['exists'])
|
'Tests checking domain existence when boto returns an error'
| def test_that_when_checking_if_a_domain_exists_and_boto3_returns_an_error_the_domain_exists_method_returns_error(self):
| self.conn.describe_elasticsearch_domain.side_effect = ClientError(error_content, 'list_domains')
result = boto_elasticsearch_domain.exists(DomainName='mydomain', **conn_parameters)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('list_domains'))
|
'Tests checking domain existence when the domain already exists'
| def test_that_when_checking_domain_status_and_a_domain_exists_the_domain_status_method_returns_info(self):
| self.conn.describe_elasticsearch_domain.return_value = {'DomainStatus': domain_ret}
result = boto_elasticsearch_domain.status(DomainName='testdomain', **conn_parameters)
self.assertTrue(result['domain'])
|
'Tests checking domain existence when boto returns an error'
| def test_that_when_checking_domain_status_and_boto3_returns_an_error_the_domain_status_method_returns_error(self):
| self.conn.describe_elasticsearch_domain.side_effect = ClientError(error_content, 'list_domains')
result = boto_elasticsearch_domain.status(DomainName='mydomain', **conn_parameters)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('list_domains'))
|
'Tests describing parameters if domain exists'
| def test_that_when_describing_domain_it_returns_the_dict_of_properties_returns_true(self):
| domainconfig = {}
for (k, v) in six.iteritems(domain_ret):
if (k == 'DomainName'):
continue
domainconfig[k] = {'Options': v}
self.conn.describe_elasticsearch_domain_config.return_value = {'DomainConfig': domainconfig}
result = boto_elasticsearch_domain.describe(DomainName=domain_ret['DomainName'], **conn_parameters)
log.warning(result)
desired_ret = copy.copy(domain_ret)
desired_ret.pop('DomainName')
self.assertEqual(result, {'domain': desired_ret})
|
'Tests describing parameters failure'
| def test_that_when_describing_domain_on_client_error_it_returns_error(self):
| self.conn.describe_elasticsearch_domain_config.side_effect = ClientError(error_content, 'list_domains')
result = boto_elasticsearch_domain.describe(DomainName='testdomain', **conn_parameters)
self.assertTrue(('error' in result))
|
'tests True domain created.'
| def test_that_when_creating_a_domain_succeeds_the_create_domain_method_returns_true(self):
| self.conn.create_elasticsearch_domain.return_value = {'DomainStatus': domain_ret}
args = copy.copy(domain_ret)
args.update(conn_parameters)
result = boto_elasticsearch_domain.create(**args)
self.assertTrue(result['created'])
|
'tests False domain not created.'
| def test_that_when_creating_a_domain_fails_the_create_domain_method_returns_error(self):
| self.conn.create_elasticsearch_domain.side_effect = ClientError(error_content, 'create_domain')
args = copy.copy(domain_ret)
args.update(conn_parameters)
result = boto_elasticsearch_domain.create(**args)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('create_domain'))
|
'tests True domain deleted.'
| def test_that_when_deleting_a_domain_succeeds_the_delete_domain_method_returns_true(self):
| result = boto_elasticsearch_domain.delete(DomainName='testdomain', **conn_parameters)
self.assertTrue(result['deleted'])
|
'tests False domain not deleted.'
| def test_that_when_deleting_a_domain_fails_the_delete_domain_method_returns_false(self):
| self.conn.delete_elasticsearch_domain.side_effect = ClientError(error_content, 'delete_domain')
result = boto_elasticsearch_domain.delete(DomainName='testdomain', **conn_parameters)
self.assertFalse(result['deleted'])
|
'tests True domain updated.'
| def test_that_when_updating_a_domain_succeeds_the_update_domain_method_returns_true(self):
| self.conn.update_elasticsearch_domain_config.return_value = {'DomainConfig': domain_ret}
args = copy.copy(domain_ret)
args.update(conn_parameters)
result = boto_elasticsearch_domain.update(**args)
self.assertTrue(result['updated'])
|
'tests False domain not updated.'
| def test_that_when_updating_a_domain_fails_the_update_domain_method_returns_error(self):
| self.conn.update_elasticsearch_domain_config.side_effect = ClientError(error_content, 'update_domain')
args = copy.copy(domain_ret)
args.update(conn_parameters)
result = boto_elasticsearch_domain.update(**args)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('update_domain'))
|
'tests True tags added.'
| def test_that_when_adding_tags_succeeds_the_add_tags_method_returns_true(self):
| self.conn.describe_elasticsearch_domain.return_value = {'DomainStatus': domain_ret}
result = boto_elasticsearch_domain.add_tags(DomainName='testdomain', a='b', **conn_parameters)
self.assertTrue(result['tagged'])
|
'tests False tags not added.'
| def test_that_when_adding_tags_fails_the_add_tags_method_returns_false(self):
| self.conn.add_tags.side_effect = ClientError(error_content, 'add_tags')
self.conn.describe_elasticsearch_domain.return_value = {'DomainStatus': domain_ret}
result = boto_elasticsearch_domain.add_tags(DomainName=domain_ret['DomainName'], a='b', **conn_parameters)
self.assertFalse(result['tagged'])
|
'tests True tags removed.'
| def test_that_when_removing_tags_succeeds_the_remove_tags_method_returns_true(self):
| self.conn.describe_elasticsearch_domain.return_value = {'DomainStatus': domain_ret}
result = boto_elasticsearch_domain.remove_tags(DomainName=domain_ret['DomainName'], TagKeys=['a'], **conn_parameters)
self.assertTrue(result['tagged'])
|
'tests False tags not removed.'
| def test_that_when_removing_tags_fails_the_remove_tags_method_returns_false(self):
| self.conn.remove_tags.side_effect = ClientError(error_content, 'remove_tags')
self.conn.describe_elasticsearch_domain.return_value = {'DomainStatus': domain_ret}
result = boto_elasticsearch_domain.remove_tags(DomainName=domain_ret['DomainName'], TagKeys=['b'], **conn_parameters)
self.assertFalse(result['tagged'])
|
'tests True tags listed.'
| def test_that_when_listing_tags_succeeds_the_list_tags_method_returns_true(self):
| self.conn.describe_elasticsearch_domain.return_value = {'DomainStatus': domain_ret}
result = boto_elasticsearch_domain.list_tags(DomainName=domain_ret['DomainName'], **conn_parameters)
self.assertEqual(result['tags'], {})
|
'tests False tags not listed.'
| def test_that_when_listing_tags_fails_the_list_tags_method_returns_false(self):
| self.conn.list_tags.side_effect = ClientError(error_content, 'list_tags')
self.conn.describe_elasticsearch_domain.return_value = {'DomainStatus': domain_ret}
result = boto_elasticsearch_domain.list_tags(DomainName=domain_ret['DomainName'], **conn_parameters)
self.assertTrue(result['error'])
|
'Tests successful return of exists function'
| def test_exists_success(self):
| ret = {}
ret['stdout'] = 'NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT\nmyzpool 149G 128K 149G 0% 1.00x ONLINE -'
ret['stderr'] = ''
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
self.assertTrue(zpool.exists('myzpool'))
|
'Tests failure return of exists function'
| def test_exists_failure(self):
| ret = {}
ret['stdout'] = ''
ret['stderr'] = "cannot open 'myzpool': no such pool"
ret['retcode'] = 1
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
self.assertFalse(zpool.exists('myzpool'))
|
'Tests successful return of healthy function'
| def test_healthy(self):
| ret = {}
ret['stdout'] = 'all pools are healthy'
ret['stderr'] = ''
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
self.assertTrue(zpool.healthy())
|
'Tests successful return of status function'
| def test_status(self):
| ret = {}
ret['stdout'] = '\n'.join([' pool: mypool', ' state: ONLINE', ' scan: scrub repaired 0 in 0h6m with 0 errors on Mon Dec 21 02:06:17 2015', 'config:', '', ' NAME STATE READ WRITE CKSUM', ' mypool ONLINE 0 0 0', ' mirror-0 ONLINE 0 0 0', ' c2t0d0 ONLINE 0 0 0', ' c2t1d0 ONLINE 0 0 0', '', 'errors: No known data errors'])
ret['stderr'] = ''
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
ret = zpool.status()
self.assertEqual('ONLINE', ret['mypool']['state'])
|
'Tests successful return of iostat function'
| def test_iostat(self):
| ret = {}
ret['stdout'] = '\n'.join([' capacity operations bandwidth', 'pool alloc free read write read write', '---------- ----- ----- ----- ----- ----- -----', 'mypool 46.7G 64.3G 4 19 113K 331K', ' mirror 46.7G 64.3G 4 19 113K 331K', ' c2t0d0 - - 1 10 114K 334K', ' c2t1d0 - - 1 10 114K 334K', '---------- ----- ----- ----- ----- ----- -----'])
ret['stderr'] = ''
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
ret = zpool.iostat('mypool')
self.assertEqual('46.7G', ret['mypool']['mypool']['capacity-alloc'])
|
'Tests successful return of list function'
| def test_list(self):
| ret = {}
ret['stdout'] = 'mypool DCTB 111G DCTB 47.4G DCTB 63.6G DCTB 42% DCTB ONLINE\n'
ret['stderr'] = ''
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
with patch('salt.modules.zpool._check_features', MagicMock(return_value=False)):
ret = zpool.list_()
res = OrderedDict([('mypool', {'alloc': '47.4G', 'cap': '42%', 'free': '63.6G', 'health': 'ONLINE', 'size': '111G'})])
self.assertEqual(res, ret)
|
'Tests successful return of get function'
| def test_get(self):
| ret = {}
ret['stdout'] = 'readonly DCTB off DCTB -\n'
ret['stderr'] = ''
ret['retcode'] = 0
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zpool.__salt__, {'cmd.run_all': mock_cmd}):
ret = zpool.get('mypool', 'readonly')
res = OrderedDict([('mypool', OrderedDict([('readonly', 'off')]))])
self.assertEqual(res, ret)
|
'Test for Run SQL query and return result'
| def test_run_query(self):
| with patch.object(oracle, '_connect', MagicMock()) as mock_connect:
mock_connect.cursor.execute.fetchall.return_value = True
with patch.object(oracle, 'show_dbs', MagicMock()):
self.assertTrue(oracle.run_query('db', 'query'))
|
'Test for Show databases configuration from pillar. Filter by `*args`'
| def test_show_dbs(self):
| with patch.dict(oracle.__salt__, {'pillar.get': MagicMock(return_value='a')}):
self.assertDictEqual(oracle.show_dbs('A', 'B'), {'A': 'a', 'B': 'a'})
self.assertEqual(oracle.show_dbs(), 'a')
|
'Test for Server Version (select banner from v$version)'
| def test_version(self):
| with patch.dict(oracle.__salt__, {'pillar.get': MagicMock(return_value='a')}):
with patch.object(oracle, 'run_query', return_value='A'):
self.assertDictEqual(oracle.version(), {})
|
'Test for Oracle Client Version'
| def test_client_version(self):
| with patch.object(oracle, 'cx_Oracle', MagicMock(side_effect=MagicMock())):
self.assertEqual(oracle.client_version(), '')
|
'Test for Show Pillar segment oracle.*'
| def test_show_pillar(self):
| with patch.dict(oracle.__salt__, {'pillar.get': MagicMock(return_value='a')}):
self.assertEqual(oracle.show_pillar('item'), 'a')
|
'Test for Show Environment used by Oracle Client'
| def test_show_env(self):
| with patch.object(os, 'environ', return_value={'PATH': 'PATH', 'ORACLE_HOME': 'ORACLE_HOME', 'TNS_ADMIN': 'TNS_ADMIN', 'NLS_LANG': 'NLS_LANG'}):
self.assertDictEqual(oracle.show_env(), {})
|
'Mock verify_data method'
| def verify_data(self, data):
| data = data
if self.flag:
return True
else:
return False
|
'Mock call method'
| @staticmethod
def call(data):
| data = data
return list
|
'Mock call_high method'
| @staticmethod
def call_high(data, orchestration_jid=None):
| data = data
return True
|
'Mock call_template_str method'
| @staticmethod
def call_template_str(data):
| data = data
return True
|
'Mock _mod_init method'
| @staticmethod
def _mod_init(data):
| data = data
return True
|
'Mock verify_high method'
| def verify_high(self, data):
| data = data
if self.flag:
return True
else:
return (-1)
|
'Mock compile_high_data'
| @staticmethod
def compile_high_data(data):
| data = data
return [{'__id__': 'ABC'}]
|
'Mock call_chunk method'
| @staticmethod
def call_chunk(data, data1, data2):
| data = data
data1 = data1
data2 = data2
return {'': 'ABC'}
|
'Mock call_chunks method'
| @staticmethod
def call_chunks(data):
| data = data
return True
|
'Mock call_listen method'
| @staticmethod
def call_listen(data, ret):
| data = data
ret = ret
return True
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.