本文整理汇总了Python中salttesting.mock.Mock.api_version方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.api_version方法的具体用法?Python Mock.api_version怎么用?Python Mock.api_version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salttesting.mock.Mock
的用法示例。
在下文中一共展示了Mock.api_version方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_with_labels_dictlist
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
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',
)
示例2: test_wait_success_absent_container
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
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"})
示例3: test_inspect_volume
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
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')
示例4: test_wait_fails_on_exit_status
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
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'}})
示例5: test_remove_network
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
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')
示例6: test_images_with_empty_tags
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
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']}})
示例7: test_wait_success_already_stopped
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
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'}})
示例8: test_list_volumes
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
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]},
)
示例9: test_create_send_host_config
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
def test_create_send_host_config(self, *args):
'''
Check host_config object is passed to create_container.
'''
__salt__ = {
'config.get': Mock(),
'mine.send': Mock(),
}
host_config = {'PublishAllPorts': True}
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', publish_all_ports=True)
client.create_container.assert_called_once_with(
host_config=host_config,
image='image',
name='ctn')
示例10: test_list_networks
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
def test_list_networks(self, *args):
'''
test list networks.
'''
__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.networks(
names=['foo'],
ids=['01234'],
)
client.networks.assert_called_once_with(
names=['foo'],
ids=['01234'],
)
示例11: test_create_with_arg_cmd
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
def test_create_with_arg_cmd(self, *args):
'''
When cmd argument is passed check it is renamed to command.
'''
__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', cmd='ls', name='ctn')
client.create_container.assert_called_once_with(
command='ls',
host_config=host_config,
image='image',
name='ctn')
示例12: test_create_volume
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
def test_create_volume(self, *args):
'''
test create 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.create_volume(
'foo',
driver='bridge',
driver_opts={},
)
client.create_volume.assert_called_once_with(
'foo',
driver='bridge',
driver_opts={},
)
示例13: test_create_with_labels_error
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import api_version [as 别名]
def test_create_with_labels_error(self, *args):
'''
Create container with invalid labels.
'''
__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}):
self.assertRaises(SaltInvocationError,
dockerng_mod.create,
'image',
name='ctn',
labels=22,
validate_input=True,
)