desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test to build an interface script for a network interface.'
def test_build_interface(self):
with patch.dict(rh_ip.__grains__, {'os': 'Fedora'}): with patch.object(rh_ip, '_raise_error_iface', return_value=None): self.assertRaises(AttributeError, rh_ip.build_interface, 'iface', 'slave', True) with patch.dict(rh_ip.__salt__, {'network.interfaces': (lambda : {'eth': True})}): ...
'Test to build a route script for a network interface.'
def test_build_routes(self):
with patch.dict(rh_ip.__grains__, {'osrelease': '5.0'}): with patch.object(rh_ip, '_parse_routes', MagicMock()): mock = jinja2.exceptions.TemplateNotFound('foo') with patch.object(jinja2.Environment, 'get_template', MagicMock(side_effect=mock)): self.assertEqual(rh_ip...
'Test to shutdown a network interface'
def test_down(self):
with patch.dict(rh_ip.__salt__, {'cmd.run': MagicMock(return_value='A')}): self.assertEqual(rh_ip.down('iface', 'iface_type'), 'A') self.assertEqual(rh_ip.down('iface', 'slave'), None)
'Test to return the content of a bond script'
def test_get_bond(self):
with patch.object(os.path, 'join', return_value='A'): with patch.object(rh_ip, '_read_file', return_value='A'): self.assertEqual(rh_ip.get_bond('iface'), 'A')
'Test to return the contents of an interface script'
def test_get_interface(self):
with patch.object(os.path, 'join', return_value='A'): with patch.object(rh_ip, '_read_file', return_value='A'): self.assertEqual(rh_ip.get_interface('iface'), 'A')
'Test to start up a network interface'
def test_up(self):
with patch.dict(rh_ip.__salt__, {'cmd.run': MagicMock(return_value='A')}): self.assertEqual(rh_ip.up('iface', 'iface_type'), 'A') self.assertEqual(rh_ip.up('iface', 'slave'), None)
'Test to return the contents of the interface routes script.'
def test_get_routes(self):
with patch.object(os.path, 'join', return_value='A'): with patch.object(rh_ip, '_read_file', return_value=['A']): self.assertEqual(rh_ip.get_routes('iface'), ['A', 'A'])
'Test to return the contents of the global network script.'
def test_get_network_settings(self):
with patch.object(rh_ip, '_read_file', return_value='A'): self.assertEqual(rh_ip.get_network_settings(), 'A')
'Test to apply global network configuration.'
def test_apply_network_settings(self):
with patch.dict(rh_ip.__salt__, {'service.restart': MagicMock(return_value=True)}): self.assertTrue(rh_ip.apply_network_settings())
'Test to build the global network script.'
def test_build_network_settings(self):
with patch.object(rh_ip, '_parse_rh_config', MagicMock()): with patch.object(rh_ip, '_parse_network_settings', MagicMock()): mock = jinja2.exceptions.TemplateNotFound('foo') with patch.object(jinja2.Environment, 'get_template', MagicMock(side_effect=mock)): self.asser...
'Test for Return server version from grub --version'
def test_version(self):
mock = MagicMock(return_value='out') with patch.dict(grub_legacy.__salt__, {'cmd.run': mock}): self.assertEqual(grub_legacy.version(), 'out')
'Test for Parse GRUB conf file'
def test_conf(self):
mock = MagicMock(side_effect=IOError('foo')) with patch('salt.utils.files.fopen', mock): with patch.object(grub_legacy, '_detect_conf', return_value='A'): self.assertRaises(CommandExecutionError, grub_legacy.conf) file_data = '\n'.join(['#', 'A B C D,E,F G H']) with pa...
'Test if it mount an image'
def test_mount(self):
with patch('os.path.join', MagicMock(return_value=True)): with patch('os.path.isdir', MagicMock(return_value=True)): with patch('os.listdir', MagicMock(return_value=False)): with patch.dict(guestfs.__salt__, {'cmd.run': MagicMock(return_value='')}): self.asser...
'Test to installs one or several pecl extensions.'
def test_install(self):
with patch.object(pecl, '_pecl', return_value='A'): self.assertEqual(pecl.install('fuse', force=True), 'A') self.assertFalse(pecl.install('fuse')) with patch.object(pecl, 'list_', return_value={'A': ['A', 'B']}): self.assertTrue(pecl.install(['A', 'B']))
'Test to uninstall one or several pecl extensions.'
def test_uninstall(self):
with patch.object(pecl, '_pecl', return_value='A'): self.assertEqual(pecl.uninstall('fuse'), 'A')
'Test to update one or several pecl extensions.'
def test_update(self):
with patch.object(pecl, '_pecl', return_value='A'): self.assertEqual(pecl.update('fuse'), 'A')
'Test to list installed pecl extensions.'
def test_list_(self):
with patch.object(pecl, '_pecl', return_value='A\nB'): self.assertDictEqual(pecl.list_('channel'), {})
'Test if it execute Augeas commands'
@skipIf(six.PY3, 'Disabled pending https://github.com/hercules-team/python-augeas/issues/30') def test_execute(self):
self.assertEqual(augeas_cfg.execute(), {'retval': True})
'Test if it execute Augeas commands'
def test_execute_io_error(self):
ret = {'error': 'Command is not supported (yet)', 'retval': False} self.assertEqual(augeas_cfg.execute(None, None, [' ']), ret)
'Test if it execute Augeas commands'
def test_execute_value_error(self):
ret = {'retval': False, 'error': 'Invalid formatted command, see debug log for details: '} self.assertEqual(augeas_cfg.execute(None, None, ['set ']), ret)
'Test if it get a value for a specific augeas path'
def test_get(self):
mock = MagicMock(side_effect=RuntimeError('error')) with patch.object(_Augeas, 'match', mock): self.assertEqual(augeas_cfg.get('/etc/hosts'), {'error': 'error'}) mock = MagicMock(return_value=True) with patch.object(_Augeas, 'match', mock): self.assertEqual(augeas_cfg.get('/etc/hosts'), ...
'Test if it set a value for a specific augeas path'
def test_setvalue(self):
self.assertEqual(augeas_cfg.setvalue('prefix=/etc/hosts'), {'retval': True})
'Test if it set a value for a specific augeas path'
def test_setvalue_io_error(self):
mock = MagicMock(side_effect=IOError('')) with patch.object(_Augeas, 'save', mock): self.assertEqual(augeas_cfg.setvalue('prefix=/files/etc/'), {'retval': False, 'error': ''})
'Test if it set a value for a specific augeas path'
def test_setvalue_uneven_path(self):
mock = MagicMock(side_effect=RuntimeError('error')) with patch.object(_Augeas, 'match', mock): self.assertRaises(SaltInvocationError, augeas_cfg.setvalue, ['/files/etc/hosts/1/canonical', 'localhost'])
'Test if it set a value for a specific augeas path'
def test_setvalue_one_prefix(self):
self.assertRaises(SaltInvocationError, augeas_cfg.setvalue, 'prefix=/files', '10.18.1.1', 'prefix=/etc', 'test')
'Test if it matches for path expression'
def test_match(self):
self.assertEqual(augeas_cfg.match('/etc/service', 'ssh'), {})
'Test if it matches for path expression'
def test_match_runtime_error(self):
mock = MagicMock(side_effect=RuntimeError('error')) with patch.object(_Augeas, 'match', mock): self.assertEqual(augeas_cfg.match('/etc/service-name', 'ssh'), {})
'Test if it removes for path expression'
def test_remove(self):
self.assertEqual(augeas_cfg.remove('/etc/service'), {'count': 0, 'retval': True})
'Test if it removes for path expression'
def test_remove_io_runtime_error(self):
mock = MagicMock(side_effect=RuntimeError('error')) with patch.object(_Augeas, 'save', mock): self.assertEqual(augeas_cfg.remove('/etc/service-name'), {'count': 0, 'error': 'error', 'retval': False})
'Test if it list the direct children of a node'
def test_ls(self):
self.assertEqual(augeas_cfg.ls('/etc/passwd'), {})
'Test if it returns recursively the complete tree of a node'
def test_tree(self):
self.assertEqual(augeas_cfg.tree('/etc/'), {'/etc': None})
'Tests build module using znc-buildmod'
def test_buildmod(self):
with patch('os.path.exists', MagicMock(return_value=False)): self.assertEqual(znc.buildmod('modules.cpp'), 'Error: The file (modules.cpp) does not exist.')
'Tests build module using znc-buildmod'
def test_buildmod_module(self):
mock = MagicMock(return_value='SALT') with patch.dict(znc.__salt__, {'cmd.run': mock}): with patch('os.path.exists', MagicMock(return_value=True)): self.assertEqual(znc.buildmod('modules.cpp'), 'SALT')
'Tests write the active configuration state to config file'
def test_dumpconf(self):
mock = MagicMock(return_value='SALT') with patch.dict(znc.__salt__, {'ps.pkill': mock}): self.assertEqual(znc.dumpconf(), 'SALT')
'Tests rehash the active configuration state from config file'
def test_rehashconf(self):
mock = MagicMock(return_value='SALT') with patch.dict(znc.__salt__, {'ps.pkill': mock}): self.assertEqual(znc.rehashconf(), 'SALT')
'Tests return server version from znc --version'
def test_version(self):
mock = MagicMock(return_value='ZNC 1.2 - http://znc.in') with patch.dict(znc.__salt__, {'cmd.run': mock}): self.assertEqual(znc.version(), 'ZNC 1.2')
'Test if it return information for the specified user'
def test_info(self):
mock_user_info = MagicMock(return_value={'name': 'SALT', 'password_changed': '', 'expiration_date': ''}) with patch.dict(win_shadow.__salt__, {'user.info': mock_user_info}): self.assertDictEqual(win_shadow.info('SALT'), {'name': 'SALT', 'passwd': 'Unavailable', 'lstchg': '', 'min': '', 'max': '', 'warn'...
'Test if it set the password for a named user.'
def test_set_password(self):
mock_cmd = MagicMock(return_value={'retcode': False}) mock_user_info = MagicMock(return_value={'name': 'SALT', 'password_changed': '', 'expiration_date': ''}) with patch.dict(win_shadow.__salt__, {'cmd.run_all': mock_cmd, 'user.info': mock_user_info}): self.assertTrue(win_shadow.set_password('root',...
'Test if it show current usages statistics.'
def test_getusage(self):
ret = {'message': 'No Random.org api key or api version found.', 'res': False} self.assertDictEqual(random_org.getUsage(), ret) self.assertDictEqual(random_org.getUsage(api_key='peW', api_version='1'), {'bitsLeft': None, 'requestsLeft': None, 'res': True, 'totalBits': None, 'totalReques...
'Test if it generate random integers.'
def test_generateintegers(self):
ret1 = {'message': 'No Random.org api key or api version found.', 'res': False} self.assertDictEqual(random_org.generateIntegers(), ret1) ret2 = {'message': 'Rquired argument, number is missing.', 'res': False} self.assertDictEqual(random_org.generateIntegers(api_key='pe...
'Test if it generate random strings.'
def test_generatestrings(self):
ret1 = {'message': 'No Random.org api key or api version found.', 'res': False} self.assertDictEqual(random_org.generateStrings(), ret1) ret2 = {'message': 'Required argument, number is missing.', 'res': False} self.assertDictEqual(random_org.generateStrings(api_key='peW...
'Test if it generate a list of random UUIDs.'
def test_generateuuids(self):
ret1 = {'message': 'No Random.org api key or api version found.', 'res': False} self.assertDictEqual(random_org.generateUUIDs(), ret1) ret2 = {'message': 'Required argument, number is missing.', 'res': False} self.assertDictEqual(random_org.generateUUIDs(api_key='peW', a...
'Test if it generates true random decimal fractions.'
def test_generatedecimalfractions(self):
ret1 = {'message': 'No Random.org api key or api version found.', 'res': False} self.assertDictEqual(random_org.generateDecimalFractions(), ret1) ret2 = {'message': 'Required argument, number is missing.', 'res': False} self.assertDictEqual(random_org.generateDecimalFrac...
'Test if it generates true random numbers from a Gaussian distribution (also known as a normal distribution).'
def test_generategaussians(self):
ret1 = {'message': 'No Random.org api key or api version found.', 'res': False} self.assertDictEqual(random_org.generateGaussians(), ret1) ret2 = {'message': 'Required argument, number is missing.', 'res': False} self.assertDictEqual(random_org.generateGaussians(api_key=...
'Test if it list all Slack users.'
def test_generateblobs(self):
ret1 = {'message': 'No Random.org api key or api version found.', 'res': False} self.assertDictEqual(random_org.generateBlobs(), ret1) ret2 = {'message': 'Required argument, number is missing.', 'res': False} self.assertDictEqual(random_org.generateBlobs(api_key='peW', a...
'Tests if the group already exists or not'
def test_add_group_exists(self):
mock_group = {'passwd': '*', 'gid': 0, 'name': 'test', 'members': ['root']} with patch('salt.modules.mac_group.info', MagicMock(return_value=mock_group)): self.assertRaises(CommandExecutionError, mac_group.add, 'test')
'Tests if there is whitespace in the group name'
def test_add_whitespace(self):
with patch('salt.modules.mac_group.info', MagicMock(return_value={})): self.assertRaises(SaltInvocationError, mac_group.add, 'white space')
'Tests if the group name starts with an underscore or not'
def test_add_underscore(self):
with patch('salt.modules.mac_group.info', MagicMock(return_value={})): self.assertRaises(SaltInvocationError, mac_group.add, '_Test')
'Tests if the gid is an int or not'
def test_add_gid_int(self):
with patch('salt.modules.mac_group.info', MagicMock(return_value={})): self.assertRaises(SaltInvocationError, mac_group.add, 'foo', 'foo')
'Tests if the gid is already in use or not'
def test_add_gid_exists(self):
with patch('salt.modules.mac_group.info', MagicMock(return_value={})): with patch('salt.modules.mac_group._list_gids', MagicMock(return_value=['3456'])): self.assertRaises(CommandExecutionError, mac_group.add, 'foo', 3456)
'Tests if specified group was added'
def test_add(self):
mock_ret = MagicMock(return_value=0) with patch.dict(mac_group.__salt__, {'cmd.retcode': mock_ret}): with patch('salt.modules.mac_group.info', MagicMock(return_value={})): with patch('salt.modules.mac_group._list_gids', MagicMock(return_value=[])): self.assertTrue(mac_group.a...
'Tests if there is whitespace in the group name'
def test_delete_whitespace(self):
self.assertRaises(SaltInvocationError, mac_group.delete, 'white space')
'Tests if the group name starts with an underscore or not'
def test_delete_underscore(self):
self.assertRaises(SaltInvocationError, mac_group.delete, '_Test')
'Tests if the group to be deleted exists or not'
def test_delete_group_exists(self):
with patch('salt.modules.mac_group.info', MagicMock(return_value={})): self.assertTrue(mac_group.delete('test'))
'Tests if the specified group was deleted'
def test_delete(self):
mock_ret = MagicMock(return_value=0) mock_group = {'passwd': '*', 'gid': 0, 'name': 'test', 'members': ['root']} with patch.dict(mac_group.__salt__, {'cmd.retcode': mock_ret}): with patch('salt.modules.mac_group.info', MagicMock(return_value=mock_group)): self.assertTrue(mac_group.delete...
'Tests if there is whitespace in the group name'
def test_info_whitespace(self):
self.assertRaises(SaltInvocationError, mac_group.info, 'white space')
'Tests the return of group information'
def test_info(self):
mock_getgrall = [grp.struct_group(('foo', '*', 20, ['test']))] with patch('grp.getgrall', MagicMock(return_value=mock_getgrall)): ret = {'passwd': '*', 'gid': 20, 'name': 'foo', 'members': ['test']} self.assertEqual(mac_group.info('foo'), ret)
'Tests the formatting of returned group information'
def test_format_info(self):
data = grp.struct_group(('wheel', '*', 0, ['root'])) ret = {'passwd': '*', 'gid': 0, 'name': 'wheel', 'members': ['root']} self.assertEqual(mac_group._format_info(data), ret)
'Tests the return of information on all groups'
def test_getent(self):
mock_getgrall = [grp.struct_group(('foo', '*', 20, ['test']))] with patch('grp.getgrall', MagicMock(return_value=mock_getgrall)): ret = [{'passwd': '*', 'gid': 20, 'name': 'foo', 'members': ['test']}] self.assertEqual(mac_group.getent(), ret)
'Tests if gid is an integer or not'
def test_chgid_gid_int(self):
self.assertRaises(SaltInvocationError, mac_group.chgid, 'foo', 'foo')
'Tests if the group id exists or not'
def test_chgid_group_exists(self):
mock_pre_gid = MagicMock(return_value='') with patch.dict(mac_group.__salt__, {'file.group_to_gid': mock_pre_gid}): with patch('salt.modules.mac_group.info', MagicMock(return_value={})): self.assertRaises(CommandExecutionError, mac_group.chgid, 'foo', 4376)
'Tests if the group id is the same as argument'
def test_chgid_gid_same(self):
mock_group = {'passwd': '*', 'gid': 0, 'name': 'test', 'members': ['root']} mock_pre_gid = MagicMock(return_value=0) with patch.dict(mac_group.__salt__, {'file.group_to_gid': mock_pre_gid}): with patch('salt.modules.mac_group.info', MagicMock(return_value=mock_group)): self.assertTrue(ma...
'Tests the gid for a named group was changed'
def test_chgid(self):
mock_group = {'passwd': '*', 'gid': 0, 'name': 'test', 'members': ['root']} mock_pre_gid = MagicMock(return_value=0) mock_ret = MagicMock(return_value=0) with patch.dict(mac_group.__salt__, {'file.group_to_gid': mock_pre_gid}): with patch.dict(mac_group.__salt__, {'cmd.retcode': mock_ret}): ...
'Test if it return version from nftables --version'
def test_version(self):
mock = MagicMock(return_value='nf_tables 0.3-1') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertEqual(nftables.version(), '0.3-1')
'Test if it build a well-formatted nftables rule based on kwargs.'
def test_build_rule(self):
self.assertEqual(nftables.build_rule(full='True'), 'Error: Table needs to be specified') self.assertEqual(nftables.build_rule(table='filter', full='True'), 'Error: Chain needs to be specified') self.assertEqual(nftables.build_rule(table='filter', chain='input', full='True'), 'E...
'Test if it return a data structure of the rules in the conf file'
def test_get_saved_rules(self):
with patch.dict(nftables.__grains__, {'os_family': 'Debian'}): with patch.object(salt.utils.files, 'fopen', MagicMock(mock_open())): self.assertListEqual(nftables.get_saved_rules(), [])
'Test if it return a data structure of the current, in-memory rules'
def test_get_rules(self):
mock = MagicMock(return_value='SALT STACK') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertListEqual(nftables.get_rules(), ['SALT STACK']) mock = MagicMock(return_value=False) with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertListEqual(nftables.ge...
'Test if it save the current in-memory rules to disk'
def test_save(self):
with patch.dict(nftables.__grains__, {'os_family': 'Debian'}): mock = MagicMock(return_value=False) with patch.dict(nftables.__salt__, {'cmd.run': mock}): with patch.object(salt.utils.files, 'fopen', MagicMock(mock_open())): self.assertEqual(nftables.save(), '#! nft ...
'Test if it get the handle for a particular rule'
def test_get_rule_handle(self):
self.assertEqual(nftables.get_rule_handle(), 'Error: Chain needs to be specified') self.assertEqual(nftables.get_rule_handle(chain='input'), 'Error: Rule needs to be specified') _ru = 'input tcp dport 22 log accept' ret = 'Error: table filter in f...
'Test if it check for the existence of a rule in the table and chain'
def test_check(self):
self.assertEqual(nftables.check(), 'Error: Chain needs to be specified') self.assertEqual(nftables.check(chain='input'), 'Error: Rule needs to be specified') _ru = 'input tcp dport 22 log accept' ret = 'Error: table filter in family ipv4 doe...
'Test if it check for the existence of a chain in the table'
def test_check_chain(self):
self.assertEqual(nftables.check_chain(), 'Error: Chain needs to be specified') mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertFalse(nftables.check_chain(chain='input')) mock = MagicMock(return_value='chain input {{') w...
'Test if it check for the existence of a table'
def test_check_table(self):
self.assertEqual(nftables.check_table(), 'Error: table needs to be specified') mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertFalse(nftables.check_table(table='nat')) mock = MagicMock(return_value='table ip nat') with ...
'Test if it create new custom table.'
def test_new_table(self):
self.assertEqual(nftables.new_table(table=None), 'Error: table needs to be specified') mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertEqual(nftables.new_table(table='nat'), True) mock = MagicMock(return_value='table ip nat...
'Test if it delete custom table.'
def test_delete_table(self):
self.assertEqual(nftables.delete_table(table=None), 'Error: table needs to be specified') mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertEqual(nftables.delete_table(table='nat'), 'Error: table nat in family ipv4 do...
'Test if it create new chain to the specified table.'
def test_new_chain(self):
self.assertEqual(nftables.new_chain(), 'Error: Chain needs to be specified') ret = 'Error: table filter in family ipv4 does not exist' mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertEqual(nftables.new_cha...
'Test if it create new chain to the specified table.'
def test_new_chain_variable(self):
mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): with patch('salt.modules.nftables.check_chain', MagicMock(return_value=False)): with patch('salt.modules.nftables.check_table', MagicMock(return_value=True)): self.assertEqual(nftables.ne...
'Test if it delete the chain from the specified table.'
def test_delete_chain(self):
self.assertEqual(nftables.delete_chain(), 'Error: Chain needs to be specified') ret = 'Error: table filter in family ipv4 does not exist' mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertEqual(nftables.dele...
'Test if it delete the chain from the specified table.'
def test_delete_chain_variables(self):
mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): with patch('salt.modules.nftables.check_chain', MagicMock(return_value=True)): with patch('salt.modules.nftables.check_table', MagicMock(return_value=True)): self.assertTrue(nftables.dele...
'Test if it append a rule to the specified table & chain.'
def test_append(self):
self.assertEqual(nftables.append(), 'Error: Chain needs to be specified') self.assertEqual(nftables.append(chain='input'), 'Error: Rule needs to be specified') _ru = 'input tcp dport 22 log accept' ret = 'Error: table filter in family ipv4 d...
'Test if it append a rule to the specified table & chain.'
def test_append_rule(self):
_ru = 'input tcp dport 22 log accept' mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}): with patch('salt.modules.nftables.check', MagicMock(return_value=False)): with patch('salt.modules.nftables.check_chain', MagicMock(return_v...
'Test if it insert a rule into the specified table & chain, at the specified position.'
def test_insert(self):
self.assertEqual(nftables.insert(), 'Error: Chain needs to be specified') self.assertEqual(nftables.insert(chain='input'), 'Error: Rule needs to be specified') _ru = 'input tcp dport 22 log accept' ret = 'Error: table filter in family ipv4 d...
'Test if it insert a rule into the specified table & chain, at the specified position.'
def test_insert_rule(self):
_ru = 'input tcp dport 22 log accept' mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}): with patch('salt.modules.nftables.check', MagicMock(return_value=False)): with patch('salt.modules.nftables.check_chain', MagicMock(return_v...
'Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule\'s position in the chain.'
def test_delete(self):
_ru = 'input tcp dport 22 log accept' self.assertEqual(nftables.delete(table='filter', chain='input', position='3', rule=_ru), 'Error: Only specify a position or a rule, not both') ret = 'Error: table filter in family ipv4 does not exist' ...
'Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule\'s position in the chain.'
def test_delete_rule(self):
mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}): with patch('salt.modules.nftables.check', MagicMock(return_value=True)): with patch('salt.modules.nftables.check_chain', MagicMock(return_value=True)): with patch('salt.modules.nfta...
'Test if it flush the chain in the specified table, flush all chains in the specified table if chain is not specified.'
def test_flush(self):
ret = 'Error: table filter in family ipv4 does not exist' mock = MagicMock(return_value='') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertEqual(nftables.flush(table='filter', chain='input'), ret) ret = 'Error: chain input in table filter...
'Test if it flush the chain in the specified table, flush all chains in the specified table if chain is not specified.'
def test_flush_chain(self):
mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}): with patch('salt.modules.nftables.check_chain', MagicMock(return_value=True)): with patch('salt.modules.nftables.check_table', MagicMock(return_value=True)): self.assertFalse(nftabl...
'Test for Return all installed services'
def test_get_all(self):
with patch.dict(launchctl.__salt__, {'cmd.run': MagicMock(return_value='A DCTB B DCTB C DCTB \n')}): with patch.object(launchctl, '_available_services', return_value={'A': 'a', 'B': 'b'}): self.assertEqual(launchctl.get_all(), ['A', 'B', 'C'])
'Test for Check that the given service is available.'
def test_available(self):
with patch.object(launchctl, '_service_by_name', return_value=True): self.assertTrue(launchctl.available('job_label'))
'Test for The inverse of service.available'
def test_missing(self):
with patch.object(launchctl, '_service_by_name', return_value=True): self.assertFalse(launchctl.missing('job_label'))
'Test for Return the status for a service'
def test_status(self):
launchctl_data = '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n <key>Label</key>\n <string>salt-minion</string>\n ...
'Test for Stop the specified service'
def test_stop(self):
with patch.object(launchctl, '_service_by_name', return_value={'file_path': 'A'}): with patch.dict(launchctl.__salt__, {'cmd.retcode': MagicMock(return_value=False)}): self.assertTrue(launchctl.stop('job_label')) with patch.object(launchctl, '_service_by_name', return_value=None): se...
'Test for Start the specified service'
def test_start(self):
with patch.object(launchctl, '_service_by_name', return_value={'file_path': 'A'}): with patch.dict(launchctl.__salt__, {'cmd.retcode': MagicMock(return_value=False)}): self.assertTrue(launchctl.start('job_label')) with patch.object(launchctl, '_service_by_name', return_value=None): s...
'Test for Restart the named service'
def test_restart(self):
with patch.object(launchctl, 'stop', return_value=None): with patch.object(launchctl, 'start', return_value=True): self.assertTrue(launchctl.restart('job_label'))
'Test for Boot (create) a new instance'
def test_boot(self):
self.mock_auth.side_effect = MagicMock() with patch.object(self.mock_auth, 'boot', MagicMock(return_value='A')): self.assertTrue(nova.boot('name'))
'Test for List storage volumes'
def test_volume_list(self):
self.mock_auth.side_effect = MagicMock() with patch.object(self.mock_auth, 'volume_list', MagicMock(return_value='A')): self.assertTrue(nova.volume_list())
'Test for Create a block storage volume'
def test_volume_show(self):
self.mock_auth.side_effect = MagicMock() with patch.object(self.mock_auth, 'volume_show', MagicMock(return_value='A')): self.assertTrue(nova.volume_show('name'))
'Test for Create a block storage volume'
def test_volume_create(self):
self.mock_auth.side_effect = MagicMock() with patch.object(self.mock_auth, 'volume_create', MagicMock(return_value='A')): self.assertTrue(nova.volume_create('name'))
'Test for Destroy the volume'
def test_volume_delete(self):
self.mock_auth.side_effect = MagicMock() with patch.object(self.mock_auth, 'volume_delete', MagicMock(return_value='A')): self.assertTrue(nova.volume_delete('name'))
'Test for Attach a block storage volume'
def test_volume_detach(self):
self.mock_auth.side_effect = MagicMock() with patch.object(self.mock_auth, 'volume_detach', MagicMock(return_value='A')): self.assertTrue(nova.volume_detach('name'))
'Test for Attach a block storage volume'
def test_volume_attach(self):
self.mock_auth.side_effect = MagicMock() with patch.object(self.mock_auth, 'volume_attach', MagicMock(return_value='A')): self.assertTrue(nova.volume_attach('name', 'serv_name'))