本文整理汇总了Python中salttesting.mock.patch.dict函数的典型用法代码示例。如果您正苦于以下问题:Python dict函数的具体用法?Python dict怎么用?Python dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dict函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_absent
def test_absent(self):
'''
Test to remove a entry or entries from a chain
'''
name = 'salt'
entry = ['192.168.0.3', '192.168.1.3']
ret = {'name': name,
'result': False,
'comment': '',
'changes': {}}
mock = MagicMock(side_effect=[True, False, False])
with patch.dict(ipset.__salt__, {'ipset.check': mock}):
comt = ('ipset entry must be specified')
ret.update({'comment': comt})
self.assertDictEqual(ipset.absent(name), ret)
with patch.dict(ipset.__opts__, {'test': True}):
comt = ('ipset entry 192.168.0.3 needs to removed '
'from set salt for family ipv4\n')
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(ipset.absent(name, entry, set_name='salt'),
ret)
comt = ('ipset entry for 192.168.0.3 not present in set (salt) for '
'ipv4\nipset entry for 192.168.1.3 not present in set '
'(salt) for ipv4\n')
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(ipset.absent(name, entry, set_name='salt'),
ret)
开发者ID:DaveQB,项目名称:salt,代码行数:31,代码来源:ipset_test.py
示例2: test_joined
def test_joined(self):
'''
Test to ensure the current node joined
to a cluster with node [email protected]
'''
ret = {'name': 'salt',
'changes': {},
'result': True,
'comment': ''}
mock = MagicMock(side_effect=[['[email protected]'], [''], ['']])
with patch.dict(rabbitmq_cluster.__salt__,
{"rabbitmq.cluster_status": mock}):
ret.update({'comment': 'Already in cluster'})
self.assertDictEqual(rabbitmq_cluster.joined('salt', 'salt',
'rahulha'), ret)
with patch.dict(rabbitmq_cluster.__opts__, {"test": True}):
ret.update({'result': None,
'comment': 'Node is set to join '
'cluster [email protected]'})
self.assertDictEqual(rabbitmq_cluster.joined('salt', 'salt',
'rahulha'), ret)
with patch.dict(rabbitmq_cluster.__opts__, {"test": False}):
mock = MagicMock(return_value={'Error': 'ERR'})
with patch.dict(rabbitmq_cluster.__salt__,
{"rabbitmq.join_cluster": mock}):
ret.update({'result': False,
'comment': 'ERR'})
self.assertDictEqual(rabbitmq_cluster.joined('salt',
'salt',
'rahulha'),
ret)
开发者ID:DaveQB,项目名称:salt,代码行数:34,代码来源:rabbitmq_cluster_test.py
示例3: test_omits
def test_omits(self):
with patch.dict(config.DEFAULTS, DEFAULTS):
with patch.dict(config.__pillar__, __pillar__):
with patch.dict(config.__opts__, __opts__):
opt_name = 'test.option.all'
opt = config.option(opt_name,
omit_opts=False,
omit_master=True,
omit_pillar=True)
self.assertEqual(opt, config.__opts__[opt_name])
opt = config.option(opt_name,
omit_opts=True,
omit_master=True,
omit_pillar=False)
self.assertEqual(opt, config.__pillar__[opt_name])
opt = config.option(opt_name,
omit_opts=True,
omit_master=False,
omit_pillar=True)
self.assertEqual(
opt, config.__pillar__['master'][opt_name])
开发者ID:DaveQB,项目名称:salt,代码行数:25,代码来源:config_test.py
示例4: test_chhomephone
def test_chhomephone(self):
'''
Change the user's Home Phone
'''
mock = MagicMock(return_value=False)
with patch.object(pw_user, '_get_gecos', mock):
self.assertFalse(pw_user.chhomephone('name', 1))
mock = MagicMock(return_value={'homephone': '1'})
with patch.object(pw_user, '_get_gecos', mock):
self.assertTrue(pw_user.chhomephone('name', 1))
mock = MagicMock(return_value={'homephone': '2'})
with patch.object(pw_user, '_get_gecos', mock):
mock = MagicMock(return_value=None)
with patch.dict(pw_user.__salt__, {'cmd.run': mock}):
mock = MagicMock(return_value={'homephone': '3'})
with patch.object(pw_user, 'info', mock):
self.assertFalse(pw_user.chhomephone('name', 1))
mock = MagicMock(return_value={'homephone': '3'})
with patch.object(pw_user, '_get_gecos', mock):
mock = MagicMock(return_value=None)
with patch.dict(pw_user.__salt__, {'cmd.run': mock}):
mock = MagicMock(return_value={'homephone': '3'})
with patch.object(pw_user, 'info', mock):
self.assertFalse(pw_user.chhomephone('name', 1))
开发者ID:DaveQB,项目名称:salt,代码行数:27,代码来源:pw_user_test.py
示例5: test_present
def test_present(self):
'''
Test to ensure the user exists on the Dell DRAC
'''
name = 'damian'
password = 'secret'
permission = 'login,test_alerts,clear_logs'
ret = {'name': name,
'result': True,
'comment': '',
'changes': {}}
mock = MagicMock(return_value=[name])
with patch.dict(drac.__salt__, {'drac.list_users': mock}):
with patch.dict(drac.__opts__, {'test': True}):
comt = ('`{0}` already exists'.format(name))
ret.update({'comment': comt})
self.assertDictEqual(drac.present(name, password, permission),
ret)
with patch.dict(drac.__opts__, {'test': False}):
comt = ('`{0}` already exists'.format(name))
ret.update({'comment': comt})
self.assertDictEqual(drac.present(name, password, permission),
ret)
开发者ID:DaveQB,项目名称:salt,代码行数:26,代码来源:drac_test.py
示例6: test_create_with_labels_dictlist
def test_create_with_labels_dictlist(self, *args):
'''
Create container with labels dictlist.
'''
__salt__ = {
'config.get': Mock(),
'mine.send': Mock(),
}
host_config = {}
client = Mock()
client.api_version = '1.19'
client.create_host_config.return_value = host_config
client.create_container.return_value = {}
with patch.dict(dockerng_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod.create(
'image',
name='ctn',
labels=[{'KEY1': 'VALUE1'}, {'KEY2': 'VALUE2'}],
validate_input=True,
)
client.create_container.assert_called_once_with(
labels={'KEY1': 'VALUE1', 'KEY2': 'VALUE2'},
host_config=host_config,
image='image',
name='ctn',
)
开发者ID:bryson,项目名称:salt,代码行数:29,代码来源:dockerng_test.py
示例7: test_absent
def test_absent(self):
'''
Test to ensure that the named extension is absent.
'''
name = 'frank'
ret = {'name': name,
'changes': {},
'result': False,
'comment': ''}
mock_t = MagicMock(side_effect=[True, False])
mock = MagicMock(side_effect=[True, True, True, False])
with patch.dict(postgres_extension.__salt__,
{'postgres.is_installed_extension': mock,
'postgres.drop_extension': mock_t}):
with patch.dict(postgres_extension.__opts__, {'test': True}):
comt = ('Extension {0} is set to be removed'.format(name))
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(postgres_extension.absent(name), ret)
with patch.dict(postgres_extension.__opts__, {'test': False}):
comt = ('Extension {0} has been removed'.format(name))
ret.update({'comment': comt, 'result': True,
'changes': {name: 'Absent'}})
self.assertDictEqual(postgres_extension.absent(name), ret)
comt = ('Extension {0} failed to be removed'.format(name))
ret.update({'comment': comt, 'result': False, 'changes': {}})
self.assertDictEqual(postgres_extension.absent(name), ret)
comt = ('Extension {0} is not present, so it cannot be removed'
.format(name))
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(postgres_extension.absent(name), ret)
开发者ID:DaveQB,项目名称:salt,代码行数:35,代码来源:postgres_extension_test.py
示例8: test_unzip
def test_unzip(self):
mock = MagicMock(return_value='salt')
with patch.dict(archive.__salt__, {'cmd.run': mock}):
ret = archive.unzip(
'/tmp/salt.{{grains.id}}.zip',
'/tmp/dest',
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
template='jinja'
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unzip /tmp/salt.{{grains.id}}.zip -d /tmp/dest '
'-x /tmp/tmpePe8yO /tmp/tmpLeSw1A',
template='jinja'
)
mock = MagicMock(return_value='salt')
with patch.dict(archive.__salt__, {'cmd.run': mock}):
ret = archive.unzip(
'/tmp/salt.{{grains.id}}.zip',
'/tmp/dest',
excludes=['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
template='jinja'
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unzip /tmp/salt.{{grains.id}}.zip -d /tmp/dest '
'-x /tmp/tmpePe8yO /tmp/tmpLeSw1A',
template='jinja'
)
开发者ID:penta-srl,项目名称:salt,代码行数:30,代码来源:archive_test.py
示例9: test_rar
def test_rar(self):
mock = MagicMock(return_value='salt')
with patch.dict(archive.__salt__, {'cmd.run': mock}):
ret = archive.rar(
'/tmp/rarfile.rar',
'/tmp/sourcefile1,/tmp/sourcefile2'
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'rar a -idp /tmp/rarfile.rar '
'/tmp/sourcefile1 /tmp/sourcefile2',
template=None
)
mock = MagicMock(return_value='salt')
with patch.dict(archive.__salt__, {'cmd.run': mock}):
ret = archive.rar(
'/tmp/rarfile.rar',
['/tmp/sourcefile1', '/tmp/sourcefile2']
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'rar a -idp /tmp/rarfile.rar '
'/tmp/sourcefile1 /tmp/sourcefile2',
template=None
)
开发者ID:penta-srl,项目名称:salt,代码行数:26,代码来源:archive_test.py
示例10: test_usage
def test_usage(self):
'''
Test if it shows in which disk the chunks are allocated.
'''
mock = MagicMock(return_value={'retcode': 1,
'stderr': '',
'stdout': 'Salt'})
with patch.dict(btrfs.__salt__, {'cmd.run_all': mock}):
mock = MagicMock(return_value={'Salt': 'salt'})
with patch.object(btrfs, '_usage_specific', mock):
self.assertDictEqual(btrfs.usage('/dev/sda1'),
{'Salt': 'salt'})
mock = MagicMock(return_value={'retcode': 1,
'stderr': '',
'stdout': 'Unallocated:\n'})
with patch.dict(btrfs.__salt__, {'cmd.run_all': mock}):
mock = MagicMock(return_value={'/dev/sda1': True})
with patch.object(btrfs, '_usage_unallocated', mock):
self.assertDictEqual(btrfs.usage('/dev/sda1'),
{'unallocated': {'/dev/sda1': True}})
mock = MagicMock(return_value={'retcode': 1,
'stderr': '',
'stdout': 'Overall:\n'})
with patch.dict(btrfs.__salt__, {'cmd.run_all': mock}):
mock = MagicMock(return_value={'/dev/sda1': True})
with patch.object(btrfs, '_usage_overall', mock):
self.assertDictEqual(btrfs.usage('/dev/sda1'),
{'overall': {'/dev/sda1': True}})
开发者ID:DaveQB,项目名称:salt,代码行数:30,代码来源:btrfs_test.py
示例11: test_chain_present
def test_chain_present(self):
'''
Test to verify the chain is exist.
'''
ret = {'name': 'salt',
'changes': {},
'result': True,
'comment': ''}
mock = MagicMock(side_effect=[True, False, False])
with patch.dict(nftables.__salt__, {"nftables.check_chain": mock}):
ret.update({'comment': 'nftables salt chain is already'
' exist in filter table for ipv4'})
self.assertDictEqual(nftables.chain_present('salt'), ret)
mock = MagicMock(side_effect=[True, ''])
with patch.dict(nftables.__salt__, {"nftables.new_chain": mock}):
ret.update({'changes': {'locale': 'salt'},
'comment': 'nftables salt chain in filter'
' table create success for ipv4'})
self.assertDictEqual(nftables.chain_present('salt'), ret)
ret.update({'changes': {},
'comment': 'Failed to create salt chain'
' in filter table: for ipv4',
'result': False})
self.assertDictEqual(nftables.chain_present('salt'), ret)
开发者ID:DaveQB,项目名称:salt,代码行数:26,代码来源:nftables_test.py
示例12: test_set_absent
def test_set_absent(self):
'''
Test to verify the set is absent.
'''
name = 'salt'
ret = {'name': name,
'result': True,
'comment': '',
'changes': {}}
mock = MagicMock(side_effect=[False, True, True, ''])
with patch.dict(ipset.__salt__, {'ipset.check_set': mock,
'ipset.flush': mock}):
comt = ('ipset set salt is already absent for family ipv4')
ret.update({'comment': comt})
self.assertDictEqual(ipset.set_absent(name), ret)
with patch.dict(ipset.__opts__, {'test': True}):
comt = ('ipset set salt needs to be removed family ipv4')
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(ipset.set_absent(name), ret)
with patch.dict(ipset.__opts__, {'test': False}):
comt = ('Failed to flush salt set: for ipv4')
ret.update({'comment': comt, 'result': False, 'changes': {}})
self.assertDictEqual(ipset.set_absent(name), ret)
开发者ID:DaveQB,项目名称:salt,代码行数:27,代码来源:ipset_test.py
示例13: test_set_present
def test_set_present(self):
'''
Test to verify the chain is exist.
'''
name = 'salt'
set_type = {'bitmap': '192.168.0.3'}
ret = {'name': name,
'result': True,
'comment': '',
'changes': {}}
mock = MagicMock(side_effect=[True, False, False, True, False, ''])
with patch.dict(ipset.__salt__, {'ipset.check_set': mock,
'ipset.new_set': mock}):
comt = ('ipset set {0} already exist for ipv4'.format(name))
ret.update({'comment': comt})
self.assertDictEqual(ipset.set_present(name, set_type), ret)
with patch.dict(ipset.__opts__, {'test': True}):
comt = ('ipset set {0} needs to added for ipv4'.format(name))
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(ipset.set_present(name, set_type), ret)
with patch.dict(ipset.__opts__, {'test': False}):
comt = ('ipset set {0} created successfully for ipv4'
.format(name))
ret.update({'comment': comt, 'result': True,
'changes': {'locale': 'salt'}})
self.assertDictEqual(ipset.set_present(name, set_type), ret)
comt = ('Failed to create salt set: for ipv4')
ret.update({'comment': comt, 'result': False, 'changes': {}})
self.assertDictEqual(ipset.set_present(name, set_type), ret)
开发者ID:DaveQB,项目名称:salt,代码行数:34,代码来源:ipset_test.py
示例14: test_flush
def test_flush(self):
'''
Test to flush current ipset set.
'''
name = 'salt'
ret = {'name': name,
'result': False,
'comment': '',
'changes': {}}
mock = MagicMock(side_effect=[False, True, True, True])
mock_f = MagicMock(side_effect=[True, False])
with patch.dict(ipset.__salt__, {'ipset.check_set': mock,
'ipset.flush': mock_f}):
comt = ('ipset set {0} does not exist for ipv4'.format(name))
ret.update({'comment': comt})
self.assertDictEqual(ipset.flush(name), ret)
with patch.dict(ipset.__opts__, {'test': True}):
comt = ('ipset entries in set {0} family ipv4 needs to '
'be flushed'.format(name))
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(ipset.flush(name), ret)
with patch.dict(ipset.__opts__, {'test': False}):
comt = ('Flush ipset entries in set {0} family ipv4'
.format(name))
ret.update({'comment': comt, 'result': True,
'changes': {'locale': 'salt'}})
self.assertDictEqual(ipset.flush(name), ret)
comt = ('Failed to flush ipset entries')
ret.update({'comment': comt, 'result': False, 'changes': {}})
self.assertDictEqual(ipset.flush(name), ret)
开发者ID:DaveQB,项目名称:salt,代码行数:35,代码来源:ipset_test.py
示例15: test_list_absent
def test_list_absent(self):
'''
Test to delete a value from a grain formed as a list
'''
ret = {'changes': {}, 'name': self.name, 'result': True,
'comment': 'Value edam is absent from grain cheese'}
ret1 = {'changes': {'deleted': self.value}, 'name': self.name,
'result': None,
'comment': 'Value edam in grain cheese is set to be deleted'}
ret2 = {'changes': {}, 'name': self.name, 'result': True,
'comment': 'Grain cheese does not exist'}
ret3 = {'changes': {}, 'name': self.name, 'result': False,
'comment': 'Grain cheese is not a valid list'}
with patch.dict(grains.__grains__, {self.name: ['eves']}):
self.assertDictEqual(grains.list_absent(self.name, self.value), ret)
with patch.dict(grains.__opts__, {'test': True}):
with patch.dict(grains.__grains__, {self.name: [self.value]}):
self.assertDictEqual(grains.list_absent(self.name, self.value),
ret1)
self.assertDictEqual(grains.list_absent(self.name, self.value), ret2)
with patch.dict(grains.__grains__, {self.name: 'eves'}):
self.assertDictEqual(grains.list_absent(self.name, self.value), ret3)
开发者ID:dmyerscough,项目名称:salt,代码行数:29,代码来源:grains_test.py
示例16: test_unrar
def test_unrar(self):
mock = MagicMock(return_value='salt')
with patch.dict(archive.__salt__, {'cmd.run': mock}):
ret = archive.unrar(
'/tmp/rarfile.rar',
'/home/strongbad/',
excludes='file_1,file_2'
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unrar x -idp /tmp/rarfile.rar '
'-x file_1 -x file_2 /home/strongbad/',
template=None
)
mock = MagicMock(return_value='salt')
with patch.dict(archive.__salt__, {'cmd.run': mock}):
ret = archive.unrar(
'/tmp/rarfile.rar',
'/home/strongbad/',
excludes=['file_1', 'file_2']
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unrar x -idp /tmp/rarfile.rar '
'-x file_1 -x file_2 /home/strongbad/',
template=None
)
开发者ID:penta-srl,项目名称:salt,代码行数:28,代码来源:archive_test.py
示例17: test__chkconfig_is_enabled
def test__chkconfig_is_enabled(self):
'''
test _chkconfig_is_enabled function
'''
name = 'atd'
chkconfig_out = textwrap.dedent('''\
{0} 0:off 1:off 2:off 3:on 4:on 5:on 6:off
'''.format(name))
xinetd_out = textwrap.dedent('''\
xinetd based services:
{0} on
'''.format(name))
with patch.object(rh_service, '_runlevel', MagicMock(return_value=3)):
mock_run = MagicMock(return_value={'retcode': 0,
'stdout': chkconfig_out})
with patch.dict(rh_service.__salt__, {'cmd.run_all': mock_run}):
self.assertTrue(rh_service._chkconfig_is_enabled(name))
self.assertFalse(rh_service._chkconfig_is_enabled(name, 2))
self.assertTrue(rh_service._chkconfig_is_enabled(name, 3))
mock_run = MagicMock(return_value={'retcode': 0,
'stdout': xinetd_out})
with patch.dict(rh_service.__salt__, {'cmd.run_all': mock_run}):
self.assertTrue(rh_service._chkconfig_is_enabled(name))
self.assertTrue(rh_service._chkconfig_is_enabled(name, 2))
self.assertTrue(rh_service._chkconfig_is_enabled(name, 3))
开发者ID:bryson,项目名称:salt,代码行数:28,代码来源:rh_service_test.py
示例18: test_tar
def test_tar(self):
mock = MagicMock(return_value='salt')
with patch.dict(archive.__salt__, {'cmd.run': mock}):
ret = archive.tar(
'zcvf', 'foo.tar',
['/tmp/something-to-compress-1',
'/tmp/something-to-compress-2'],
cwd=None, template=None
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'tar -zcvf foo.tar /tmp/something-to-compress-1 '
'/tmp/something-to-compress-2',
cwd=None,
template=None
)
mock = MagicMock(return_value='salt')
with patch.dict(archive.__salt__, {'cmd.run': mock}):
ret = archive.tar(
'zcvf', 'foo.tar',
'/tmp/something-to-compress-1,/tmp/something-to-compress-2',
cwd=None, template=None
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'tar -zcvf foo.tar /tmp/something-to-compress-1 '
'/tmp/something-to-compress-2',
cwd=None,
template=None
)
开发者ID:penta-srl,项目名称:salt,代码行数:31,代码来源:archive_test.py
示例19: test_check_mine_cache_is_refreshed_on_container_change_event
def test_check_mine_cache_is_refreshed_on_container_change_event(self, _):
'''
Every command that might modify docker containers state.
Should trig an update on ``mine.send``
'''
for command_name, args in (('create', ()),
('rm_', ()),
('kill', ()),
('pause', ()),
('signal_', ('KILL',)),
('start', ()),
('stop', ()),
('unpause', ()),
('_run', ('command',)),
('_script', ('command',)),
):
mine_send = Mock()
command = getattr(dockerng_mod, command_name)
docker_client = MagicMock()
docker_client.api_version = '1.12'
with patch.dict(dockerng_mod.__salt__,
{'mine.send': mine_send,
'container_resource.run': MagicMock(),
'cp.cache_file': MagicMock(return_value=False)}):
with patch.dict(dockerng_mod.__context__,
{'docker.client': docker_client}):
command('container', *args)
mine_send.assert_called_with('dockerng.ps', verbose=True, all=True,
host=True)
开发者ID:bryson,项目名称:salt,代码行数:30,代码来源:dockerng_test.py
示例20: test_install_pyenv
def test_install_pyenv(self):
'''
Test to install pyenv if not installed.
'''
name = 'python-2.7.6'
ret = {'name': name,
'changes': {},
'result': None,
'comment': ''}
with patch.dict(pyenv.__opts__, {'test': True}):
comt = ('pyenv is set to be installed')
ret.update({'comment': comt})
self.assertDictEqual(pyenv.install_pyenv(name), ret)
with patch.dict(pyenv.__opts__, {'test': False}):
mock_t = MagicMock(return_value=True)
mock_str = MagicMock(return_value='2.7.6')
mock_lst = MagicMock(return_value=['2.7.6'])
with patch.dict(pyenv.__salt__, {'pyenv.install_python': mock_t,
'pyenv.default': mock_str,
'pyenv.versions': mock_lst}):
comt = ('Successfully installed python')
ret.update({'comment': comt, 'result': True, 'default': False,
'changes': {None: 'Installed'}})
self.assertDictEqual(pyenv.install_pyenv(name), ret)
开发者ID:DaveQB,项目名称:salt,代码行数:27,代码来源:pyenv_test.py
注:本文中的salttesting.mock.patch.dict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论