desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Test to remove a license'
| def test_remove_license(self):
| with patch.object(powerpath, 'has_powerpath', return_value=False):
self.assertDictEqual(powerpath.remove_license('key'), {'output': 'PowerPath is not installed', 'result': False, 'retcode': (-1)})
mock = MagicMock(return_value={'retcode': 1, 'stderr': 'stderr'})
with patch.object(powerpath, 'has_powerpath', return_value=True):
with patch.dict(powerpath.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(powerpath.remove_license('key'), {'output': 'stderr', 'result': False, 'retcode': 1})
|
'Test if it return the information for a specified job id'
| def test_get_jid(self):
| mock_ret = MagicMock(return_value='DB')
with patch.object(salt.loader, 'returners', MagicMock(return_value={'redis.get_jid': mock_ret})):
self.assertEqual(ret.get_jid('redis', 'net'), 'DB')
|
'Test if it return info about last time fun was called on each minion'
| def test_get_fun(self):
| mock_ret = MagicMock(return_value='DB')
with patch.object(salt.loader, 'returners', MagicMock(return_value={'mysql.get_fun': mock_ret})):
self.assertEqual(ret.get_fun('mysql', 'net'), 'DB')
|
'Test if it return a list of all job ids'
| def test_get_jids(self):
| mock_ret = MagicMock(return_value='DB')
with patch.object(salt.loader, 'returners', MagicMock(return_value={'mysql.get_jids': mock_ret})):
self.assertEqual(ret.get_jids('mysql'), 'DB')
|
'Test if it return a list of all minions'
| def test_get_minions(self):
| mock_ret = MagicMock(return_value='DB')
with patch.object(salt.loader, 'returners', MagicMock(return_value={'mysql.get_minions': mock_ret})):
self.assertEqual(ret.get_minions('mysql'), 'DB')
|
'Mock method for SendMessage'
| @staticmethod
def SendMessage(*args):
| return [args[0]]
|
'Test to rehash the Environment variables'
| def test_rehash(self):
| self.assertTrue(win_path.rehash())
|
'Test to Returns the system path'
| def test_get_path(self):
| mock = MagicMock(return_value={'vdata': 'c:\\salt'})
with patch.dict(win_path.__salt__, {'reg.read_value': mock}):
self.assertListEqual(win_path.get_path(), ['c:\\salt'])
|
'Test to check if the directory is configured'
| def test_exists(self):
| mock = MagicMock(return_value='c:\\salt')
with patch.object(win_path, 'get_path', mock):
self.assertTrue(win_path.exists('c:\\salt'))
|
'Test to add the directory to the SYSTEM path'
| def test_add(self):
| mock_get = MagicMock(return_value=['c:\\salt'])
with patch.object(win_path, 'get_path', mock_get):
mock_set = MagicMock(return_value=True)
with patch.dict(win_path.__salt__, {'reg.set_value': mock_set}):
mock_rehash = MagicMock(side_effect=[True, False])
with patch.object(win_path, 'rehash', mock_rehash):
self.assertTrue(win_path.add('c:\\salt', 1))
self.assertFalse(win_path.add('c:\\salt', 1))
|
'Test to remove the directory from the SYSTEM path'
| def test_remove(self):
| mock_get = MagicMock(side_effect=[[1], ['c:\\salt'], ['c:\\salt']])
with patch.object(win_path, 'get_path', mock_get):
self.assertTrue(win_path.remove('c:\\salt'))
mock_set = MagicMock(side_effect=[True, False])
with patch.dict(win_path.__salt__, {'reg.set_value': mock_set}):
mock_rehash = MagicMock(return_value='Salt')
with patch.object(win_path, 'rehash', mock_rehash):
self.assertEqual(win_path.remove('c:\\salt'), 'Salt')
self.assertFalse(win_path.remove('c:\\salt'))
|
'Test for SPF records which use the \'redirect\' SPF mechanism
https://en.wikipedia.org/wiki/Sender_Policy_Framework#Mechanisms'
| def test_spf_redir(self):
| dig_mock = MagicMock(side_effect=_spf_side_effect)
with patch.dict(dig.__salt__, {'cmd.run_all': dig_mock}):
self.assertEqual(dig.SPF('xmission-redirect.com'), ['198.60.22.0/24', '166.70.13.0/24'])
|
'Test for SPF records which use the \'include\' SPF mechanism
https://en.wikipedia.org/wiki/Sender_Policy_Framework#Mechanisms'
| def test_spf_include(self):
| dig_mock = MagicMock(side_effect=_spf_side_effect)
with patch.dict(dig.__salt__, {'cmd.run_all': dig_mock}):
self.assertEqual(dig.SPF('xmission.com'), ['198.60.22.0/24', '166.70.13.0/24'])
|
'Test if it show parsed configuration'
| def test_show_conf(self):
| with patch('salt.modules.logrotate._parse_conf', MagicMock(return_value=True)):
self.assertTrue(logrotate.show_conf())
|
'Test if it set a new value for a specific configuration line'
| def test_set(self):
| with patch('salt.modules.logrotate._parse_conf', MagicMock(return_value=PARSE_CONF)):
with patch.dict(logrotate.__salt__, {'file.replace': MagicMock(return_value=True)}):
self.assertTrue(logrotate.set_('rotate', '2'))
|
'Test if it fails to set a new value for a specific configuration line'
| def test_set_failed(self):
| with patch('salt.modules.logrotate._parse_conf', MagicMock(return_value=PARSE_CONF)):
kwargs = {'key': '/var/log/wtmp', 'value': 2}
self.assertRaises(SaltInvocationError, logrotate.set_, **kwargs)
|
'Test if it set a new value for a specific configuration line'
| def test_set_setting(self):
| with patch.dict(logrotate.__salt__, {'file.replace': MagicMock(return_value=True)}):
with patch('salt.modules.logrotate._parse_conf', MagicMock(return_value=PARSE_CONF)):
self.assertTrue(logrotate.set_('/var/log/wtmp', 'rotate', '2'))
|
'Test if it fails to set a new value for a specific configuration line'
| def test_set_setting_failed(self):
| with patch('salt.modules.logrotate._parse_conf', MagicMock(return_value=PARSE_CONF)):
kwargs = {'key': 'rotate', 'value': '/var/log/wtmp', 'setting': '2'}
self.assertRaises(SaltInvocationError, logrotate.set_, **kwargs)
|
'Test for rsync files from src to dst'
| def test_rsync(self):
| with patch.dict(rsync.__salt__, {'config.option': MagicMock(return_value=False)}):
self.assertRaises(SaltInvocationError, rsync.rsync, '', '')
with patch.dict(rsync.__salt__, {'config.option': MagicMock(return_value='A'), 'cmd.run_all': MagicMock(side_effect=[IOError('f'), 'A'])}):
with patch.object(rsync, '_check', return_value=['A']):
self.assertRaises(CommandExecutionError, rsync.rsync, 'a', 'b')
self.assertEqual(rsync.rsync('src', 'dst'), 'A')
|
'Test for return rsync version'
| def test_version(self):
| mock = MagicMock(side_effect=[IOError('f'), 'A B C\n'])
with patch.dict(rsync.__salt__, {'cmd.run_stdout': mock}):
self.assertRaises(CommandExecutionError, rsync.version)
self.assertEqual(rsync.version(), 'C')
|
'Mock connect method'
| def connect(self, dbase, isolation_level=None):
| self.dbase = dbase
self.isolation_level = isolation_level
return MockSqlite3()
|
'Mock connect method'
| @staticmethod
def cursor():
| return MockSqlite3()
|
'Mock connect method'
| @staticmethod
def execute(sql):
| return sql
|
'Mock connect method'
| @staticmethod
def fetchall():
| return True
|
'Tests if it return version of pysqlite.'
| def test_version(self):
| self.assertEqual(sqlite3.version(), '2.6.0')
|
'Tests if it return version of sqlite.'
| def test_sqlite_version(self):
| self.assertEqual(sqlite3.sqlite_version(), '3.8.2')
|
'Tests if it issue an SQL query to sqlite3 (with no return data).'
| def test_modify(self):
| self.assertFalse(sqlite3.modify())
self.assertTrue(sqlite3.modify('/root/test.db', 'CREATE TABLE test(id INT, testdata TEXT);'))
|
'Tests if it retrieve data from an sqlite3 db
(returns all rows, be careful!)'
| def test_fetch(self):
| self.assertFalse(sqlite3.fetch())
self.assertTrue(sqlite3.fetch('/root/test.db', 'CREATE TABLE test(id INT, testdata TEXT);'))
|
'Tests if it show all tables in the database.'
| def test_tables(self):
| self.assertFalse(sqlite3.tables())
self.assertTrue(sqlite3.tables('/root/test.db'))
|
'Tests if it show all indices in the database.'
| def test_indices(self):
| self.assertFalse(sqlite3.indices())
self.assertTrue(sqlite3.indices('/root/test.db'))
|
'Tests if it show all indices in the database,
for people with poor spelling skills'
| def test_indexes(self):
| self.assertTrue(sqlite3.indexes('/root/test.db'))
|
'Test to execute a puppet run'
| def test_run(self):
| mock = MagicMock(return_value={'A': 'B'})
with patch.object(salt.utils.args, 'clean_kwargs', mock):
mock = MagicMock(return_value={'retcode': 0})
mock_lst = MagicMock(return_value=[])
with patch.dict(puppet.__salt__, {'cmd.run_all': mock, 'cmd.run': mock_lst}):
self.assertTrue(puppet.run())
|
'Test to execute a puppet noop run'
| def test_noop(self):
| mock = MagicMock(return_value={'stderr': 'A', 'stdout': 'B'})
with patch.object(puppet, 'run', mock):
self.assertDictEqual(puppet.noop(), {'stderr': 'A', 'stdout': 'B'})
|
'Test to enable the puppet agent'
| def test_enable(self):
| mock_lst = MagicMock(return_value=[])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
mock = MagicMock(return_value=True)
with patch.object(os.path, 'isfile', mock):
mock = MagicMock(return_value=True)
with patch.object(os, 'remove', mock):
self.assertTrue(puppet.enable())
with patch.object(os, 'remove', MagicMock(side_effect=IOError)):
self.assertRaises(CommandExecutionError, puppet.enable)
self.assertFalse(puppet.enable())
|
'Test to disable the puppet agent'
| def test_disable(self):
| mock_lst = MagicMock(return_value=[])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
mock = MagicMock(side_effect=[True, False])
with patch.object(os.path, 'isfile', mock):
self.assertFalse(puppet.disable())
with patch('salt.utils.files.fopen', mock_open()):
self.assertTrue(puppet.disable())
try:
with patch('salt.utils.files.fopen', mock_open()) as m_open:
m_open.side_effect = IOError(13, 'Permission denied:', '/file')
self.assertRaises(CommandExecutionError, puppet.disable)
except StopIteration:
pass
|
'Test to display puppet agent status'
| def test_status(self):
| mock_lst = MagicMock(return_value=[])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
mock = MagicMock(side_effect=[True])
with patch.object(os.path, 'isfile', mock):
self.assertEqual(puppet.status(), 'Administratively disabled')
mock = MagicMock(side_effect=[False, True])
with patch.object(os.path, 'isfile', mock):
with patch('salt.utils.files.fopen', mock_open(read_data='1')):
mock = MagicMock(return_value=True)
with patch.object(os, 'kill', mock):
self.assertEqual(puppet.status(), 'Applying a catalog')
mock = MagicMock(side_effect=[False, True])
with patch.object(os.path, 'isfile', mock):
with patch('salt.utils.files.fopen', mock_open()):
mock = MagicMock(return_value=True)
with patch.object(os, 'kill', mock):
self.assertEqual(puppet.status(), 'Stale lockfile')
mock = MagicMock(side_effect=[False, False, True])
with patch.object(os.path, 'isfile', mock):
with patch('salt.utils.files.fopen', mock_open(read_data='1')):
mock = MagicMock(return_value=True)
with patch.object(os, 'kill', mock):
self.assertEqual(puppet.status(), 'Idle daemon')
mock = MagicMock(side_effect=[False, False, True])
with patch.object(os.path, 'isfile', mock):
with patch('salt.utils.files.fopen', mock_open()):
mock = MagicMock(return_value=True)
with patch.object(os, 'kill', mock):
self.assertEqual(puppet.status(), 'Stale pidfile')
mock = MagicMock(side_effect=[False, False, False])
with patch.object(os.path, 'isfile', mock):
self.assertEqual(puppet.status(), 'Stopped')
|
'Test to show a summary of the last puppet agent run'
| def test_summary(self):
| mock_lst = MagicMock(return_value=[])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
with patch('salt.utils.files.fopen', mock_open(read_data='resources: 1')):
self.assertDictEqual(puppet.summary(), {'resources': 1})
with patch('salt.utils.files.fopen', mock_open()) as m_open:
m_open.side_effect = IOError(13, 'Permission denied:', '/file')
self.assertRaises(CommandExecutionError, puppet.summary)
|
'Test to runs a plugin synch between the puppet master and agent'
| def test_plugin_sync(self):
| mock_lst = MagicMock(return_value=[])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
mock_lst = MagicMock(side_effect=[False, True])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
self.assertEqual(puppet.plugin_sync(), '')
self.assertTrue(puppet.plugin_sync())
|
'Test to run facter and return the results'
| def test_facts(self):
| mock_lst = MagicMock(return_value=[])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
mock_lst = MagicMock(return_value='True')
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
mock = MagicMock(return_value=['a', 'b'])
with patch.object(puppet, '_format_fact', mock):
self.assertDictEqual(puppet.facts(), {'a': 'b'})
|
'Test to run facter for a specific fact'
| def test_fact(self):
| mock_lst = MagicMock(return_value=[])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
mock_lst = MagicMock(side_effect=[False, True])
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
self.assertEqual(puppet.fact('salt'), '')
self.assertTrue(puppet.fact('salt'))
|
'Tests the creation of a dscl node'
| def test_dscl(self):
| mac_mock = MagicMock(return_value={'pid': 4948, 'retcode': 0, 'stderr': '', 'stdout': ''})
with patch.dict(mac_user.__salt__, {'cmd.run_all': mac_mock}):
with patch.dict(mac_user.__grains__, {'kernel': 'Darwin', 'osrelease': '10.9.1', 'osrelease_info': (10, 9, 1)}):
self.assertEqual(mac_user._dscl(['username', 'UniqueID', 501]), {'pid': 4948, 'retcode': 0, 'stderr': '', 'stdout': ''})
|
'Tests the availability of the next uid'
| def test_first_avail_uid(self):
| with patch('pwd.getpwall', MagicMock(return_value=self.mock_pwall)):
self.assertEqual(mac_user._first_avail_uid(), 501)
|
'Tests if the user exists or not'
| def test_add_user_exists(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value=self.mock_info_ret)):
self.assertRaises(CommandExecutionError, mac_user.add, 'test')
|
'Tests if there is whitespace in the user name'
| def test_add_whitespace(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(SaltInvocationError, mac_user.add, 'foo bar')
|
'Tests if the uid is an int'
| def test_add_uid_int(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(SaltInvocationError, mac_user.add, 'foo', 'foo')
|
'Tests if the gid is an int'
| def test_add_gid_int(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(SaltInvocationError, mac_user.add, 'foo', 20, 'foo')
|
'Tests if there is whitespace in the user name'
| def test_delete_whitespace(self):
| self.assertRaises(SaltInvocationError, mac_user.delete, 'foo bar')
|
'Tests if the user exists or not'
| def test_delete_user_exists(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertTrue(mac_user.delete('foo'))
|
'Tests the list of information for all users'
| def test_getent(self):
| with patch('pwd.getpwall', MagicMock(return_value=self.mock_pwall)):
with patch('salt.modules.mac_user.list_groups', MagicMock(return_value=['TEST_GROUP'])):
ret = [{'shell': '/usr/bin/false', 'name': '_amavisd', 'gid': 83, 'groups': ['TEST_GROUP'], 'home': '/var/virusmails', 'fullname': 'AMaViS Daemon', 'uid': 83}, {'shell': '/usr/bin/false', 'name': '_appleevents', 'gid': 55, 'groups': ['TEST_GROUP'], 'home': '/var/empty', 'fullname': 'AppleEvents Daemon', 'uid': 55}, {'shell': '/usr/bin/false', 'name': '_appowner', 'gid': 87, 'groups': ['TEST_GROUP'], 'home': '/var/empty', 'fullname': 'Application Owner', 'uid': 87}]
self.assertEqual(mac_user.getent(), ret)
|
'Tests if the uid is an int'
| def test_chuid_int(self):
| self.assertRaises(SaltInvocationError, mac_user.chuid, 'foo', 'foo')
|
'Tests if the user exists or not'
| def test_chuid_user_exists(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(CommandExecutionError, mac_user.chuid, 'foo', 4376)
|
'Tests if the user\'s uid is the same as as the argument'
| def test_chuid_same_uid(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value=self.mock_info_ret)):
self.assertTrue(mac_user.chuid('foo', 4376))
|
'Tests if the gid is an int'
| def test_chgid_int(self):
| self.assertRaises(SaltInvocationError, mac_user.chgid, 'foo', 'foo')
|
'Tests if the user exists or not'
| def test_chgid_user_exists(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(CommandExecutionError, mac_user.chgid, 'foo', 4376)
|
'Tests if the user\'s gid is the same as as the argument'
| def test_chgid_same_gid(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value=self.mock_info_ret)):
self.assertTrue(mac_user.chgid('foo', 4376))
|
'Tests if the user exists or not'
| def test_chshell_user_exists(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(CommandExecutionError, mac_user.chshell, 'foo', '/bin/bash')
|
'Tests if the user\'s shell is the same as the argument'
| def test_chshell_same_shell(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value=self.mock_info_ret)):
self.assertTrue(mac_user.chshell('foo', '/bin/bash'))
|
'Test if the user exists or not'
| def test_chhome_user_exists(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(CommandExecutionError, mac_user.chhome, 'foo', '/Users/foo')
|
'Tests if the user\'s home is the same as the argument'
| def test_chhome_same_home(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value=self.mock_info_ret)):
self.assertTrue(mac_user.chhome('foo', '/Users/foo'))
|
'Tests if the user exists or not'
| def test_chfullname_user_exists(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(CommandExecutionError, mac_user.chfullname, 'test', 'TEST USER')
|
'Tests if the user\'s full name is the same as the argument'
| def test_chfullname_same_name(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value=self.mock_info_ret)):
self.assertTrue(mac_user.chfullname('test', 'TEST USER'))
|
'Tests if the user exists or not'
| def test_chgroups_user_exists(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value={})):
self.assertRaises(CommandExecutionError, mac_user.chgroups, 'foo', 'wheel,root')
|
'Test if there is white space in groups argument'
| def test_chgroups_bad_groups(self):
| with patch('salt.modules.mac_user.info', MagicMock(return_value=self.mock_info_ret)):
self.assertRaises(SaltInvocationError, mac_user.chgroups, 'test', 'bad group')
|
'Tests if the user\'s list of groups is the same as the arguments'
| def test_chgroups_same_desired(self):
| mock_primary = MagicMock(return_value='wheel')
with patch.dict(mac_user.__salt__, {'file.gid_to_group': mock_primary}):
with patch('salt.modules.mac_user.info', MagicMock(return_value=self.mock_info_ret)):
with patch('salt.modules.mac_user.list_groups', MagicMock(return_value=('wheel', 'root'))):
self.assertTrue(mac_user.chgroups('test', 'wheel,root'))
|
'Tests the return of user information'
| def test_info(self):
| mock_pwnam = pwd.struct_passwd(('test', '*', 0, 0, 'TEST USER', '/var/test', '/bin/bash'))
ret = {'shell': '/bin/bash', 'name': 'test', 'gid': 0, 'groups': ['_TEST_GROUP'], 'home': '/var/test', 'fullname': 'TEST USER', 'uid': 0}
with patch('pwd.getpwnam', MagicMock(return_value=mock_pwnam)):
with patch('salt.modules.mac_user.list_groups', MagicMock(return_value=['_TEST_GROUP'])):
self.assertEqual(mac_user.info('root'), ret)
|
'Tests the formatting of returned user information'
| def test_format_info(self):
| data = pwd.struct_passwd(('_TEST_GROUP', '*', 83, 83, 'AMaViS Daemon', '/var/virusmails', '/usr/bin/false'))
ret = {'shell': '/usr/bin/false', 'name': '_TEST_GROUP', 'gid': 83, 'groups': ['_TEST_GROUP'], 'home': '/var/virusmails', 'fullname': 'AMaViS Daemon', 'uid': 83}
with patch('salt.modules.mac_user.list_groups', MagicMock(return_value=['_TEST_GROUP'])):
self.assertEqual(mac_user._format_info(data), ret)
|
'Tests the list of all users'
| def test_list_users(self):
| with patch('pwd.getpwall', MagicMock(return_value=self.mock_pwall)):
ret = ['_amavisd', '_appleevents', '_appowner']
self.assertEqual(mac_user.list_users(), ret)
|
'Test if it execute a defaults client run and return a dict'
| def test_get_mock(self):
| with patch.object(inspect, 'stack', MagicMock(return_value=[])):
with patch('salt.modules.defaults.get', MagicMock(return_value={'users': {'root': [0]}})):
self.assertEqual(defaults.get('core:users:root'), {'users': {'root': [0]}})
|
'Test for return the modjk version'
| def test_version(self):
| with patch.object(modjk, '_do_http', return_value={'worker.jk_version': 'mod_jk/1.2.37'}):
self.assertEqual(modjk.version(), '1.2.37')
|
'Test for get the current running config (not from disk)'
| def test_get_running(self):
| with patch.object(modjk, '_do_http', return_value={}):
self.assertDictEqual(modjk.get_running(), {})
|
'Test for dump the original configuration that was loaded from disk'
| def test_dump_config(self):
| with patch.object(modjk, '_do_http', return_value={}):
self.assertDictEqual(modjk.dump_config(), {})
|
'Test for return a list of member workers from the configuration files'
| def test_list_configured_members(self):
| with patch.object(modjk, '_do_http', return_value={}):
self.assertListEqual(modjk.list_configured_members('loadbalancer1'), [])
with patch.object(modjk, '_do_http', return_value={'worker.loadbalancer1.balance_workers': 'SALT'}):
self.assertListEqual(modjk.list_configured_members('loadbalancer1'), ['SALT'])
|
'Test for return a list of member workers and their status'
| def test_workers(self):
| with patch.object(modjk, '_do_http', return_value={'worker.list': 'Salt1,Salt2'}):
self.assertDictEqual(modjk.workers(), {})
|
'Test for set the all the workers in lbn to recover and
activate them if they are not'
| def test_recover_all(self):
| with patch.object(modjk, '_do_http', return_value={}):
self.assertDictEqual(modjk.recover_all('loadbalancer1'), {})
with patch.object(modjk, '_do_http', return_value={'worker.loadbalancer1.balance_workers': 'SALT'}):
with patch.object(modjk, 'worker_status', return_value={'activation': 'ACT', 'state': 'OK'}):
self.assertDictEqual(modjk.recover_all('loadbalancer1'), {'SALT': {'activation': 'ACT', 'state': 'OK'}})
|
'Test for reset all runtime statistics for the load balancer'
| def test_reset_stats(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.reset_stats('loadbalancer1'))
|
'Test for edit the loadbalancer settings'
| def test_lb_edit(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.lb_edit('loadbalancer1', {'vlr': 1, 'vlt': 60}))
|
'Test for stop all the given workers in the specific load balancer'
| def test_bulk_stop(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.bulk_stop(['node1', 'node2', 'node3'], 'loadbalancer1'))
|
'Test for activate all the given workers in the specific load balancer'
| def test_bulk_activate(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.bulk_activate(['node1', 'node2', 'node3'], 'loadbalancer1'))
|
'Test for disable all the given workers in the specific load balancer'
| def test_bulk_disable(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.bulk_disable(['node1', 'node2', 'node3'], 'loadbalancer1'))
|
'Test for recover all the given workers in the specific load balancer'
| def test_bulk_recover(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.bulk_recover(['node1', 'node2', 'node3'], 'loadbalancer1'))
|
'Test for return the state of the worker'
| def test_worker_status(self):
| with patch.object(modjk, '_do_http', return_value={'worker.node1.activation': 'ACT', 'worker.node1.state': 'OK'}):
self.assertDictEqual(modjk.worker_status('node1'), {'activation': 'ACT', 'state': 'OK'})
with patch.object(modjk, '_do_http', return_value={}):
self.assertFalse(modjk.worker_status('node1'))
|
'Test for set the worker to recover this module will fail
if it is in OK state'
| def test_worker_recover(self):
| with patch.object(modjk, '_do_http', return_value={}):
self.assertDictEqual(modjk.worker_recover('node1', 'loadbalancer1'), {})
|
'Test for set the worker to disable state in the lbn load balancer'
| def test_worker_disable(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.worker_disable('node1', 'loadbalancer1'))
|
'Test for set the worker to activate state in the lbn load balancer'
| def test_worker_activate(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.worker_activate('node1', 'loadbalancer1'))
|
'Test for set the worker to stopped state in the lbn load balancer'
| def test_worker_stop(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.worker_stop('node1', 'loadbalancer1'))
|
'Test for edit the worker settings'
| def test_worker_edit(self):
| with patch.object(modjk, '_do_http', return_value={'worker.result.type': 'OK'}):
self.assertTrue(modjk.worker_edit('node1', 'loadbalancer1', {'vwf': 500, 'vwd': 60}))
|
'Helper function to create a test vpc'
| def _create_vpc(self, name=None, tags=None):
| if (not self.conn):
self.conn = boto.vpc.connect_to_region(region)
vpc = self.conn.create_vpc(cidr_block)
_maybe_set_name_tag(name, vpc)
_maybe_set_tags(tags, vpc)
return vpc
|
'Helper function to create a test subnet'
| def _create_subnet(self, vpc_id, cidr_block='10.0.0.0/25', name=None, tags=None, availability_zone=None):
| if (not self.conn):
self.conn = boto.vpc.connect_to_region(region)
subnet = self.conn.create_subnet(vpc_id, cidr_block, availability_zone=availability_zone)
_maybe_set_name_tag(name, subnet)
_maybe_set_tags(tags, subnet)
return subnet
|
'Helper function to create a test internet gateway'
| def _create_internet_gateway(self, vpc_id, name=None, tags=None):
| if (not self.conn):
self.conn = boto.vpc.connect_to_region(region)
igw = self.conn.create_internet_gateway()
_maybe_set_name_tag(name, igw)
_maybe_set_tags(tags, igw)
return igw
|
'Helper function to create a test customer gateway'
| def _create_customer_gateway(self, vpc_id, name=None, tags=None):
| if (not self.conn):
self.conn = boto.vpc.connect_to_region(region)
gw = self.conn.create_customer_gateway(vpc_id)
_maybe_set_name_tag(name, gw)
_maybe_set_tags(tags, gw)
return gw
|
'Helper function to create test dchp options'
| def _create_dhcp_options(self, domain_name='example.com', domain_name_servers=None, ntp_servers=None, netbios_name_servers=None, netbios_node_type=2):
| if (not netbios_name_servers):
netbios_name_servers = ['10.0.0.1']
if (not ntp_servers):
ntp_servers = ['5.6.7.8']
if (not domain_name_servers):
domain_name_servers = ['1.2.3.4']
if (not self.conn):
self.conn = boto.vpc.connect_to_region(region)
return self.conn.create_dhcp_options(domain_name=domain_name, domain_name_servers=domain_name_servers, ntp_servers=ntp_servers, netbios_name_servers=netbios_name_servers, netbios_node_type=netbios_node_type)
|
'Helper function to create test network acl'
| def _create_network_acl(self, vpc_id):
| if (not self.conn):
self.conn = boto.vpc.connect_to_region(region)
return self.conn.create_network_acl(vpc_id)
|
'Helper function to create test network acl entry'
| def _create_network_acl_entry(self, network_acl_id, rule_number, protocol, rule_action, cidr_block, egress=None, icmp_code=None, icmp_type=None, port_range_from=None, port_range_to=None):
| if (not self.conn):
self.conn = boto.vpc.connect_to_region(region)
return self.conn.create_network_acl_entry(network_acl_id, rule_number, protocol, rule_action, cidr_block, egress=egress, icmp_code=icmp_code, icmp_type=icmp_type, port_range_from=port_range_from, port_range_to=port_range_to)
|
'Helper function to create a test route table'
| def _create_route_table(self, vpc_id, name=None, tags=None):
| if (not self.conn):
self.conn = boto.vpc.connect_to_region(region)
rtbl = self.conn.create_route_table(vpc_id)
_maybe_set_name_tag(name, rtbl)
_maybe_set_tags(tags, rtbl)
return rtbl
|
'Tests checking vpc existence via id when the vpc already exists'
| @mock_ec2
def test_that_when_checking_if_a_vpc_exists_by_id_and_a_vpc_exists_the_vpc_exists_method_returns_true(self):
| vpc = self._create_vpc()
vpc_exists_result = boto_vpc.exists(vpc_id=vpc.id, **conn_parameters)
self.assertTrue(vpc_exists_result['exists'])
|
'Tests checking vpc existence via id when the vpc does not exist'
| @mock_ec2
def test_that_when_checking_if_a_vpc_exists_by_id_and_a_vpc_does_not_exist_the_vpc_exists_method_returns_false(self):
| self._create_vpc()
vpc_exists_result = boto_vpc.exists(vpc_id='fake', **conn_parameters)
self.assertFalse(vpc_exists_result['exists'])
|
'Tests checking vpc existence via name when vpc exists'
| @mock_ec2
def test_that_when_checking_if_a_vpc_exists_by_name_and_a_vpc_exists_the_vpc_exists_method_returns_true(self):
| self._create_vpc(name='test')
vpc_exists_result = boto_vpc.exists(name='test', **conn_parameters)
self.assertTrue(vpc_exists_result['exists'])
|
'Tests checking vpc existence via name when vpc does not exist'
| @mock_ec2
def test_that_when_checking_if_a_vpc_exists_by_name_and_a_vpc_does_not_exist_the_vpc_exists_method_returns_false(self):
| self._create_vpc()
vpc_exists_result = boto_vpc.exists(name='test', **conn_parameters)
self.assertFalse(vpc_exists_result['exists'])
|
'Tests checking vpc existence via tag when vpc exists'
| @mock_ec2
def test_that_when_checking_if_a_vpc_exists_by_tags_and_a_vpc_exists_the_vpc_exists_method_returns_true(self):
| self._create_vpc(tags={'test': 'testvalue'})
vpc_exists_result = boto_vpc.exists(tags={'test': 'testvalue'}, **conn_parameters)
self.assertTrue(vpc_exists_result['exists'])
|
'Tests checking vpc existence via tag when vpc does not exist'
| @mock_ec2
def test_that_when_checking_if_a_vpc_exists_by_tags_and_a_vpc_does_not_exist_the_vpc_exists_method_returns_false(self):
| self._create_vpc()
vpc_exists_result = boto_vpc.exists(tags={'test': 'testvalue'}, **conn_parameters)
self.assertFalse(vpc_exists_result['exists'])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.