desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'This test covers cases where the replacement string is numeric, and the CLI parser yamlifies it into a numeric type. If not converted back to a string type in file.replace, a TypeError occurs when the replacemen is attempted. See https://github.com/saltstack/salt/issues/9097 for more information.'
def test_numeric_repl(self):
filemod.replace(self.tfile.name, 'Etiam', 123)
'Check that file.blockreplace works consistently on files with and without newlines at end of file.'
def test_replace_append_newline_at_eof(self):
base = 'bar' args = {'marker_start': '#start', 'marker_end': '#stop', 'content': 'baz', 'append_if_not_found': True} block = '{marker_start}\n{content}{marker_end}\n'.format(**args) expected = ((base + '\n') + block) with tempfile.NamedTemporaryFile(mode='w+') as tfile: tfile.write((base + '...
'Check that file.append works consistently on files with and without newlines at end of file.'
def test_append_newline_at_eof(self):
with tempfile.NamedTemporaryFile(mode='w+') as tfile: tfile.write('foo\n') tfile.flush() filemod.append(tfile.name, 'bar') with salt.utils.files.fopen(tfile.name) as tfile2: self.assertEqual(tfile2.read(), 'foo\nbar\n') with tempfile.NamedTemporaryFile(mode='w+') as t...
'Check various hash file formats.'
def test_extract_hash(self):
with tempfile.NamedTemporaryFile(mode='w+') as tfile: tfile.write('rc.conf ef6e82e4006dee563d98ada2a2a80a27\nead48423703509d37c4a90e6a0d53e143b6fc268 example.tar.gz\nfe05bcdcdc4928012781a5f1a2a77cbb5398e106 ./subdir/example.tar.gz\nad782ecdac770fc6eb9a62e44f90873fb97fb26b foo.tar.bz2\n') ...
'Tests if user is passed as an integer'
def test_user_to_uid_int(self):
user = 5034 ret = filemod.user_to_uid(user) self.assertEqual(ret, user)
'Tests if group is passed as an integer'
def test_group_to_gid_int(self):
group = 5034 ret = filemod.group_to_gid(group) self.assertEqual(ret, group)
'Tests that the templating engine works on string contents'
def test_apply_template_on_contents(self):
contents = 'This is a {{ template }}.' defaults = {'template': 'templated file'} ret = filemod.apply_template_on_contents(contents, template='jinja', context={'opts': filemod.__opts__}, defaults=defaults, saltenv='base') self.assertEqual(ret, 'This is a templated file.')
'Tests that when calling file.line with ``mode=replace``, the function doesn\'t stack trace if the file is empty. Should return ``False``. See Issue #31135.'
def test_replace_line_in_empty_file(self):
empty_file = tempfile.NamedTemporaryFile(delete=False, mode='w+') self.assertEqual(os.stat(empty_file.name).st_size, 0) self.assertFalse(filemod.line(empty_file.name, content='foo', match='bar', mode='replace')) empty_file.close() os.remove(empty_file.name)
'Tests that when calling file.line with ``mode=delete``, the function doesn\'t stack trace if the file is empty. Should return ``False``. See Issue #38438.'
def test_delete_line_in_empty_file(self):
empty_file = tempfile.NamedTemporaryFile(delete=False, mode='w+') self.assertEqual(os.stat(empty_file.name).st_size, 0) self.assertFalse(filemod.line(empty_file.name, content='foo', match='bar', mode='delete')) empty_file.close() os.remove(empty_file.name)
'tests the splitting of a list of rules into individual rules'
def test__split_rules(self):
rules = [OrderedDict([('ip_protocol', u'tcp'), ('from_port', 22), ('to_port', 22), ('grants', [OrderedDict([('cidr_ip', u'0.0.0.0/0')])])]), OrderedDict([('ip_protocol', u'tcp'), ('from_port', 80), ('to_port', 80), ('grants', [OrderedDict([('cidr_ip', u'0.0.0.0/0')])])])] split_rules = [{'to_port': 22, 'from_po...
'Test of creation of an EC2-Classic security group. The test ensures that a group was created with the desired name and description'
@mock_ec2 def test_create_ec2_classic(self):
group_name = _random_group_name() group_description = 'test_create_ec2_classic' boto_secgroup.create(group_name, group_description, **conn_parameters) conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) group_filter = {'group-name': group_name} secgroup_created_group = conn.get_all...
'test of creation of an EC2-VPC security group. The test ensures that a group was created in a given vpc with the desired name and description'
@mock_ec2 def test_create_ec2_vpc(self):
group_name = _random_group_name() group_description = 'test_create_ec2_vpc' boto_secgroup.create(group_name, group_description, vpc_id=vpc_id, **conn_parameters) conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) group_filter = {'group-name': group_name, 'vpc-id': vpc_id} secgroup...
'tests that given a name of a group in EC2-Classic that the correct group id will be retrieved'
@mock_ec2 def test_get_group_id_ec2_classic(self):
group_name = _random_group_name() group_description = 'test_get_group_id_ec2_classic' conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) group_classic = conn.create_security_group(name=group_name, description=group_description) group_vpc = conn.create_security_group(name=group_name, d...
'tests that given a name of a group in EC2-VPC that the correct group id will be retrieved'
@skipIf(True, 'test skipped because moto does not yet support group filters https://github.com/spulec/moto/issues/154') @mock_ec2 def test_get_group_id_ec2_vpc(self):
group_name = _random_group_name() group_description = 'test_get_group_id_ec2_vpc' conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) group_classic = conn.create_security_group(name=group_name, description=group_description) group_vpc = conn.create_security_group(name=group_name, descr...
'tests return of \'config\' when given group name. get_config returns an OrderedDict.'
@mock_ec2 def test_get_config_single_rule_group_name(self):
group_name = _random_group_name() ip_protocol = u'tcp' from_port = 22 to_port = 22 cidr_ip = u'0.0.0.0/0' rules_egress = [{'to_port': (-1), 'from_port': (-1), 'ip_protocol': u'-1', 'cidr_ip': u'0.0.0.0/0'}] conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) group = conn.cr...
'tests \'true\' existence of a group in EC2-Classic when given name'
@mock_ec2 def test_exists_true_name_classic(self):
group_name = _random_group_name() group_description = 'test_exists_true_ec2_classic' conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) group_classic = conn.create_security_group(group_name, group_description) group_vpc = conn.create_security_group(group_name, group_description, vpc_i...
'tests \'true\' existence of a group in EC2-VPC when given name and vpc_id'
@mock_ec2 def test_exists_true_name_vpc(self):
group_name = _random_group_name() group_description = 'test_exists_true_ec2_vpc' conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) conn.create_security_group(group_name, group_description, vpc_id=vpc_id) salt_exists_result = boto_secgroup.exists(name=group_name, vpc_id=vpc_id, **conn...
'tests \'false\' existence of a group in vpc when given name and vpc_id'
@mock_ec2 def test_exists_false_name_vpc(self):
group_name = _random_group_name() salt_exists_result = boto_secgroup.exists(group_name, vpc_id=vpc_id, **conn_parameters) self.assertFalse(salt_exists_result)
'tests \'true\' existence of a group when given group_id'
@mock_ec2 def test_exists_true_group_id(self):
group_name = _random_group_name() group_description = 'test_exists_true_group_id' conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) group = conn.create_security_group(group_name, group_description) salt_exists_result = boto_secgroup.exists(group_id=group.id, **conn_parameters) se...
'tests \'false\' existence of a group when given group_id'
@mock_ec2 def test_exists_false_group_id(self):
group_id = _random_group_id() salt_exists_result = boto_secgroup.exists(group_id=group_id, **conn_parameters) self.assertFalse(salt_exists_result)
'test deletion of a group in EC2-Classic. Test does the following: 1. creates two groups, in EC2-Classic and one in EC2-VPC 2. saves the group_ids to group_ids_pre_delete 3. removes the group in EC2-VPC 4. saves the group ids of groups to group_ids_post_delete 5. compares the group_ids_pre_delete and group_ids_post_del...
@mock_ec2 def test_delete_group_ec2_classic(self):
group_name = _random_group_name() group_description = 'test_delete_group_ec2_classic' conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) group_classic = conn.create_security_group(name=group_name, description=group_description) group_vpc = conn.create_security_group(name=group_name, d...
'tests ensures that _get_conn returns an boto.ec2.connection.EC2Connection object.'
@mock_ec2 def test__get_conn_true(self):
conn = boto.ec2.connect_to_region(region, **boto_conn_parameters) salt_conn = boto_secgroup._get_conn(**conn_parameters) self.assertEqual(conn.__class__, salt_conn.__class__)
'Test for install Rbenv systemwide'
def test_install(self):
with patch.object(rbenv, '_rbenv_path', return_value=True): with patch.object(rbenv, '_install_rbenv', return_value=True): with patch.object(rbenv, '_install_ruby_build', return_value=True): with patch.object(os.path, 'expanduser', return_value='A'): self.asse...
'Test for updates the current versions of Rbenv and Ruby-Build'
def test_update(self):
with patch.object(rbenv, '_rbenv_path', return_value=True): with patch.object(rbenv, '_update_rbenv', return_value=True): with patch.object(rbenv, '_update_ruby_build', return_value=True): with patch.object(os.path, 'expanduser', return_value='A'): self.assert...
'Test for check if Rbenv is installed.'
def test_is_installed(self):
with patch.object(rbenv, '_rbenv_bin', return_value='A'): with patch.dict(rbenv.__salt__, {'cmd.has_exec': MagicMock(return_value=True)}): self.assertTrue(rbenv.is_installed())
'Test for install a ruby implementation.'
def test_install_ruby(self):
with patch.dict(rbenv.__grains__, {'os': 'FreeBSD'}): with patch.dict(rbenv.__salt__, {'config.get': MagicMock(return_value='True')}): with patch.object(rbenv, '_rbenv_exec', return_value={'retcode': 0, 'stderr': 'stderr'}): with patch.object(rbenv, 'rehash', return_value=None): ...
'Test for uninstall a ruby implementation.'
def test_uninstall_ruby(self):
with patch.object(rbenv, '_rbenv_exec', return_value=None): self.assertTrue(rbenv.uninstall_ruby('ruby', 'runas'))
'Test for list the installed versions of ruby.'
def test_versions(self):
with patch.object(rbenv, '_rbenv_exec', return_value='A\nBC\nD'): self.assertListEqual(rbenv.versions(), ['A', 'BC', 'D'])
'Test for returns or sets the currently defined default ruby.'
def test_default(self):
with patch.object(rbenv, '_rbenv_exec', MagicMock(side_effect=[None, False])): self.assertTrue(rbenv.default('ruby', 'runas')) self.assertEqual(rbenv.default(), '')
'Test for list the installable versions of ruby.'
def test_list_(self):
with patch.object(rbenv, '_rbenv_exec', return_value='A\nB\nCD\n'): self.assertListEqual(rbenv.list_(), ['A', 'B', 'CD'])
'Test for run rbenv rehash to update the installed shims.'
def test_rehash(self):
with patch.object(rbenv, '_rbenv_exec', return_value=None): self.assertTrue(rbenv.rehash())
'Test for execute a ruby command with rbenv\'s shims using a specific ruby version.'
def test_do_with_ruby(self):
with patch.object(rbenv, 'do', return_value='A'): self.assertEqual(rbenv.do_with_ruby('ruby', 'cmdline'), 'A')
'Test for adding a user'
def test_add(self):
with patch.dict(useradd.__grains__, {'kernel': 'OpenBSD'}): mock_primary = MagicMock(return_value='Salt') with patch.dict(useradd.__salt__, {'file.gid_to_group': mock_primary}): mock = MagicMock(return_value={'retcode': 0}) with patch.dict(useradd.__salt__, {'cmd.run_all': mo...
'Test if user.getent already have a value'
@skipIf((HAS_PWD is False), 'The pwd module is not available') def test_getent(self):
with patch('salt.modules.useradd.__context__', MagicMock(return_value='Salt')): self.assertTrue(useradd.getent())
'Tests the return information on all users'
@skipIf((HAS_PWD is False), 'The pwd module is not available') def test_getent_user(self):
with patch('pwd.getpwall', MagicMock(return_value=[''])): ret = [{'gid': 0, 'groups': ['root'], 'home': '/root', 'name': 'root', 'passwd': 'x', 'shell': '/bin/bash', 'uid': 0, 'fullname': 'root', 'roomnumber': '', 'workphone': '', 'homephone': ''}] with patch('salt.modules.useradd._format_info', Mag...
'Test if the uid of a user change'
def test_chuid(self):
mock = MagicMock(return_value={'uid': 11}) with patch.object(useradd, 'info', mock): self.assertTrue(useradd.chuid('name', 11)) mock_run = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {'cmd.run': mock_run}): mock = MagicMock(side_effect=[{'uid': 11}, {'uid': 11}]) ...
'Test the default group of the user'
def test_chgid(self):
mock = MagicMock(return_value={'gid': 11}) with patch.object(useradd, 'info', mock): self.assertTrue(useradd.chgid('name', 11)) mock_run = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {'cmd.run': mock_run}): mock = MagicMock(side_effect=[{'gid': 22}, {'gid': 22}]) ...
'Test the default shell of user'
def test_chshell(self):
mock = MagicMock(return_value={'shell': '/bin/bash'}) with patch.object(useradd, 'info', mock): self.assertTrue(useradd.chshell('name', '/bin/bash')) mock_run = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {'cmd.run': mock_run}): mock = MagicMock(side_effect=[{'shell': ...
'Test if home directory given is same as previous home directory'
def test_chhome(self):
mock = MagicMock(return_value={'home': '/root'}) with patch.object(useradd, 'info', mock): self.assertTrue(useradd.chhome('name', '/root')) mock = MagicMock(return_value=None) with patch.dict(useradd.__salt__, {'cmd.run': mock}): mock = MagicMock(side_effect=[{'home': '/root'}, {'home': ...
'Test if user groups changed'
def test_chgroups(self):
mock = MagicMock(return_value=['wheel', 'root']) with patch.object(useradd, 'list_groups', mock): self.assertTrue(useradd.chgroups('foo', 'wheel,root')) mock = MagicMock(return_value=['wheel', 'root']) with patch.object(useradd, 'list_groups', mock): with patch.dict(useradd.__grains__, {...
'Test if the user\'s Full Name is changed'
def test_chfullname(self):
mock = MagicMock(return_value=False) with patch.object(useradd, '_get_gecos', mock): self.assertFalse(useradd.chfullname('Salt', 'SaltStack')) mock = MagicMock(return_value={'fullname': 'SaltStack'}) with patch.object(useradd, '_get_gecos', mock): self.assertTrue(useradd.chfullname('Salt...
'Test if the user\'s Room Number is changed'
def test_chroomnumber(self):
mock = MagicMock(return_value=False) with patch.object(useradd, '_get_gecos', mock): self.assertFalse(useradd.chroomnumber('salt', 1)) mock = MagicMock(return_value={'roomnumber': '1'}) with patch.object(useradd, '_get_gecos', mock): self.assertTrue(useradd.chroomnumber('salt', 1)) m...
'Test if the user\'s Work Phone is changed'
def test_chworkphone(self):
mock = MagicMock(return_value=False) with patch.object(useradd, '_get_gecos', mock): self.assertFalse(useradd.chworkphone('salt', 1)) mock = MagicMock(return_value={'workphone': '1'}) with patch.object(useradd, '_get_gecos', mock): self.assertTrue(useradd.chworkphone('salt', 1)) mock...
'Test if the user\'s Home Phone is changed'
def test_chhomephone(self):
mock = MagicMock(return_value=False) with patch.object(useradd, '_get_gecos', mock): self.assertFalse(useradd.chhomephone('salt', 1)) mock = MagicMock(return_value={'homephone': '1'}) with patch.object(useradd, '_get_gecos', mock): self.assertTrue(useradd.chhomephone('salt', 1)) mock...
'Test the user information'
@skipIf((HAS_PWD is False), 'The pwd module is not available') def test_info(self):
self.assertEqual(useradd.info('username-that-doesnt-exist'), {}) mock = MagicMock(return_value=pwd.struct_passwd(('_TEST_GROUP', '*', 83, 83, 'AMaViS Daemon', '/var/virusmails', '/usr/bin/false'))) with patch.object(pwd, 'getpwnam', mock): self.assertEqual(useradd.info('username-that-doesnt-exist...
'Test if it return a list of groups the named user belongs to'
def test_list_groups(self):
with patch('salt.utils.get_group_list', MagicMock(return_value='Salt')): self.assertEqual(useradd.list_groups('name'), 'Salt')
'Test if it returns a list of all users'
@skipIf((HAS_PWD is False), 'The pwd module is not available') def test_list_users(self):
self.assertTrue(useradd.list_users())
'Test if the username for a named user changed'
def test_rename(self):
mock = MagicMock(return_value=False) with patch.object(useradd, 'info', mock): self.assertRaises(CommandExecutionError, useradd.rename, 'salt', 1) mock = MagicMock(return_value=True) with patch.object(useradd, 'info', mock): self.assertRaises(CommandExecutionError, useradd.rename, 'salt'...
'Tests if a file system created on the specified device'
def test_mkfs(self):
mock = MagicMock() with patch.dict(extfs.__salt__, {'cmd.run': mock}): self.assertListEqual([], extfs.mkfs('/dev/sda1', 'ext4'))
'Tests if specified group was added'
def test_tune(self):
mock = MagicMock() with patch.dict(extfs.__salt__, {'cmd.run': mock}): with patch('salt.modules.extfs.tune', MagicMock(return_value='')): self.assertEqual('', extfs.tune('/dev/sda1'))
'Tests if specified group was added'
def test_dump(self):
mock = MagicMock() with patch.dict(extfs.__salt__, {'cmd.run': mock}): self.assertEqual({'attributes': {}, 'blocks': {}}, extfs.dump('/dev/sda1'))
'Tests if specified group was added'
def test_attributes(self):
with patch('salt.modules.extfs.dump', MagicMock(return_value={'attributes': {}, 'blocks': {}})): self.assertEqual({}, extfs.attributes('/dev/sda1'))
'Tests if specified group was added'
def test_blocks(self):
with patch('salt.modules.extfs.dump', MagicMock(return_value={'attributes': {}, 'blocks': {}})): self.assertEqual({}, extfs.blocks('/dev/sda1'))
'Test for Query a resource, and decode the return data'
def test_query(self):
with patch.object(salt.utils.http, 'query', return_value='A'): self.assertEqual(http.query('url'), 'A')
'Get packages on the different distros. :return:'
def test_env_loader(self):
inspector = Inspector(cachedir='/foo/cache', piddir='/foo/pid', pidfilename='bar.pid') self.assertEqual(inspector.dbfile, '/foo/cache/_minion_collector.db') self.assertEqual(inspector.pidfile, '/foo/pid/bar.pid')
'Test file tree. :return:'
def test_file_tree(self):
inspector = Inspector(cachedir='/test', piddir='/test', pidfilename='bar.pid') tree_root = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'inspectlib', 'tree_test') expected_tree = (['/a/a/dummy.a', '/a/b/dummy.b', '/b/b.1', '/b/b.2', '/b/b.3'], ['/a', '/a/a', '/a/b', '/a/c', '/b', '/c'], ['/a/a/d...
'Test get_unmanaged_files. :return:'
def test_get_unmanaged_files(self):
inspector = Inspector(cachedir='/test', piddir='/test', pidfilename='bar.pid') managed = (['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']) system_all = (['a', 'b', 'c'], ['d', 'E', 'f'], ['G', 'H', 'i']) self.assertEqual(inspector._get_unmanaged_files(managed=managed, system_all=system_all), ([], ['E'...
'Test if grains switching the pkg get method. :return:'
def test_pkg_get(self):
debian_list = '\ng++\ng++-4.9\ng++-5\ngawk\ngcc\ngcc-4.9\ngcc-4.9-base:amd64\ngcc-4.9-base:i386\ngcc-5\ngcc-5-base:amd64\ngcc-5-base:i386\ngcc-6-base:amd64\ngcc-6-base:i386\n' inspector = Inspector(cachedir='/test', piddir='/test', pidfilename='bar.pid') inspector.grains_core = MagicMock() inspector.gra...
'Test if it list all HipChat rooms.'
def test_list_rooms(self):
with patch('salt.modules.hipchat._query', MagicMock(return_value=True)): self.assertEqual(hipchat.list_rooms(), True)
'Test if it list all HipChat users.'
def test_list_users(self):
with patch('salt.modules.hipchat._query', MagicMock(return_value=True)): self.assertEqual(hipchat.list_users(), True)
'Test if it find a room by name and return it.'
def test_find_room(self):
mock = MagicMock(return_value=[{'name': 'Development Room'}]) with patch.object(hipchat, 'list_rooms', mock): self.assertEqual(hipchat.find_room('Development Room'), {'name': 'Development Room'}) self.assertEqual(hipchat.find_room('QA Room'), False)
'Test if it find a user by name and return it.'
def test_find_user(self):
mock = MagicMock(return_value=[{'name': 'Thomas Hatch'}]) with patch.object(hipchat, 'list_rooms', mock): self.assertEqual(hipchat.find_room('Thomas Hatch'), {'name': 'Thomas Hatch'}) self.assertEqual(hipchat.find_user('Salt QA'), False)
'Test if it send a message to a HipChat room.'
def test_send_message(self):
with patch('salt.modules.hipchat._query', MagicMock(return_value=True)): self.assertEqual(hipchat.send_message('Development Room', 'Build is done', 'Build Server'), True)
'Test if it send a message to a HipChat room.'
def test_send_message_false(self):
with patch('salt.modules.hipchat._query', MagicMock(return_value=False)): self.assertEqual(hipchat.send_message('Development Room', 'Build is done', 'Build Server'), False)
'Test parallels.__virtual__'
def test___virtual__(self):
mock_true = MagicMock(return_value=True) mock_false = MagicMock(return_value=False) with patch('salt.utils.path.which', mock_false): ret = parallels.__virtual__() self.assertTrue(isinstance(ret, tuple)) self.assertEqual(len(ret), 2) self.assertFalse(ret[0]) self.asser...
'Test parallels._normalize_args'
def test__normalize_args(self):
def _validate_ret(ret): '\n Assert that the returned data is a list of strings\n ' self.assertTrue(isinstance(ret, list)) for arg in ret: self.assertTrue(isins...
'Test parallels._find_guids'
def test__find_guids(self):
guid_str = textwrap.dedent('\n PARENT_SNAPSHOT_ID SNAPSHOT_ID\n ...
'Test parallels.prlsrvctl'
def test_prlsrvctl(self):
runas = 'macdev' info_cmd = ['prlsrvctl', 'info'] info_fcn = MagicMock() with patch.dict(parallels.__salt__, {'cmd.run': info_fcn}): parallels.prlsrvctl('info', runas=runas) info_fcn.assert_called_once_with(info_cmd, runas=runas) usb_cmd = ['prlsrvctl', 'usb', 'list'] usb_fcn = M...
'Test parallels.prlctl'
def test_prlctl(self):
runas = 'macdev' user_cmd = ['prlctl', 'user', 'list'] user_fcn = MagicMock() with patch.dict(parallels.__salt__, {'cmd.run': user_fcn}): parallels.prlctl('user', 'list', runas=runas) user_fcn.assert_called_once_with(user_cmd, runas=runas) exec_cmd = ['prlctl', 'exec', 'macvm', 'unam...
'Test parallels.list_vms'
def test_list_vms(self):
runas = 'macdev' mock_plain = MagicMock() with patch.object(parallels, 'prlctl', mock_plain): parallels.list_vms(runas=runas) mock_plain.assert_called_once_with('list', [], runas=runas) mock_name = MagicMock() with patch.object(parallels, 'prlctl', mock_name): parallels.list_...
'Test parallels.clone'
def test_clone(self):
name = 'macvm' runas = 'macdev' mock_clone = MagicMock() with patch.object(parallels, 'prlctl', mock_clone): parallels.clone(name, 'macvm_new', runas=runas) mock_clone.assert_called_once_with('clone', [name, '--name', 'macvm_new'], runas=runas) mock_linked = MagicMock() with patc...
'Test parallels.delete'
def test_delete(self):
name = 'macvm' runas = 'macdev' mock_delete = MagicMock() with patch.object(parallels, 'prlctl', mock_delete): parallels.delete(name, runas=runas) mock_delete.assert_called_once_with('delete', name, runas=runas)
'Test parallels.exists'
def test_exists(self):
name = 'macvm' runas = 'macdev' mock_list = MagicMock(return_value='Name: {0}\nState: running'.format(name)) with patch.object(parallels, 'list_vms', mock_list): self.assertTrue(parallels.exists(name, runas=runas)) mock_list = MagicMock(return_value='Name: {0}\nState: running'.fo...
'Test parallels.start'
def test_start(self):
name = 'macvm' runas = 'macdev' mock_start = MagicMock() with patch.object(parallels, 'prlctl', mock_start): parallels.start(name, runas=runas) mock_start.assert_called_once_with('start', name, runas=runas)
'Test parallels.stop'
def test_stop(self):
name = 'macvm' runas = 'macdev' mock_stop = MagicMock() with patch.object(parallels, 'prlctl', mock_stop): parallels.stop(name, runas=runas) mock_stop.assert_called_once_with('stop', [name], runas=runas) mock_kill = MagicMock() with patch.object(parallels, 'prlctl', mock_kill): ...
'Test parallels.restart'
def test_restart(self):
name = 'macvm' runas = 'macdev' mock_start = MagicMock() with patch.object(parallels, 'prlctl', mock_start): parallels.restart(name, runas=runas) mock_start.assert_called_once_with('restart', name, runas=runas)
'Test parallels.reset'
def test_reset(self):
name = 'macvm' runas = 'macdev' mock_start = MagicMock() with patch.object(parallels, 'prlctl', mock_start): parallels.reset(name, runas=runas) mock_start.assert_called_once_with('reset', name, runas=runas)
'Test parallels.status'
def test_status(self):
name = 'macvm' runas = 'macdev' mock_start = MagicMock() with patch.object(parallels, 'prlctl', mock_start): parallels.status(name, runas=runas) mock_start.assert_called_once_with('status', name, runas=runas)
'Test parallels.exec_'
def test_exec_(self):
name = 'macvm' runas = 'macdev' mock_start = MagicMock() with patch.object(parallels, 'prlctl', mock_start): parallels.exec_(name, 'find /etc/paths.d', runas=runas) mock_start.assert_called_once_with('exec', [name, 'find', '/etc/paths.d'], runas=runas)
'Test parallels.snapshot_id_to_name'
def test_snapshot_id_to_name(self):
name = 'macvm' snap_id = 'a5b8999f-5d95-4aff-82de-e515b0101b66' self.assertRaises(SaltInvocationError, parallels.snapshot_id_to_name, name, '{8-4-4-4-12}') mock_no_data = MagicMock(return_value='') with patch.object(parallels, 'prlctl', mock_no_data): self.assertRaises(SaltInvocationError, p...
'Test parallels.snapshot_name_to_id'
def test_snapshot_name_to_id(self):
name = 'macvm' snap_ids = ['a5b8999f-5d95-4aff-82de-e515b0101b66', 'a7345be5-ab66-478c-946e-a6c2caf14909'] snap_id = snap_ids[0] guid_str = textwrap.dedent('\n PARENT_SNAPSHOT_ID ...
'Test parallels._validate_snap_name'
def test__validate_snap_name(self):
name = 'macvm' snap_id = 'a5b8999f-5d95-4aff-82de-e515b0101b66' self.assertEqual(parallels._validate_snap_name(name, snap_id), snap_id) mock_snap_symb = MagicMock(return_value=snap_id) with patch.object(parallels, 'snapshot_name_to_id', mock_snap_symb): self.assertEqual(parallels._validate_s...
'Test parallels.list_snapshots'
def test_list_snapshots(self):
name = 'macvm' guid_str = textwrap.dedent('\n PARENT_SNAPSHOT_ID SNAPSHOT_ID\n ...
'Test parallels.snapshot'
def test_snapshot(self):
name = 'macvm' mock_snap = MagicMock(return_value='') with patch.object(parallels, 'prlctl', mock_snap): parallels.snapshot(name) mock_snap.assert_called_once_with('snapshot', [name], runas=None) snap_name = 'h_0' mock_snap_name = MagicMock(return_value='') with patch.object(para...
'Test parallels.delete_snapshot'
def test_delete_snapshot(self):
delete_message = 'Delete the snapshot...\nThe snapshot has been successfully deleted.' name = 'macvm' snap_name = 'kaon' snap_id = 'c2eab062-a635-4ccd-b9ae-998370f898b5' mock_snap_name = MagicMock(return_value=snap_id) with patch.object(parallels, '_validate_snap_name', mock...
'Test parallels.revert_snapshot'
def test_revert_snapshot(self):
name = 'macvm' snap_name = 'k-bar' snap_id = 'c2eab062-a635-4ccd-b9ae-998370f898b5' mock_snap_name = MagicMock(return_value=snap_id) with patch.object(parallels, '_validate_snap_name', mock_snap_name): mock_delete = MagicMock(return_value='') with patch.object(parallels, 'prlctl', mo...
'Test - Create an IIS application pool.'
def test_create_apppool(self):
with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.list_apppools', MagicMock(return_value=dict())): with patch.dict(win_iis.__salt__): self.assertTrue(win_iis.create_apppool('MyTestPool'))
'Test - List all configured IIS application pools.'
def test_list_apppools(self):
with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value=LIST_APPPOOLS_SRVMGR)): self.assertEqual(win_iis.list_apppools(), APPPOOL_LIST)
'Test - Remove an IIS application pool.'
def test_remove_apppool(self):
with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.list_apppools', MagicMock(return_value={'MyTestPool': {'applications': list(), 'state': 'Started'}})): self.assertTrue(win_iis.r...
'Test - Restart an IIS application pool.'
def test_restart_apppool(self):
with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): self.assertTrue(win_iis.restart_apppool('MyTestPool'))
'Test - Create a basic website in IIS.'
def test_create_site(self):
kwargs = {'name': 'MyTestSite', 'sourcepath': 'C:\\inetpub\\wwwroot', 'apppool': 'MyTestPool', 'hostheader': 'mytestsite.local', 'ipaddress': '*', 'port': 80, 'protocol': 'http'} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): ...
'Test - Create a basic website in IIS using invalid data.'
def test_create_site_failed(self):
kwargs = {'name': 'MyTestSite', 'sourcepath': 'C:\\inetpub\\wwwroot', 'apppool': 'MyTestPool', 'hostheader': 'mytestsite.local', 'ipaddress': '*', 'port': 80, 'protocol': 'invalid-protocol-name'} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retco...
'Test - Delete a website from IIS.'
def test_remove_site(self):
with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.list_sites', MagicMock(return_value=SITE_LIST)): self.assertTrue(win_iis.remove_site('MyTestSite'))
'Test - Create an IIS application.'
def test_create_app(self):
kwargs = {'name': 'testApp', 'site': 'MyTestSite', 'sourcepath': 'C:\\inetpub\\apps\\testApp', 'apppool': 'MyTestPool'} with patch.dict(win_iis.__salt__): with patch('os.path.isdir', MagicMock(return_value=True)): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': ...
'Test - Get all configured IIS applications for the specified site.'
def test_list_apps(self):
with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value=LIST_APPS_SRVMGR)): self.assertEqual(win_iis.list_apps('MyTestSite'), APP_LIST)
'Test - Remove an IIS application.'
def test_remove_app(self):
kwargs = {'name': 'otherApp', 'site': 'MyTestSite'} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.list_apps', MagicMock(return_value=APP_LIST)): self.assertTrue(win_iis.r...
'Test - Create an IIS binding.'
def test_create_binding(self):
kwargs = {'site': 'MyTestSite', 'hostheader': '', 'ipaddress': '*', 'port': 80, 'protocol': 'http', 'sslflags': 0} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.list_bindings', MagicMock...
'Test - Create an IIS binding using invalid data.'
def test_create_binding_failed(self):
kwargs = {'site': 'MyTestSite', 'hostheader': '', 'ipaddress': '*', 'port': 80, 'protocol': 'invalid-protocol-name', 'sslflags': 999} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.list_b...
'Test - Get all configured IIS bindings for the specified site.'
def test_list_bindings(self):
with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis.list_sites', MagicMock(return_value=SITE_LIST)): self.assertEqual(win_iis.list_bindings('MyTestSite'), BINDING_LIST)
'Test - Remove an IIS binding.'
def test_remove_binding(self):
kwargs = {'site': 'MyTestSite', 'hostheader': 'myothertestsite.local', 'ipaddress': '*', 'port': 443} with patch.dict(win_iis.__salt__): with patch('salt.modules.win_iis._srvmgr', MagicMock(return_value={'retcode': 0})): with patch('salt.modules.win_iis.list_bindings', MagicMock(return_value...