本文整理汇总了Python中salttesting.mock.Mock类的典型用法代码示例。如果您正苦于以下问题:Python Mock类的具体用法?Python Mock怎么用?Python Mock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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
示例3: add_process
def add_process(self, pid=100, cmd="cmd", name="name", user="user", user_domain="domain", get_owner_result=0):
process = Mock()
process.GetOwner = Mock(return_value=(user_domain, get_owner_result, user))
process.ProcessId = pid
process.CommandLine = cmd
process.Name = name
self.__processes.append(process)
开发者ID:AccelerationNet,项目名称:salt,代码行数:7,代码来源:win_status_test.py
示例4: test_running_with_labels
def test_running_with_labels(self):
'''
Test dockerng.running with labels parameter.
'''
dockerng_create = Mock()
__salt__ = {'dockerng.list_containers': MagicMock(),
'dockerng.list_tags': MagicMock(),
'dockerng.pull': MagicMock(),
'dockerng.state': MagicMock(),
'dockerng.inspect_image': MagicMock(),
'dockerng.create': dockerng_create,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
dockerng_state.running(
'cont',
image='image:latest',
labels=['LABEL1', 'LABEL2'],
)
dockerng_create.assert_called_with(
'image:latest',
validate_input=False,
validate_ip_addrs=False,
name='cont',
labels=['LABEL1', 'LABEL2'],
client_timeout=60)
开发者ID:mahak,项目名称:salt,代码行数:26,代码来源:dockerng_test.py
示例5: test_with_user
def test_with_user(self):
config = {'states': ['device'], 'user': 'fred'}
mock = Mock(return_value='* daemon started successfully *\nList of devices attached\nHTC\tdevice',)
with patch.dict(adb.__salt__, {'cmd.run': mock}):
ret = adb.beacon(config)
mock.assert_called_once_with('adb devices', runas='fred')
self.assertEqual(ret, [{'device': 'HTC', 'state': 'device', 'tag': 'device'}])
开发者ID:HowardMei,项目名称:saltstack,代码行数:8,代码来源:adb_beacon_test.py
示例6: test_screen_state
def test_screen_state(self):
config = {'screen_event': True, 'user': 'frank'}
mock = Mock(return_value=0)
with patch.dict(glxinfo.__salt__, {'cmd.retcode': mock}):
ret = glxinfo.beacon(config)
self.assertEqual(ret, [{'tag': 'screen_event', 'screen_available': True}])
mock.assert_called_once_with('DISPLAY=:0 glxinfo', runas='frank', python_shell=True)
开发者ID:HowardMei,项目名称:saltstack,代码行数:8,代码来源:glxinfo.py
示例7: test_wait_success_absent_container
def test_wait_success_absent_container(self):
client = Mock()
client.api_version = '1.21'
dockerng_inspect_container = Mock(side_effect=CommandExecutionError)
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo', ignore_already_stopped=True)
self.assertEqual(result, {'result': True,
'comment': "Container 'foo' absent"})
开发者ID:bryson,项目名称:salt,代码行数:12,代码来源:dockerng_test.py
示例8: test_validate_input_min_docker_py
def test_validate_input_min_docker_py(self):
docker_mock = Mock()
docker_mock.version_info = (1, 0, 0)
dockerng_mod.docker = None
with patch.dict(dockerng_mod.VALID_CREATE_OPTS['command'],
{'path': 'Config:Cmd',
'image_path': 'Config:Cmd',
'min_docker_py': (999, 0, 0)}):
with patch.object(dockerng_mod, 'docker', docker_mock):
self.assertRaisesRegexp(SaltInvocationError,
"The 'command' parameter requires at"
" least docker-py 999.0.0.*$",
dockerng_state._validate_input,
{'command': 'echo boom'})
开发者ID:bryson,项目名称:salt,代码行数:14,代码来源:dockerng_test.py
示例9: test_call_success
def test_call_success(self):
'''
test module calling inside containers
'''
ret = None
docker_run_all_mock = MagicMock(
return_value={
'retcode': 0,
'stdout': '{"retcode": 0, "comment": "container cmd"}',
'stderr': 'err',
})
docker_copy_to_mock = MagicMock(
return_value={
'retcode': 0
})
client = Mock()
client.put_archive = Mock()
with patch.dict(dockerng_mod.__opts__, {'cachedir': '/tmp'}):
with patch.dict(dockerng_mod.__salt__, {'dockerng.run_all': docker_run_all_mock,
'dockerng.copy_to': docker_copy_to_mock}):
with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
# call twice to verify tmp path later
for i in range(2):
ret = dockerng_mod.call(
'ID',
'test.arg',
1, 2,
arg1='val1')
# Check that the directory is different each time
# [ call(name, [args]), ...
self.assertIn('mkdir', docker_run_all_mock.mock_calls[0][1][1])
self.assertIn('mkdir', docker_run_all_mock.mock_calls[3][1][1])
self.assertNotEqual(docker_run_all_mock.mock_calls[0][1][1],
docker_run_all_mock.mock_calls[3][1][1])
self.assertIn('salt-call', docker_run_all_mock.mock_calls[1][1][1])
self.assertIn('salt-call', docker_run_all_mock.mock_calls[4][1][1])
self.assertNotEqual(docker_run_all_mock.mock_calls[1][1][1],
docker_run_all_mock.mock_calls[4][1][1])
# check directory cleanup
self.assertIn('rm -rf', docker_run_all_mock.mock_calls[2][1][1])
self.assertIn('rm -rf', docker_run_all_mock.mock_calls[5][1][1])
self.assertNotEqual(docker_run_all_mock.mock_calls[2][1][1],
docker_run_all_mock.mock_calls[5][1][1])
self.assertEqual({"retcode": 0, "comment": "container cmd"}, ret)
开发者ID:bryson,项目名称:salt,代码行数:49,代码来源:dockerng_test.py
示例10: add_process
def add_process(
self,
pid=100,
cmd='cmd',
name='name',
user='user',
user_domain='domain',
get_owner_result=0):
process = Mock()
process.GetOwner = Mock(
return_value=(user_domain, get_owner_result, user)
)
process.ProcessId = pid
process.CommandLine = cmd
process.Name = name
self.__processes.append(process)
开发者ID:DavideyLee,项目名称:salt,代码行数:16,代码来源:win_status_test.py
示例11: test_inspect_volume
def test_inspect_volume(self, *args):
'''
test inspect volume.
'''
__salt__ = {
'config.get': Mock(),
'mine.send': Mock(),
}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod.inspect_volume('foo')
client.inspect_volume.assert_called_once_with('foo')
开发者ID:bryson,项目名称:salt,代码行数:16,代码来源:dockerng_test.py
示例12: test_remove_network
def test_remove_network(self, *args):
'''
test remove network.
'''
__salt__ = {
'config.get': Mock(),
'mine.send': Mock(),
}
host_config = {}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod.remove_network('foo')
client.remove_network.assert_called_once_with('foo')
开发者ID:bryson,项目名称:salt,代码行数:17,代码来源:dockerng_test.py
示例13: test_wait_fails_on_exit_status
def test_wait_fails_on_exit_status(self):
client = Mock()
client.api_version = '1.21'
client.wait = Mock(return_value=1)
dockerng_inspect_container = Mock(side_effect=[
{'State': {'Running': True}},
{'State': {'Stopped': True}}])
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo', fail_on_exit_status=True)
self.assertEqual(result, {'result': False,
'exit_status': 1,
'state': {'new': 'stopped',
'old': 'running'}})
开发者ID:bryson,项目名称:salt,代码行数:17,代码来源:dockerng_test.py
示例14: test_images_with_empty_tags
def test_images_with_empty_tags(self):
"""
docker 1.12 reports also images without tags with `null`.
"""
client = Mock()
client.api_version = '1.24'
client.images = Mock(
return_value=[{'Id': 'sha256:abcde',
'RepoTags': None},
{'Id': 'sha256:abcdef'},
{'Id': 'sha256:abcdefg',
'RepoTags': ['image:latest']}])
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.images()
self.assertEqual(result,
{'sha256:abcdefg': {'RepoTags': ['image:latest']}})
开发者ID:bryson,项目名称:salt,代码行数:18,代码来源:dockerng_test.py
示例15: test_running_with_labels_from_image
def test_running_with_labels_from_image(self):
'''
Test dockerng.running with labels parameter supports also
labels carried by the image.
'''
dockerng_create = Mock()
image_id = 'a' * 128
dockerng_inspect_image = MagicMock(
return_value={
'Id': image_id,
'Config': {
'Hostname': 'saltstack-container',
'WorkingDir': '/',
'Cmd': ['bash'],
'Volumes': {'/path': {}},
'Entrypoint': None,
'ExposedPorts': {},
'Labels': {'IMAGE_LABEL': 'image_foo',
'LABEL1': 'label1'},
},
})
__salt__ = {'dockerng.list_containers': MagicMock(),
'dockerng.list_tags': MagicMock(),
'dockerng.pull': MagicMock(),
'dockerng.state': MagicMock(),
'dockerng.inspect_image': dockerng_inspect_image,
'dockerng.create': dockerng_create,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
dockerng_state.running(
'cont',
image='image:latest',
labels=[{'LABEL1': 'foo1'}, {'LABEL2': 'foo2'}],
)
dockerng_create.assert_called_with(
'image:latest',
validate_input=False,
validate_ip_addrs=False,
name='cont',
labels={'LABEL1': 'foo1', 'LABEL2': 'foo2'},
client_timeout=60)
开发者ID:bryson,项目名称:salt,代码行数:43,代码来源:dockerng_test.py
示例16: test_volume_absent
def test_volume_absent(self):
'''
Test dockerng.volume_absent
'''
dockerng_remove_volume = Mock(return_value='removed')
__salt__ = {'dockerng.remove_volume': dockerng_remove_volume,
'dockerng.volumes': Mock(return_value={
'Volumes': [{'Name': 'volume_foo'}]}),
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
ret = dockerng_state.volume_absent(
'volume_foo',
)
dockerng_remove_volume.assert_called_with('volume_foo')
self.assertEqual(ret, {'name': 'volume_foo',
'comment': '',
'changes': {'removed': 'removed'},
'result': True})
开发者ID:bryson,项目名称:salt,代码行数:19,代码来源:dockerng_test.py
示例17: test_wait_success_already_stopped
def test_wait_success_already_stopped(self):
client = Mock()
client.api_version = '1.21'
client.wait = Mock(return_value=0)
dockerng_inspect_container = Mock(side_effect=[
{'State': {'Stopped': True}},
{'State': {'Stopped': True}},
])
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo', ignore_already_stopped=True)
self.assertEqual(result, {'result': True,
'comment': "Container 'foo' already stopped",
'exit_status': 0,
'state': {'new': 'stopped',
'old': 'stopped'}})
开发者ID:bryson,项目名称:salt,代码行数:19,代码来源:dockerng_test.py
示例18: test_volume_present
def test_volume_present(self):
'''
Test dockerng.volume_present
'''
dockerng_create_volume = Mock(return_value='created')
__salt__ = {'dockerng.create_volume': dockerng_create_volume,
'dockerng.volumes': Mock(return_value={'Volumes': []}),
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
ret = dockerng_state.volume_present(
'volume_foo',
)
dockerng_create_volume.assert_called_with('volume_foo',
driver=None,
driver_opts=None)
self.assertEqual(ret, {'name': 'volume_foo',
'comment': '',
'changes': {'created': 'created'},
'result': True})
开发者ID:HowardMei,项目名称:saltstack,代码行数:20,代码来源:dockerng_test.py
示例19: test_list_volumes
def test_list_volumes(self, *args):
'''
test list volumes.
'''
__salt__ = {
'config.get': Mock(),
'mine.send': Mock(),
}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod.volumes(
filters={'dangling': [True]},
)
client.volumes.assert_called_once_with(
filters={'dangling': [True]},
)
开发者ID:bryson,项目名称:salt,代码行数:20,代码来源:dockerng_test.py
示例20: test_running_with_no_predifined_volume
def test_running_with_no_predifined_volume(self):
'''
Test dockerng.running function with an image
that doens't have VOLUME defined.
The ``binds`` argument, should create a container
with respective volumes extracted from ``binds``.
'''
dockerng_create = Mock()
dockerng_start = Mock()
__salt__ = {'dockerng.list_containers': MagicMock(),
'dockerng.list_tags': MagicMock(),
'dockerng.pull': MagicMock(),
'dockerng.state': MagicMock(),
'dockerng.inspect_image': MagicMock(),
'dockerng.create': dockerng_create,
'dockerng.start': dockerng_start,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
dockerng_state.running(
'cont',
image='image:latest',
binds=['/host-0:/container-0:ro'])
dockerng_create.assert_called_with(
'image:latest',
validate_input=False,
name='cont',
binds={'/host-0': {'bind': '/container-0', 'ro': True}},
volumes=['/container-0'],
validate_ip_addrs=False,
client_timeout=60)
dockerng_start.assert_called_with('cont')
开发者ID:bryson,项目名称:salt,代码行数:33,代码来源:dockerng_test.py
注:本文中的salttesting.mock.Mock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论