本文整理汇总了Python中salttesting.mock.Mock.assert_called_with方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.assert_called_with方法的具体用法?Python Mock.assert_called_with怎么用?Python Mock.assert_called_with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salttesting.mock.Mock
的用法示例。
在下文中一共展示了Mock.assert_called_with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_volume_present_with_another_driver
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_volume_present_with_another_driver(self):
'''
Test dockerng.volume_present
'''
dockerng_create_volume = Mock(return_value='created')
dockerng_remove_volume = Mock(return_value='removed')
__salt__ = {'dockerng.create_volume': dockerng_create_volume,
'dockerng.remove_volume': dockerng_remove_volume,
'dockerng.volumes': Mock(return_value={
'Volumes': [{'Name': 'volume_foo',
'Driver': 'foo'}]}),
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
ret = dockerng_state.volume_present(
'volume_foo',
driver='bar',
force=True,
)
dockerng_remove_volume.assert_called_with('volume_foo')
dockerng_create_volume.assert_called_with('volume_foo',
driver='bar',
driver_opts=None)
self.assertEqual(ret, {'name': 'volume_foo',
'comment': '',
'changes': {'created': 'created',
'removed': 'removed'},
'result': True})
示例2: test_check_mine_cache_is_refreshed_on_container_change_event
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
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)
示例3: test_running_with_predifined_volume
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_running_with_predifined_volume(self):
'''
Test dockerng.running function with an image
that already have VOLUME defined.
The ``binds`` argument, shouldn't have side effects on
container creation.
'''
dockerng_create = Mock()
dockerng_start = Mock()
dockerng_history = MagicMock(return_value=['VOLUME /container-0'])
__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,
'dockerng.history': dockerng_history,
}
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,
binds={'/host-0': {'bind': '/container-0', 'ro': True}},
validate_ip_addrs=False,
name='cont',
client_timeout=60)
dockerng_start.assert_called_with('cont')
示例4: test_running_with_labels
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
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)
示例5: test_running_with_predifined_ports
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_running_with_predifined_ports(self):
'''
Test dockerng.running function with an image
that contains EXPOSE statements.
The ``port_bindings`` argument, shouldn't have side effect on container
creation.
'''
dockerng_create = Mock()
dockerng_start = Mock()
dockerng_history = MagicMock(return_value=['EXPOSE 9797/tcp'])
__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,
'dockerng.history': dockerng_history,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
dockerng_state.running(
'cont',
image='image:latest',
port_bindings=['9090:9797/tcp'])
dockerng_create.assert_called_with(
'image:latest',
validate_input=False,
name='cont',
port_bindings={9797: [9090]},
validate_ip_addrs=False,
client_timeout=60)
dockerng_start.assert_called_with('cont')
示例6: test_network_present
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_network_present(self):
'''
Test dockerng.network_present
'''
dockerng_create_network = Mock(return_value='created')
dockerng_connect_container_to_network = Mock(return_value='connected')
dockerng_inspect_container = Mock(return_value={'Id': 'abcd'})
__salt__ = {'dockerng.create_network': dockerng_create_network,
'dockerng.inspect_container': dockerng_inspect_container,
'dockerng.connect_container_to_network': dockerng_connect_container_to_network,
'dockerng.networks': Mock(return_value=[]),
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
ret = dockerng_state.network_present(
'network_foo',
containers=['container'],
)
dockerng_create_network.assert_called_with('network_foo', driver=None)
dockerng_connect_container_to_network.assert_called_with('abcd',
'network_foo')
self.assertEqual(ret, {'name': 'network_foo',
'comment': '',
'changes': {'connected': 'connected',
'created': 'created'},
'result': True})
示例7: test_running_with_no_predifined_volume
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
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')
示例8: test_running_with_udp_bindings
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_running_with_udp_bindings(self):
'''
Check that `ports` contains ports defined from `port_bindings` with
protocol declaration passed as tuple. As stated by docker-py
documentation
https://docker-py.readthedocs.io/en/latest/port-bindings/
In sls:
.. code-block:: yaml
container:
dockerng.running:
- port_bindings:
- '9090:9797/udp'
is equivalent of:
.. code-block:: yaml
container:
dockerng.running:
- ports:
- 9797/udp
- port_bindings:
- '9090:9797/udp'
'''
dockerng_create = Mock()
dockerng_start = Mock()
dockerng_inspect_image = Mock(return_value={
'Id': 'abcd',
'Config': {'ExposedPorts': {}}
})
__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,
'dockerng.start': dockerng_start,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
dockerng_state.running(
'cont',
image='image:latest',
port_bindings=['9090:9797/udp'])
dockerng_create.assert_called_with(
'image:latest',
validate_input=False,
name='cont',
ports=[(9797, 'udp')],
port_bindings={'9797/udp': [9090]},
validate_ip_addrs=False,
client_timeout=60)
dockerng_start.assert_called_with('cont')
示例9: test_running_with_predifined_ports
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_running_with_predifined_ports(self):
'''
Test dockerng.running function with an image
that expose ports (via Dockerfile EXPOSE statement).
Check that `ports` contains ports defined on Image and by
`port_bindings` argument.
Inside Dockerfile:
.. code-block::
EXPOSE 9898
In sls:
.. code-block:: yaml
container:
dockerng.running:
- port_bindings:
- '9090:9797/tcp'
'''
dockerng_create = Mock()
dockerng_start = Mock()
dockerng_inspect_image = Mock(return_value={
'Id': 'abcd',
'Config': {'ExposedPorts': {'9898/tcp': {}}}
})
__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,
'dockerng.start': dockerng_start,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
dockerng_state.running(
'cont',
image='image:latest',
port_bindings=['9090:9797/tcp'])
dockerng_create.assert_called_with(
'image:latest',
validate_input=False,
name='cont',
ports=[9797],
port_bindings={9797: [9090]},
validate_ip_addrs=False,
client_timeout=60)
dockerng_start.assert_called_with('cont')
示例10: test_running_compare_images_by_id
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_running_compare_images_by_id(self):
'''
Make sure the container is running
against expected image.
Here the local image is named 'image:latest' and the container
is also running against an image called 'image:latest'.
Therefore the image ids are diverging because the tag 'image:latest'
moved to a fresher image.
Thus this test make sure the old container is droped and recreated.
'''
new_fake_image_id = 'abcdefgh'
old_fake_image_id = '123456789'
dockerng_inspect_image = Mock(return_value={'Id': new_fake_image_id})
dockerng_inspect_container = Mock(
return_value={'Image': old_fake_image_id,
'Config': {'Image': 'image:latest'}})
dockerng_list_containers = Mock(return_value=['cont'])
dockerng__state = Mock(return_value='running')
dockerng_stop = Mock(return_value={'result': True})
dockerng_rm = Mock(return_value=['container-id'])
__salt__ = {'dockerng.list_containers': dockerng_list_containers,
'dockerng.inspect_container': dockerng_inspect_container,
'dockerng.inspect_image': dockerng_inspect_image,
'dockerng.list_tags': MagicMock(),
'dockerng.state': dockerng__state,
'dockerng.pull': MagicMock(return_value=new_fake_image_id),
'dockerng.create': MagicMock(return_value='new_container'),
'dockerng.start': MagicMock(),
'dockerng.stop': dockerng_stop,
'dockerng.rm': dockerng_rm,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
ret = dockerng_state.running(
'cont',
image='image:latest',
)
dockerng_stop.assert_called_with('cont', timeout=10, unpause=True)
dockerng_rm.assert_called_with('cont')
self.assertEqual(ret, {'name': 'cont',
'comment': "Container 'cont' was replaced",
'result': True,
'changes': {'added': 'new_container',
'image': new_fake_image_id,
'removed': ['container-id']}
})
示例11: test_volume_absent
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
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})
示例12: test_running_with_labels_from_image
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
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)
示例13: test_volume_present
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
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})
示例14: test_network_absent
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_network_absent(self):
'''
Test dockerng.network_absent
'''
dockerng_remove_network = Mock(return_value='removed')
dockerng_disconnect_container_from_network = Mock(return_value='disconnected')
__salt__ = {'dockerng.remove_network': dockerng_remove_network,
'dockerng.disconnect_container_from_network': dockerng_disconnect_container_from_network,
'dockerng.networks': Mock(return_value=[{'Containers': {'container': {}}}]),
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
ret = dockerng_state.network_absent(
'network_foo',
)
dockerng_disconnect_container_from_network.assert_called_with('container',
'network_foo')
dockerng_remove_network.assert_called_with('network_foo')
self.assertEqual(ret, {'name': 'network_foo',
'comment': '',
'changes': {'disconnected': 'disconnected',
'removed': 'removed'},
'result': True})
示例15: test_running_with_no_predifined_ports
# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import assert_called_with [as 别名]
def test_running_with_no_predifined_ports(self):
'''
Test dockerng.running function with an image
that doens't have EXPOSE defined.
The ``port_bindings`` argument, should create a container
with ``ports`` extracted from ``port_bindings``.
'''
dockerng_create = Mock()
dockerng_start = Mock()
dockerng_inspect_image = Mock(return_value={
'Id': 'abcd',
'Config': {'Config': {'ExposedPorts': {}}},
})
__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,
'dockerng.start': dockerng_start,
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
dockerng_state.running(
'cont',
image='image:latest',
port_bindings=['9090:9797/tcp'])
dockerng_create.assert_called_with(
'image:latest',
validate_input=False,
name='cont',
ports=[9797],
port_bindings={9797: [9090]},
validate_ip_addrs=False,
client_timeout=60)
dockerng_start.assert_called_with('cont')