desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Mock render_state method'
| def render_state(self, sls, saltenv, mods, matches, local=False):
| sls = sls
saltenv = saltenv
mods = mods
matches = matches
local = local
if self.flag:
return ({}, True)
else:
return ({}, False)
|
'Mock get_top method'
| @staticmethod
def get_top():
| return '_top'
|
'Mock verify_tops method'
| def verify_tops(self, data):
| data = data
if self.flag:
return ['a', 'b']
else:
return []
|
'Mock top_matches method'
| @staticmethod
def top_matches(data):
| data = data
return ['a', 'b', 'c']
|
'Mock push_active method'
| @staticmethod
def push_active():
| return True
|
'Mock compile_highstate method'
| @staticmethod
def compile_highstate():
| return 'A'
|
'Mock compile_state_usage method'
| @staticmethod
def compile_state_usage():
| return 'A'
|
'Mock pop_active method'
| @staticmethod
def pop_active():
| return True
|
'Mock compile_low_chunks method'
| @staticmethod
def compile_low_chunks():
| return True
|
'Mock render_highstate method'
| def render_highstate(self, data):
| data = data
if self.flag:
return (['a', 'b'], True)
else:
return (['a', 'b'], False)
|
'Mock call_highstate method'
| @staticmethod
def call_highstate(exclude, cache, cache_name, force=None, whitelist=None, orchestration_jid=None):
| exclude = exclude
cache = cache
cache_name = cache_name
force = force
whitelist = whitelist
return True
|
'Mock load method'
| @staticmethod
def load(data):
| data = data
return {'A': 'B'}
|
'Mock dump method'
| @staticmethod
def dump(data, data1):
| data = data
data1 = data1
return True
|
'Mock open method'
| @staticmethod
def open(data, data1):
| data = data
data1 = data1
return MockTarFile
|
'Mock getmembers method'
| @staticmethod
def getmembers():
| return [MockTarFile]
|
'Mock extractall method'
| @staticmethod
def extractall(data):
| data = data
return True
|
'Mock close method'
| @staticmethod
def close():
| return True
|
'Mock load method'
| def load(self, data, object_hook=None):
| data = data
object_hook = object_hook
if self.flag:
return [True]
else:
return [{'test': ''}]
|
'Test of checking i fthe state function is already running'
| def test_running(self):
| self.assertEqual(state.running(True), [])
mock = MagicMock(side_effect=[[{'fun': 'state.running', 'pid': '4126', 'jid': '20150325123407204096'}], []])
with patch.dict(state.__salt__, {'saltutil.is_running': mock}):
self.assertListEqual(state.running(), ['The function "state.running" is running as PID 4126 and was started at 2015, Mar 25 12:34:07.204096 with jid 20150325123407204096'])
self.assertListEqual(state.running(), [])
|
'Test of executing a single low data call'
| def test_low(self):
| mock = MagicMock(side_effect=[False, None, None])
with patch.object(state, '_check_queue', mock):
self.assertFalse(state.low({'state': 'pkg', 'fun': 'installed', 'name': 'vi'}))
MockState.State.flag = False
self.assertEqual(state.low({'state': 'pkg', 'fun': 'installed', 'name': 'vi'}), list)
MockState.State.flag = True
self.assertTrue(state.low({'state': 'pkg', 'fun': 'installed', 'name': 'vi'}))
|
'Test for checking the state system'
| def test_high(self):
| mock = MagicMock(side_effect=[False, None])
with patch.object(state, '_check_queue', mock):
self.assertFalse(state.high({'vim': {'pkg': ['installed']}}))
mock = MagicMock(return_value={'test': True})
with patch.object(state, '_get_opts', mock):
self.assertTrue(state.high({'vim': {'pkg': ['installed']}}))
|
'Test of executing the information
stored in a template file on the minion'
| def test_template(self):
| mock = MagicMock(side_effect=[False, None, None])
with patch.object(state, '_check_queue', mock):
self.assertFalse(state.template('/home/salt/salt.sls'))
MockState.HighState.flag = True
self.assertTrue(state.template('/home/salt/salt.sls'))
MockState.HighState.flag = False
self.assertTrue(state.template('/home/salt/salt.sls'))
|
'Test for Executing the information
stored in a string from an sls template'
| def test_template_str(self):
| mock = MagicMock(side_effect=[False, None])
with patch.object(state, '_check_queue', mock):
self.assertFalse(state.template_str('Template String'))
self.assertTrue(state.template_str('Template String'))
|
'Test to apply states'
| def test_apply_(self):
| mock = MagicMock(return_value=True)
with patch.object(state, 'sls', mock):
self.assertTrue(state.apply_(True))
with patch.object(state, 'highstate', mock):
self.assertTrue(state.apply_(None))
|
'Test to list disabled states'
| def test_list_disabled(self):
| mock = MagicMock(return_value=['A', 'B', 'C'])
with patch.dict(state.__salt__, {'grains.get': mock}):
self.assertListEqual(state.list_disabled(), ['A', 'B', 'C'])
|
'Test to Enable state function or sls run'
| def test_enable(self):
| mock = MagicMock(return_value=['A', 'B'])
with patch.dict(state.__salt__, {'grains.get': mock}):
mock = MagicMock(return_value=[])
with patch.dict(state.__salt__, {'grains.setval': mock}):
mock = MagicMock(return_value=[])
with patch.dict(state.__salt__, {'saltutil.refresh_modules': mock}):
self.assertDictEqual(state.enable('A'), {'msg': 'Info: A state enabled.', 'res': True})
self.assertDictEqual(state.enable('Z'), {'msg': 'Info: Z state already enabled.', 'res': True})
|
'Test to disable state run'
| def test_disable(self):
| mock = MagicMock(return_value=['C', 'D'])
with patch.dict(state.__salt__, {'grains.get': mock}):
mock = MagicMock(return_value=[])
with patch.dict(state.__salt__, {'grains.setval': mock}):
mock = MagicMock(return_value=[])
with patch.dict(state.__salt__, {'saltutil.refresh_modules': mock}):
self.assertDictEqual(state.disable('C'), {'msg': 'Info: C state already disabled.', 'res': True})
self.assertDictEqual(state.disable('Z'), {'msg': 'Info: Z state disabled.', 'res': True})
|
'Test to clear out cached state file'
| def test_clear_cache(self):
| mock = MagicMock(return_value=['A.cache.p', 'B.cache.p', 'C'])
with patch.object(os, 'listdir', mock):
mock = MagicMock(return_value=True)
with patch.object(os.path, 'isfile', mock):
mock = MagicMock(return_value=True)
with patch.object(os, 'remove', mock):
self.assertEqual(state.clear_cache(), ['A.cache.p', 'B.cache.p'])
|
'Test to execute single state function'
| def test_single(self):
| ret = {'pkg_|-name=vim_|-name=vim_|-installed': list}
mock = MagicMock(side_effect=['A', None, None, None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.single('pkg.installed', ' name=vim'), 'A')
self.assertEqual(state.single('pk', 'name=vim'), 'Invalid function passed')
with patch.dict(state.__opts__, {'test': 'install'}):
mock = MagicMock(return_value={'test': ''})
with patch.object(state, '_get_opts', mock):
mock = MagicMock(return_value=True)
with patch.object(salt.utils, 'test_mode', mock):
self.assertRaises(SaltInvocationError, state.single, 'pkg.installed', 'name=vim', pillar='A')
MockState.State.flag = True
self.assertTrue(state.single('pkg.installed', 'name=vim'))
MockState.State.flag = False
self.assertDictEqual(state.single('pkg.installed', 'name=vim'), ret)
|
'Test to return the top data that the minion will use for a highstate'
| def test_show_top(self):
| mock = MagicMock(side_effect=['A', None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.show_top(), 'A')
MockState.HighState.flag = True
self.assertListEqual(state.show_top(), ['a', 'b'])
MockState.HighState.flag = False
self.assertListEqual(state.show_top(), ['a', 'b', 'c'])
|
'Test to Execute the pending state request'
| def test_run_request(self):
| mock = MagicMock(side_effect=[{}, {'name': 'A'}, {'name': {'mods': 'A', 'kwargs': {}}}])
with patch.object(state, 'check_request', mock):
self.assertDictEqual(state.run_request('A'), {})
self.assertDictEqual(state.run_request('A'), {})
mock = MagicMock(return_value=['True'])
with patch.object(state, 'apply_', mock):
mock = MagicMock(return_value='')
with patch.object(os, 'remove', mock):
self.assertListEqual(state.run_request('name'), ['True'])
|
'Test to retrieve the highstate data from the salt master'
| def test_show_highstate(self):
| mock = MagicMock(side_effect=['A', None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.show_highstate(), 'A')
self.assertRaises(SaltInvocationError, state.show_highstate, pillar='A')
self.assertEqual(state.show_highstate(), 'A')
|
'Test to list out the low data that will be applied to this minion'
| def test_show_lowstate(self):
| mock = MagicMock(side_effect=['A', None])
with patch.object(state, '_check_queue', mock):
self.assertRaises(AssertionError, state.show_lowstate)
self.assertTrue(state.show_lowstate())
|
'Test to list out the state usage that will be applied to this minion'
| def test_show_state_usage(self):
| mock = MagicMock(side_effect=['A', None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.show_state_usage(), 'A')
self.assertRaises(SaltInvocationError, state.show_state_usage, pillar='A')
self.assertEqual(state.show_state_usage(), 'A')
|
'Test to call a single ID from the
named module(s) and handle all requisites'
| def test_sls_id(self):
| mock = MagicMock(side_effect=['A', None, None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.sls_id('apache', 'http'), 'A')
with patch.dict(state.__opts__, {'test': 'A'}):
mock = MagicMock(return_value={'test': True, 'environment': None})
with patch.object(state, '_get_opts', mock):
mock = MagicMock(return_value=True)
with patch.object(salt.utils, 'test_mode', mock):
MockState.State.flag = True
MockState.HighState.flag = True
self.assertEqual(state.sls_id('apache', 'http'), 2)
MockState.State.flag = False
self.assertDictEqual(state.sls_id('ABC', 'http'), {'': 'ABC'})
self.assertRaises(SaltInvocationError, state.sls_id, 'DEF', 'http')
|
'Test to display the low data from a specific sls'
| def test_show_low_sls(self):
| mock = MagicMock(side_effect=['A', None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.show_low_sls('foo'), 'A')
with patch.dict(state.__opts__, {'test': 'A'}):
mock = MagicMock(return_value={'test': True, 'environment': None})
with patch.object(state, '_get_opts', mock):
MockState.State.flag = True
MockState.HighState.flag = True
self.assertEqual(state.show_low_sls('foo'), 2)
MockState.State.flag = False
self.assertListEqual(state.show_low_sls('foo'), [{'__id__': 'ABC'}])
|
'Test to display the state data from a specific sls'
| def test_show_sls(self):
| mock = MagicMock(side_effect=['A', None, None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.show_sls('foo'), 'A')
with patch.dict(state.__opts__, {'test': 'A'}):
mock = MagicMock(return_value={'test': True, 'environment': None})
with patch.object(state, '_get_opts', mock):
mock = MagicMock(return_value=True)
with patch.object(salt.utils, 'test_mode', mock):
self.assertRaises(SaltInvocationError, state.show_sls, 'foo', pillar='A')
MockState.State.flag = True
self.assertEqual(state.show_sls('foo'), 2)
MockState.State.flag = False
self.assertListEqual(state.show_sls('foo'), ['a', 'b'])
|
'Test to execute a specific top file'
| def test_top(self):
| ret = ['Pillar failed to render with the following messages:', 'E']
mock = MagicMock(side_effect=['A', None, None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.top('reverse_top.sls'), 'A')
mock = MagicMock(side_effect=[False, True, True])
with patch.object(state, '_check_pillar', mock):
with patch.dict(state.__pillar__, {'_errors': 'E'}):
self.assertListEqual(state.top('reverse_top.sls'), ret)
with patch.dict(state.__opts__, {'test': 'A'}):
mock = MagicMock(return_value={'test': True})
with patch.object(state, '_get_opts', mock):
mock = MagicMock(return_value=True)
with patch.object(salt.utils, 'test_mode', mock):
self.assertRaises(SaltInvocationError, state.top, 'reverse_top.sls', pillar='A')
mock = MagicMock(return_value='salt://reverse_top.sls')
with patch.object(os.path, 'join', mock):
mock = MagicMock(return_value=True)
with patch.object(state, '_set_retcode', mock):
self.assertTrue(state.top('reverse_top.sls exclude=exclude.sls'))
|
'Test to retrieve the state data from the
salt master for the minion and execute it'
| def test_highstate(self):
| arg = 'whitelist=sls1.sls'
mock = MagicMock(side_effect=[True, False, False, False])
with patch.object(state, '_disabled', mock):
self.assertDictEqual(state.highstate('whitelist=sls1.sls'), {'comment': 'Disabled', 'name': 'Salt highstate run is disabled. To re-enable, run state.enable highstate', 'result': 'False'})
mock = MagicMock(side_effect=['A', None, None])
with patch.object(state, '_check_queue', mock):
self.assertEqual(state.highstate('whitelist=sls1.sls'), 'A')
with patch.dict(state.__opts__, {'test': 'A'}):
mock = MagicMock(return_value={'test': True})
with patch.object(state, '_get_opts', mock):
self.assertRaises(SaltInvocationError, state.highstate, 'whitelist=sls1.sls', pillar='A')
mock = MagicMock(return_value=True)
with patch.dict(state.__salt__, {'config.option': mock}):
mock = MagicMock(return_value='A')
with patch.object(state, '_filter_running', mock):
mock = MagicMock(return_value=True)
with patch.object(state, '_filter_running', mock):
mock = MagicMock(return_value=True)
with patch.object(salt.payload, 'Serial', mock):
with patch.object(os.path, 'join', mock):
with patch.object(state, '_set_retcode', mock):
self.assertTrue(state.highstate(arg))
|
'Test to clear out the state execution request without executing it'
| def test_clear_request(self):
| mock = MagicMock(return_value=True)
with patch.object(os.path, 'join', mock):
mock = MagicMock(return_value=True)
with patch.object(salt.payload, 'Serial', mock):
mock = MagicMock(side_effect=[False, True, True])
with patch.object(os.path, 'isfile', mock):
self.assertTrue(state.clear_request('A'))
mock = MagicMock(return_value=True)
with patch.object(os, 'remove', mock):
self.assertTrue(state.clear_request())
mock = MagicMock(return_value={})
with patch.object(state, 'check_request', mock):
self.assertFalse(state.clear_request('A'))
|
'Test to return the state request information'
| def test_check_request(self):
| mock = MagicMock(return_value=True)
with patch.object(os.path, 'join', mock):
with patch('salt.modules.state.salt.payload', MockSerial):
mock = MagicMock(side_effect=[True, True, False])
with patch.object(os.path, 'isfile', mock):
with patch('salt.utils.files.fopen', mock_open()):
self.assertDictEqual(state.check_request(), {'A': 'B'})
with patch('salt.utils.files.fopen', mock_open()):
self.assertEqual(state.check_request('A'), 'B')
self.assertDictEqual(state.check_request(), {})
|
'Test to request the local admin execute a state run'
| def test_request(self):
| mock = MagicMock(return_value=True)
with patch.object(state, 'apply_', mock):
mock = MagicMock(return_value=True)
with patch.object(os.path, 'join', mock):
mock = MagicMock(return_value={'test_run': '', 'mods': '', 'kwargs': ''})
with patch.object(state, 'check_request', mock):
mock = MagicMock(return_value=True)
with patch.object(os, 'umask', mock):
with patch.object(salt.utils.platform, 'is_windows', mock):
with patch.dict(state.__salt__, {'cmd.run': mock}):
with patch('salt.utils.files.fopen', mock_open()):
mock = MagicMock(return_value=True)
with patch.object(os, 'umask', mock):
self.assertTrue(state.request('A'))
|
'Test to execute a set list of state files from an environment'
| def test_sls(self):
| arg = 'core,edit.vim dev'
ret = ['Pillar failed to render with the following messages:', 'E', '1']
mock = MagicMock(return_value=True)
with patch.object(state, 'running', mock):
with patch.dict(state.__context__, {'retcode': 1}):
self.assertEqual(state.sls('core,edit.vim dev'), True)
mock = MagicMock(side_effect=[True, True, True, True, True, True])
with patch.object(state, '_wait', mock):
mock = MagicMock(side_effect=[['A'], [], [], [], [], []])
with patch.object(state, '_disabled', mock):
with patch.dict(state.__context__, {'retcode': 1}):
self.assertEqual(state.sls('core,edit.vim dev', None, None, True), ['A'])
mock = MagicMock(side_effect=[False, True, True, True, True])
with patch.object(state, '_check_pillar', mock):
with patch.dict(state.__context__, {'retcode': 5}):
with patch.dict(state.__pillar__, {'_errors': 'E1'}):
self.assertListEqual(state.sls('core,edit.vim dev', None, None, True), ret)
with patch.dict(state.__opts__, {'test': None}):
mock = MagicMock(return_value={'test': '', 'environment': None})
with patch.object(state, '_get_opts', mock):
mock = MagicMock(return_value=True)
with patch.object(salt.utils, 'test_mode', mock):
self.assertRaises(SaltInvocationError, state.sls, 'core,edit.vim dev', None, None, True, pillar='A')
mock = MagicMock(return_value='/D/cache.cache.p')
with patch.object(os.path, 'join', mock):
mock = MagicMock(return_value=True)
with patch.object(os.path, 'isfile', mock):
with patch('salt.utils.files.fopen', mock_open()):
self.assertTrue(state.sls(arg, None, None, True, cache=True))
MockState.HighState.flag = True
self.assertTrue(state.sls('core,edit.vim dev', None, None, True))
MockState.HighState.flag = False
mock = MagicMock(return_value=True)
with patch.dict(state.__salt__, {'config.option': mock}):
mock = MagicMock(return_value=True)
with patch.object(state, '_filter_running', mock):
self.sub_test_sls()
|
'Sub function of test_sls'
| def sub_test_sls(self):
| mock = MagicMock(return_value=True)
with patch.object(os.path, 'join', mock):
with patch.object(os, 'umask', mock):
mock = MagicMock(return_value=False)
with patch.object(salt.utils.platform, 'is_windows', mock):
mock = MagicMock(return_value=True)
with patch.object(os, 'umask', mock):
with patch.object(state, '_set_retcode', mock):
with patch.dict(state.__opts__, {'test': True}):
with patch('salt.utils.files.fopen', mock_open()):
self.assertTrue(state.sls('core,edit.vim dev', None, None, True))
|
'Test to execute a packaged state run'
| def test_pkg(self):
| mock = MagicMock(side_effect=[False, True, True, True, True, True, True, True])
with patch.object(os.path, 'isfile', mock):
with patch('salt.modules.state.tarfile', MockTarFile):
with patch('salt.modules.state.json', MockJson()):
self.assertEqual(state.pkg('/tmp/state_pkg.tgz', '', 'md5'), {})
mock = MagicMock(side_effect=[False, 0, 0, 0, 0])
with patch.object(salt.utils, 'get_hash', mock):
self.assertDictEqual(state.pkg('/tmp/state_pkg.tgz', '', 'md5'), {})
self.assertDictEqual(state.pkg('/tmp/state_pkg.tgz', 0, 'md5'), {})
MockTarFile.path = ''
MockJson.flag = True
with patch('salt.utils.files.fopen', mock_open()):
self.assertListEqual(state.pkg('/tmp/state_pkg.tgz', 0, 'md5'), [True])
MockTarFile.path = ''
MockJson.flag = False
with patch('salt.utils.files.fopen', mock_open()):
self.assertTrue(state.pkg('/tmp/state_pkg.tgz', 0, 'md5'))
|
'Test to halt a running system'
| def test_halt(self):
| mock = MagicMock(return_value='salt')
with patch.object(win_system, 'shutdown', mock):
self.assertEqual(win_system.halt(), 'salt')
|
'Test to change the system runlevel on sysV compatible systems'
| def test_init(self):
| self.assertEqual(win_system.init(3), 'Not implemented on Windows at this time.')
|
'Test to poweroff a running system'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_poweroff(self):
| mock = MagicMock(return_value='salt')
with patch.object(win_system, 'shutdown', mock):
self.assertEqual(win_system.poweroff(), 'salt')
|
'Test to reboot the system'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_reboot(self):
| with patch('salt.modules.win_system.shutdown', MagicMock(return_value=True)) as shutdown:
self.assertEqual(win_system.reboot(), True)
|
'Test to reboot the system with a timeout'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_reboot_with_timeout_in_minutes(self):
| with patch('salt.modules.win_system.shutdown', MagicMock(return_value=True)) as shutdown:
self.assertEqual(win_system.reboot(5, in_seconds=False), True)
shutdown.assert_called_with(timeout=5, in_seconds=False, reboot=True, only_on_pending_reboot=False)
|
'Test to reboot the system with a timeout'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_reboot_with_timeout_in_seconds(self):
| with patch('salt.modules.win_system.shutdown', MagicMock(return_value=True)) as shutdown:
self.assertEqual(win_system.reboot(5, in_seconds=True), True)
shutdown.assert_called_with(timeout=5, in_seconds=True, reboot=True, only_on_pending_reboot=False)
|
'Test to reboot the system with a timeout and
wait for it to finish'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_reboot_with_wait(self):
| with patch('salt.modules.win_system.shutdown', MagicMock(return_value=True)):
with patch('salt.modules.win_system.time.sleep', MagicMock()) as time:
self.assertEqual(win_system.reboot(wait_for_reboot=True), True)
time.assert_called_with(330)
|
'Test to shutdown a running system'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_shutdown(self):
| with patch('salt.modules.win_system.win32api.InitiateSystemShutdown', MagicMock()):
self.assertEqual(win_system.shutdown(), True)
|
'Test to shutdown a running system with no timeout or warning'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_shutdown_hard(self):
| with patch('salt.modules.win_system.shutdown', MagicMock(return_value=True)) as shutdown:
self.assertEqual(win_system.shutdown_hard(), True)
shutdown.assert_called_with(timeout=0)
|
'Test to set the Windows computer name'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_set_computer_name(self):
| with patch('salt.modules.win_system.windll.kernel32.SetComputerNameExW', MagicMock(return_value=True)):
with patch.object(win_system, 'get_computer_name', MagicMock(return_value='salt')):
with patch.object(win_system, 'get_pending_computer_name', MagicMock(return_value='salt_new')):
self.assertDictEqual(win_system.set_computer_name('salt_new'), {'Computer Name': {'Current': 'salt', 'Pending': 'salt_new'}})
with patch('salt.modules.win_system.windll.kernel32.SetComputerNameExW', MagicMock(return_value=False)):
self.assertFalse(win_system.set_computer_name('salt'))
|
'Test to get a pending computer name.'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_get_pending_computer_name(self):
| with patch.object(win_system, 'get_computer_name', MagicMock(return_value='salt')):
reg_mock = MagicMock(return_value={'vdata': 'salt'})
with patch.dict(win_system.__salt__, {'reg.read_value': reg_mock}):
self.assertFalse(win_system.get_pending_computer_name())
reg_mock = MagicMock(return_value={'vdata': 'salt_pending'})
with patch.dict(win_system.__salt__, {'reg.read_value': reg_mock}):
self.assertEqual(win_system.get_pending_computer_name(), 'salt_pending')
|
'Test to get the Windows computer name'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_get_computer_name(self):
| with patch('salt.modules.win_system.win32api.GetComputerNameEx', MagicMock(side_effect=['computer name', ''])):
self.assertEqual(win_system.get_computer_name(), 'computer name')
self.assertFalse(win_system.get_computer_name())
|
'Test to set the Windows computer description'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_set_computer_desc(self):
| mock = MagicMock(return_value=True)
with patch.dict(win_system.__salt__, {'cmd.run': mock}):
mock = MagicMock(return_value="Salt's comp")
with patch.object(win_system, 'get_computer_desc', mock):
self.assertDictEqual(win_system.set_computer_desc("Salt's comp"), {'Computer Description': "Salt's comp"})
|
'Test to get the Windows computer description'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_get_computer_desc(self):
| with patch('salt.modules.win_system.get_system_info', MagicMock(side_effect=[{'description': 'salt description'}, {'description': None}])):
self.assertEqual(win_system.get_computer_desc(), 'salt description')
self.assertFalse(win_system.get_computer_desc())
|
'Test to join a computer to an Active Directory domain'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs w32net and other windows libraries')
def test_join_domain(self):
| with patch('salt.modules.win_system._join_domain', MagicMock(return_value=0)):
with patch('salt.modules.win_system.get_domain_workgroup', MagicMock(return_value={'Workgroup': 'Workgroup'})):
self.assertDictEqual(win_system.join_domain('saltstack', 'salt', 'salt@123'), {'Domain': 'saltstack', 'Restart': False})
with patch('salt.modules.win_system.get_domain_workgroup', MagicMock(return_value={'Domain': 'saltstack'})):
self.assertEqual(win_system.join_domain('saltstack', 'salt', 'salt@123'), 'Already joined to saltstack')
|
'Test to get system time'
| def test_get_system_time(self):
| tm = datetime.strftime(datetime.now(), '%I:%M:%S %p')
win_tm = win_system.get_system_time()
try:
self.assertEqual(win_tm, tm)
except AssertionError:
import re
self.assertTrue(re.search('^\\d{2}:\\d{2} \\w{2}$', win_tm))
|
'Test to set system time'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_set_system_time(self):
| with patch('salt.modules.win_system.set_system_date_time', MagicMock(side_effect=[False, True])):
self.assertFalse(win_system.set_system_time('11:31:15 AM'))
self.assertTrue(win_system.set_system_time('11:31:15 AM'))
|
'Test to get system date'
| def test_get_system_date(self):
| date = datetime.strftime(datetime.now(), '%m/%d/%Y')
self.assertEqual(win_system.get_system_date(), date)
|
'Test to set system date'
| @skipIf((not win_system.HAS_WIN32NET_MODS), 'this test needs the w32net library')
def test_set_system_date(self):
| with patch('salt.modules.win_system.set_system_date_time', MagicMock(side_effect=[False, True])):
self.assertFalse(win_system.set_system_date('03-28-13'))
self.assertTrue(win_system.set_system_date('03-28-13'))
|
'Test to start the Windows time service'
| def test_start_time_service(self):
| mock = MagicMock(return_value=True)
with patch.dict(win_system.__salt__, {'service.start': mock}):
self.assertTrue(win_system.start_time_service())
|
'Test to stop the windows time service'
| def test_stop_time_service(self):
| mock = MagicMock(return_value=True)
with patch.dict(win_system.__salt__, {'service.stop': mock}):
self.assertTrue(win_system.stop_time_service())
|
'Test setting a new hostname'
| def test_set_hostname(self):
| cmd_run_mock = MagicMock(return_value='Method execution successful.')
get_hostname = MagicMock(return_value='MINION')
with patch.dict(win_system.__salt__, {'cmd.run': cmd_run_mock}):
with patch.object(win_system, 'get_hostname', get_hostname):
win_system.set_hostname('NEW')
cmd_run_mock.assert_called_once_with(cmd="wmic computersystem where name='MINION' call rename name='NEW'")
|
'Test setting a new hostname'
| def test_get_hostname(self):
| cmd_run_mock = MagicMock(return_value='MINION')
with patch.dict(win_system.__salt__, {'cmd.run': cmd_run_mock}):
ret = win_system.get_hostname()
self.assertEqual(ret, 'MINION')
cmd_run_mock.assert_called_once_with(cmd='hostname')
|
'Compares the two list of dictionaries to ensure they have same content. Returns True
if there is difference, else False'
| def _diff_list_dicts(self, listdict1, listdict2, sortkey):
| if (len(listdict1) != len(listdict2)):
return True
listdict1_sorted = sorted(listdict1, key=(lambda x: x[sortkey]))
listdict2_sorted = sorted(listdict2, key=(lambda x: x[sortkey]))
for (item1, item2) in zip(listdict1_sorted, listdict2_sorted):
if (len((set(item1) & set(item2))) != len(set(item2))):
return True
return False
|
'Tests checking an apigateway rest api existence when api\'s name exists'
| def test_that_when_checking_if_a_rest_api_exists_and_a_rest_api_exists_the_api_exists_method_returns_true(self):
| self.conn.get_rest_apis.return_value = {'items': [{'name': 'myapi', 'id': '1234def'}]}
api_exists_result = boto_apigateway.api_exists(name='myapi', **conn_parameters)
self.assertTrue(api_exists_result['exists'])
|
'Tests checking an apigateway rest api existence when multiple api\'s with same name exists'
| def test_that_when_checking_if_a_rest_api_exists_and_multiple_rest_api_exist_the_api_exists_method_returns_true(self):
| self.conn.get_rest_apis.return_value = {'items': [{'name': 'myapi', 'id': '1234abc'}, {'name': 'myapi', 'id': '1234def'}]}
api_exists_result = boto_apigateway.api_exists(name='myapi', **conn_parameters)
self.assertTrue(api_exists_result['exists'])
|
'Tests checking an apigateway rest api existence when no matching rest api name exists'
| def test_that_when_checking_if_a_rest_api_exists_and_no_rest_api_exists_the_api_exists_method_returns_false(self):
| self.conn.get_rest_apis.return_value = {'items': [{'name': 'myapi', 'id': '1234abc'}, {'name': 'myapi', 'id': '1234def'}]}
api_exists_result = boto_apigateway.api_exists(name='myapi123', **conn_parameters)
self.assertFalse(api_exists_result['exists'])
|
'Tests that all rest apis defined for a region is returned'
| def test_that_when_describing_rest_apis_and_no_name_given_the_describe_apis_method_returns_list_of_all_rest_apis(self):
| self.conn.get_rest_apis.return_value = {u'items': [{u'description': u'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'id': u'2ut6i4vyle', u'name': u'Swagger Petstore'}, {u'description': u'testingabcd', u'createdDate': datetime.datetime(2015, 12, 3, 21, 57, 58), u'id': u'g41ls77hz0', u'name': u'testingabc'}, {u'description': u'a simple food delivery service test', u'createdDate': datetime.datetime(2015, 11, 4, 23, 57, 28), u'id': u'h7pbwydho9', u'name': u'Food Delivery Service'}, {u'description': u'Created by AWS Lambda', u'createdDate': datetime.datetime(2015, 11, 4, 17, 55, 41), u'id': u'i2yyd1ldvj', u'name': u'LambdaMicroservice'}, {u'description': u'cloud tap service with combination of API GW and Lambda', u'createdDate': datetime.datetime(2015, 11, 17, 22, 3, 18), u'id': u'rm06h9oac4', u'name': u'API Gateway Cloudtap Service'}, {u'description': u'testing1234', u'createdDate': datetime.datetime(2015, 12, 2, 19, 51, 44), u'id': u'vtir6ssxvd', u'name': u'testing123'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
items = self.conn.get_rest_apis.return_value['items']
get_apis_result = boto_apigateway.describe_apis(**conn_parameters)
items_dt = [boto_apigateway._convert_datetime_str(item) for item in items]
apis = get_apis_result.get('restapi')
diff = self._diff_list_dicts(apis, items_dt, 'id')
self.assertTrue(apis)
self.assertEqual(len(apis), len(items))
self.assertFalse(diff)
|
'Tests that exactly 2 apis are returned matching \'testing123\''
| def test_that_when_describing_rest_apis_and_name_is_testing123_the_describe_apis_method_returns_list_of_two_rest_apis(self):
| self.conn.get_rest_apis.return_value = {u'items': [{u'description': u'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'id': u'2ut6i4vyle', u'name': u'Swagger Petstore'}, {u'description': u'testingabcd', u'createdDate': datetime.datetime(2015, 12, 3, 21, 57, 58), u'id': u'g41ls77hz0', u'name': u'testing123'}, {u'description': u'a simple food delivery service test', u'createdDate': datetime.datetime(2015, 11, 4, 23, 57, 28), u'id': u'h7pbwydho9', u'name': u'Food Delivery Service'}, {u'description': u'Created by AWS Lambda', u'createdDate': datetime.datetime(2015, 11, 4, 17, 55, 41), u'id': u'i2yyd1ldvj', u'name': u'LambdaMicroservice'}, {u'description': u'cloud tap service with combination of API GW and Lambda', u'createdDate': datetime.datetime(2015, 11, 17, 22, 3, 18), u'id': u'rm06h9oac4', u'name': u'API Gateway Cloudtap Service'}, {u'description': u'testing1234', u'createdDate': datetime.datetime(2015, 12, 2, 19, 51, 44), u'id': u'vtir6ssxvd', u'name': u'testing123'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
expected_items = [{u'description': u'testingabcd', u'createdDate': datetime.datetime(2015, 12, 3, 21, 57, 58), u'id': u'g41ls77hz0', u'name': u'testing123'}, {u'description': u'testing1234', u'createdDate': datetime.datetime(2015, 12, 2, 19, 51, 44), u'id': u'vtir6ssxvd', u'name': u'testing123'}]
get_apis_result = boto_apigateway.describe_apis(name='testing123', **conn_parameters)
expected_items_dt = [boto_apigateway._convert_datetime_str(item) for item in expected_items]
apis = get_apis_result.get('restapi')
diff = self._diff_list_dicts(apis, expected_items_dt, 'id')
self.assertTrue(apis)
self.assertIs(diff, False)
|
'Tests that no apis are returned matching \'testing123\''
| def test_that_when_describing_rest_apis_and_name_is_testing123_the_describe_apis_method_returns_no_matching_items(self):
| self.conn.get_rest_apis.return_value = {u'items': [{u'description': u'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'id': u'2ut6i4vyle', u'name': u'Swagger Petstore'}, {u'description': u'a simple food delivery service test', u'createdDate': datetime.datetime(2015, 11, 4, 23, 57, 28), u'id': u'h7pbwydho9', u'name': u'Food Delivery Service'}, {u'description': u'Created by AWS Lambda', u'createdDate': datetime.datetime(2015, 11, 4, 17, 55, 41), u'id': u'i2yyd1ldvj', u'name': u'LambdaMicroservice'}, {u'description': u'cloud tap service with combination of API GW and Lambda', u'createdDate': datetime.datetime(2015, 11, 17, 22, 3, 18), u'id': u'rm06h9oac4', u'name': u'API Gateway Cloudtap Service'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
get_apis_result = boto_apigateway.describe_apis(name='testing123', **conn_parameters)
apis = get_apis_result.get('restapi')
self.assertFalse(apis)
|
'test True if rest api is created'
| def test_that_when_creating_a_rest_api_succeeds_the_create_api_method_returns_true(self):
| created_date = datetime.datetime.now()
assigned_api_id = 'created_api_id'
self.conn.create_rest_api.return_value = {u'description': u'unit-testing1234', u'createdDate': created_date, u'id': assigned_api_id, u'name': u'unit-testing123', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
create_api_result = boto_apigateway.create_api(name='unit-testing123', description='unit-testing1234', **conn_parameters)
api = create_api_result.get('restapi')
self.assertTrue(create_api_result.get('created'))
self.assertTrue(api)
self.assertEqual(api['id'], assigned_api_id)
self.assertEqual(api['createdDate'], '{0}'.format(created_date))
self.assertEqual(api['name'], 'unit-testing123')
self.assertEqual(api['description'], 'unit-testing1234')
|
'test True for rest api creation error.'
| def test_that_when_creating_a_rest_api_fails_the_create_api_method_returns_error(self):
| self.conn.create_rest_api.side_effect = ClientError(error_content, 'create_rest_api')
create_api_result = boto_apigateway.create_api(name='unit-testing123', description='unit-testing1234', **conn_parameters)
api = create_api_result.get('restapi')
self.assertEqual(create_api_result.get('error').get('message'), error_message.format('create_rest_api'))
|
'test True if the deleted count for "testing123" api is 2.'
| def test_that_when_deleting_rest_apis_and_name_is_testing123_matching_two_apis_the_delete_api_method_returns_delete_count_of_two(self):
| self.conn.get_rest_apis.return_value = {u'items': [{u'description': u'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'id': u'2ut6i4vyle', u'name': u'Swagger Petstore'}, {u'description': u'testingabcd', u'createdDate': datetime.datetime(2015, 12, 3, 21, 57, 58), u'id': u'g41ls77hz0', u'name': u'testing123'}, {u'description': u'a simple food delivery service test', u'createdDate': datetime.datetime(2015, 11, 4, 23, 57, 28), u'id': u'h7pbwydho9', u'name': u'Food Delivery Service'}, {u'description': u'Created by AWS Lambda', u'createdDate': datetime.datetime(2015, 11, 4, 17, 55, 41), u'id': u'i2yyd1ldvj', u'name': u'LambdaMicroservice'}, {u'description': u'cloud tap service with combination of API GW and Lambda', u'createdDate': datetime.datetime(2015, 11, 17, 22, 3, 18), u'id': u'rm06h9oac4', u'name': u'API Gateway Cloudtap Service'}, {u'description': u'testing1234', u'createdDate': datetime.datetime(2015, 12, 2, 19, 51, 44), u'id': u'vtir6ssxvd', u'name': u'testing123'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
self.conn.delete_rest_api.return_value = None
delete_api_result = boto_apigateway.delete_api(name='testing123', **conn_parameters)
self.assertTrue(delete_api_result.get('deleted'))
self.assertEqual(delete_api_result.get('count'), 2)
|
'Test that the given api name doesn\'t exists, and delete_api should return deleted status of False'
| def test_that_when_deleting_rest_apis_and_name_given_provides_no_match_the_delete_api_method_returns_false(self):
| self.conn.get_rest_apis.return_value = {u'items': [{u'description': u'testing1234', u'createdDate': datetime.datetime(2015, 12, 2, 19, 51, 44), u'id': u'vtir6ssxvd', u'name': u'testing1234'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
self.conn.delete_rest_api.return_value = None
delete_api_result = boto_apigateway.delete_api(name='testing123', **conn_parameters)
self.assertFalse(delete_api_result.get('deleted'))
|
'tests True if all api_keys are returned.'
| def test_that_describing_api_keys_the_describe_api_keys_method_returns_all_api_keys(self):
| self.conn.get_api_keys.return_value = {u'items': [{u'description': u'test-lambda-api-key', u'enabled': True, u'stageKeys': [u'123yd1l123/test'], u'lastUpdatedDate': datetime.datetime(2015, 11, 4, 19, 22, 18), u'createdDate': datetime.datetime(2015, 11, 4, 19, 21, 7), u'id': u'88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', u'name': u'test-salt-key'}, {u'description': u'testing_salt_123', u'enabled': True, u'stageKeys': [], u'lastUpdatedDate': datetime.datetime(2015, 12, 5, 0, 14, 49), u'createdDate': datetime.datetime(2015, 12, 4, 22, 29, 33), u'id': u'999999989b8cNSp4505pL6OgDe3oW7oY29Z3eIZ4', u'name': u'testing_salt'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
items = self.conn.get_api_keys.return_value['items']
get_api_keys_result = boto_apigateway.describe_api_keys(**conn_parameters)
items_dt = [boto_apigateway._convert_datetime_str(item) for item in items]
api_keys = get_api_keys_result.get('apiKeys')
diff = False
if (len(api_keys) != len(items)):
diff = True
else:
diff = self._diff_list_dicts(api_keys, items_dt, 'id')
self.assertTrue(api_keys)
self.assertIs(diff, False)
|
'test True for describe api keys error.'
| def test_that_describing_api_keys_fails_the_desribe_api_keys_method_returns_error(self):
| self.conn.get_api_keys.side_effect = ClientError(error_content, 'get_api_keys')
result = boto_apigateway.describe_api_keys(**conn_parameters)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('get_api_keys'))
|
'tests True if the key is found.'
| def test_that_describing_an_api_key_the_describe_api_key_method_returns_matching_api_key(self):
| self.conn.get_api_key.return_value = api_key_ret
result = boto_apigateway.describe_api_key(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', **conn_parameters)
self.assertEqual(result.get('apiKey', {}).get('id'), self.conn.get_api_key.return_value.get('id'))
|
'test True for error being thrown.'
| def test_that_describing_an_api_key_that_does_not_exists_the_desribe_api_key_method_returns_error(self):
| self.conn.get_api_key.side_effect = ClientError(error_content, 'get_api_keys')
result = boto_apigateway.describe_api_key(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', **conn_parameters)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('get_api_keys'))
|
'tests that we can successfully create an api key and the createDat and lastUpdateDate are
converted to string'
| def test_that_when_creating_an_api_key_succeeds_the_create_api_key_method_returns_true(self):
| now = datetime.datetime.now()
self.conn.create_api_key.return_value = {u'description': u'test-lambda-api-key', u'enabled': True, u'stageKeys': [u'123yd1l123/test'], u'lastUpdatedDate': now, u'createdDate': now, u'id': u'88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', u'name': u'test-salt-key', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}}
create_api_key_result = boto_apigateway.create_api_key('test-salt-key', 'test-lambda-api-key', **conn_parameters)
api_key = create_api_key_result.get('apiKey')
now_str = '{0}'.format(now)
self.assertTrue(create_api_key_result.get('created'))
self.assertEqual(api_key.get('lastUpdatedDate'), now_str)
self.assertEqual(api_key.get('createdDate'), now_str)
|
'tests that we properly handle errors when create an api key fails.'
| def test_that_when_creating_an_api_key_fails_the_create_api_key_method_returns_error(self):
| self.conn.create_api_key.side_effect = ClientError(error_content, 'create_api_key')
create_api_key_result = boto_apigateway.create_api_key('test-salt-key', 'unit-testing1234')
api_key = create_api_key_result.get('apiKey')
self.assertFalse(api_key)
self.assertIs(create_api_key_result.get('created'), False)
self.assertEqual(create_api_key_result.get('error').get('message'), error_message.format('create_api_key'))
|
'test True if the api key is successfully deleted.'
| def test_that_when_deleting_an_api_key_that_exists_the_delete_api_key_method_returns_true(self):
| self.conn.delete_api_key.return_value = {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
result = boto_apigateway.delete_api_key(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', **conn_parameters)
self.assertTrue(result.get('deleted'))
|
'Test that the given api key doesn\'t exists, and delete_api_key should return deleted status of False'
| def test_that_when_deleting_an_api_key_that_does_not_exist_the_delete_api_key_method_returns_false(self):
| self.conn.delete_api_key.side_effect = ClientError(error_content, 'delete_api_key')
result = boto_apigateway.delete_api_key(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', **conn_parameters)
self.assertFalse(result.get('deleted'))
|
'Test True if api key descriptipn update is successful'
| def test_that_when_updating_an_api_key_description_successfully_the_update_api_key_description_method_returns_true(self):
| self.conn.update_api_key.return_value = api_key_ret
result = boto_apigateway.update_api_key_description(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', description='test-lambda-api-key', **conn_parameters)
self.assertTrue(result.get('updated'))
|
'Test False if api key doesn\'t exists for the update request'
| def test_that_when_updating_an_api_key_description_for_a_key_that_does_not_exist_the_update_api_key_description_method_returns_false(self):
| self.conn.update_api_key.side_effect = ClientError(error_content, 'update_api_key')
result = boto_apigateway.update_api_key_description(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', description='test-lambda-api-key', **conn_parameters)
self.assertFalse(result.get('updated'))
|
'Test True for the status of the enabled flag of the returned api key'
| def test_that_when_enabling_an_api_key_that_exists_the_enable_api_key_method_returns_api_key(self):
| self.conn.update_api_key.return_value = api_key_ret
result = boto_apigateway.enable_api_key(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', **conn_parameters)
self.assertTrue(result.get('apiKey', {}).get('enabled'))
|
'Test Equality of the returned value of \'erorr\''
| def test_that_when_enabling_an_api_key_that_does_not_exist_the_enable_api_key_method_returns_error(self):
| self.conn.update_api_key.side_effect = ClientError(error_content, 'update_api_key')
result = boto_apigateway.enable_api_key(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', **conn_parameters)
self.assertEqual(result.get('error').get('message'), error_message.format('update_api_key'))
|
'Test False for the status of the enabled flag of the returned api key'
| def test_that_when_disabling_an_api_key_that_exists_the_disable_api_key_method_returns_api_key(self):
| self.conn.update_api_key.return_value = api_key_ret.copy()
self.conn.update_api_key.return_value['enabled'] = False
result = boto_apigateway.disable_api_key(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', **conn_parameters)
self.assertFalse(result.get('apiKey', {}).get('enabled'))
|
'Test Equality of the returned value of \'erorr\''
| def test_that_when_disabling_an_api_key_that_does_not_exist_the_disable_api_key_method_returns_error(self):
| self.conn.update_api_key.side_effect = ClientError(error_content, 'update_api_key')
result = boto_apigateway.disable_api_key(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', **conn_parameters)
self.assertEqual(result.get('error').get('message'), error_message.format('update_api_key'))
|
'Test True for returned value of \'associated\''
| def test_that_when_associating_stages_to_an_api_key_that_exists_the_associate_api_key_stagekeys_method_returns_true(self):
| self.conn.update_api_key.retuen_value = api_key_ret
result = boto_apigateway.associate_api_key_stagekeys(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', stagekeyslist=[u'123yd1l123/test'], **conn_parameters)
self.assertTrue(result.get('associated'))
|
'Test False returned value of \'associated\''
| def test_that_when_associating_stages_to_an_api_key_that_does_not_exist_the_associate_api_key_stagekeys_method_returns_false(self):
| self.conn.update_api_key.side_effect = ClientError(error_content, 'update_api_key')
result = boto_apigateway.associate_api_key_stagekeys(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', stagekeyslist=[u'123yd1l123/test'], **conn_parameters)
self.assertFalse(result.get('associated'))
|
'Test True for returned value of \'associated\''
| def test_that_when_disassociating_stages_to_an_api_key_that_exists_the_disassociate_api_key_stagekeys_method_returns_true(self):
| self.conn.update_api_key.retuen_value = None
result = boto_apigateway.disassociate_api_key_stagekeys(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', stagekeyslist=[u'123yd1l123/test'], **conn_parameters)
self.assertTrue(result.get('disassociated'))
|
'Test False returned value of \'associated\''
| def test_that_when_disassociating_stages_to_an_api_key_that_does_not_exist_the_disassociate_api_key_stagekeys_method_returns_false(self):
| self.conn.update_api_key.side_effect = ClientError(error_content, 'update_api_key')
result = boto_apigateway.disassociate_api_key_stagekeys(apiKey='88883333amaa1ZMVGCoLeaTrQk8kzOC36vCgRcT2', stagekeyslist=[u'123yd1l123/test'], **conn_parameters)
self.assertFalse(result.get('disassociated'))
|
'Test Equality for number of deployments is 2'
| def test_that_when_describing_api_deployments_the_describe_api_deployments_method_returns_list_of_deployments(self):
| self.conn.get_deployments.return_value = {u'items': [{u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'id': u'n05smo'}, {u'createdDate': datetime.datetime(2015, 12, 2, 19, 51, 44), u'id': u'n05sm1'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
result = boto_apigateway.describe_api_deployments(restApiId='rm06h9oac4', **conn_parameters)
self.assertEqual(len(result.get('deployments', {})), 2)
|
'Test Equality of error returned'
| def test_that_when_describing_api_deployments_and_an_error_occurred_the_describe_api_deployments_method_returns_error(self):
| self.conn.get_deployments.side_effect = ClientError(error_content, 'get_deployments')
result = boto_apigateway.describe_api_deployments(restApiId='rm06h9oac4', **conn_parameters)
self.assertEqual(result.get('error').get('message'), error_message.format('get_deployments'))
|
'Test True for the returned deployment'
| def test_that_when_describing_an_api_deployment_the_describe_api_deployment_method_returns_the_deployment(self):
| self.conn.get_deployment.return_value = {u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'id': u'n05smo', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}}
result = boto_apigateway.describe_api_deployment(restApiId='rm06h9oac4', deploymentId='n05smo', **conn_parameters)
self.assertTrue(result.get('deployment'))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.