本文整理汇总了Python中unittest.mock.ANY属性的典型用法代码示例。如果您正苦于以下问题:Python mock.ANY属性的具体用法?Python mock.ANY怎么用?Python mock.ANY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类unittest.mock
的用法示例。
在下文中一共展示了mock.ANY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_all_capsules
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_all_capsules(self, mock_container_get_by_uuid,
mock_capsule_list,
mock_container_show):
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context,
**test_container)
mock_container_get_by_uuid.return_value = test_container_obj
test_capsule = utils.create_test_container(context=self.context)
test_capsule_obj = objects.Capsule(self.context, **test_capsule)
mock_capsule_list.return_value = [test_capsule_obj]
mock_container_show.return_value = test_container_obj
response = self.app.get('/v1/capsules/')
mock_capsule_list.assert_called_once_with(mock.ANY,
1000, None, 'id', 'asc',
filters=None)
context = mock_capsule_list.call_args[0][0]
self.assertIs(False, context.all_projects)
self.assertEqual(200, response.status_int)
actual_capsules = response.json['capsules']
self.assertEqual(1, len(actual_capsules))
self.assertEqual(test_capsule['uuid'],
actual_capsules[0].get('uuid'))
示例2: test_get_all_capsules_with_exception
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_all_capsules_with_exception(self,
mock_container_get_by_uuid,
mock_capsule_list):
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context,
**test_container)
mock_container_get_by_uuid.return_value = test_container_obj
test_capsule = utils.create_test_container(context=self.context)
test_capsule_obj = objects.Capsule(self.context, **test_capsule)
mock_capsule_list.return_value = [test_capsule_obj]
response = self.app.get('/v1/capsules/')
mock_capsule_list.assert_called_once_with(mock.ANY,
1000, None, 'id', 'asc',
filters=None)
context = mock_capsule_list.call_args[0][0]
self.assertIs(False, context.all_projects)
self.assertEqual(200, response.status_int)
actual_capsules = response.json['capsules']
self.assertEqual(1, len(actual_capsules))
self.assertEqual(test_capsule['uuid'],
actual_capsules[0].get('uuid'))
示例3: test_get_all_availability_zones
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_all_availability_zones(self,
mock_availability_zone_list,
mock_policy):
mock_policy.return_value = True
test_a_zone = utils.get_test_zun_service()
availability_zones = [objects.ZunService(self.context, **test_a_zone)]
mock_availability_zone_list.return_value = availability_zones
response = self.get('/v1/availability_zones')
mock_availability_zone_list.assert_called_once_with(
mock.ANY, 1000, None, 'availability_zone', 'asc')
self.assertEqual(200, response.status_int)
actual_a_zones = response.json['availability_zones']
self.assertEqual(1, len(actual_a_zones))
self.assertEqual(test_a_zone['availability_zone'],
actual_a_zones[0].get('availability_zone'))
示例4: test_get_all_images
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_all_images(self, mock_image_list, mock_policy_enforce):
test_image = utils.get_test_image()
images = [objects.Image(self.context, **test_image)]
mock_image_list.return_value = images
response = self.get('/v1/images/')
mock_image_list.assert_called_once_with(mock.ANY,
1000, None, 'id', 'asc',
filters=None)
self.assertEqual(200, response.status_int)
actual_images = response.json['images']
self.assertEqual(1, len(actual_images))
self.assertEqual(test_image['uuid'],
actual_images[0].get('uuid'))
self.assertEqual(test_image['host'],
actual_images[0].get('host'))
示例5: test_get_all_registries_all_projects
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_all_registries_all_projects(self, mock_registry_list,
mock_policy):
mock_policy.return_value = True
test_registry = utils.get_test_registry()
registries = [objects.Registry(self.context, **test_registry)]
mock_registry_list.return_value = registries
response = self.get('/v1/registries/?all_projects=1')
mock_registry_list.assert_called_once_with(mock.ANY,
1000, None, 'id', 'asc',
filters={})
context = mock_registry_list.call_args[0][0]
self.assertIs(True, context.all_projects)
self.assertEqual(200, response.status_int)
actual_registries = response.json['registries']
self.assertEqual(1, len(actual_registries))
self.assertEqual(test_registry['uuid'],
actual_registries[0].get('uuid'))
示例6: test_get_all_containers_by_admin
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_all_containers_by_admin(self, mock_container_list, mock_can):
mock_can.return_value = True
test_container = utils.get_test_container()
containers = [objects.Container(self.context, **test_container)]
mock_container_list.return_value = containers
response = self.get('/v1/containers/')
mock_container_list.assert_called_once_with(mock.ANY,
1000, None, 'id', 'asc',
filters={})
context = mock_container_list.call_args[0][0]
self.assertIs(False, context.all_projects)
self.assertEqual(200, response.status_int)
actual_containers = response.json['containers']
self.assertEqual(1, len(actual_containers))
self.assertEqual(test_container['uuid'],
actual_containers[0].get('uuid'))
self.assertIn('host', actual_containers[0])
示例7: test_get_all_containers_all_projects
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_all_containers_all_projects(self, mock_container_list,
mock_policy):
mock_policy.return_value = True
test_container = utils.get_test_container()
containers = [objects.Container(self.context, **test_container)]
mock_container_list.return_value = containers
response = self.get('/v1/containers/?all_projects=1')
mock_container_list.assert_called_once_with(mock.ANY,
1000, None, 'id', 'asc',
filters={})
context = mock_container_list.call_args[0][0]
self.assertIs(True, context.all_projects)
self.assertEqual(200, response.status_int)
actual_containers = response.json['containers']
self.assertEqual(1, len(actual_containers))
self.assertEqual(test_container['uuid'],
actual_containers[0].get('uuid'))
示例8: test_get_one_by_uuid
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_one_by_uuid(self, mock_container_get_by_uuid,
mock_container_show):
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_container_get_by_uuid.return_value = test_container_obj
mock_container_show.return_value = test_container_obj
response = self.get('/v1/containers/%s/' % test_container['uuid'])
mock_container_get_by_uuid.assert_called_once_with(
mock.ANY,
test_container['uuid'])
context = mock_container_get_by_uuid.call_args[0][0]
self.assertIs(False, context.all_projects)
self.assertEqual(200, response.status_int)
self.assertEqual(test_container['uuid'],
response.json['uuid'])
self.assertNotIn('host', response.json)
示例9: test_get_one_by_uuid_all_projects
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_get_one_by_uuid_all_projects(self, mock_container_get_by_uuid,
mock_container_show, mock_policy):
mock_policy.return_value = True
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_container_get_by_uuid.return_value = test_container_obj
mock_container_show.return_value = test_container_obj
response = self.get('/v1/containers/%s/?all_projects=1' %
test_container['uuid'])
mock_container_get_by_uuid.assert_called_once_with(
mock.ANY,
test_container['uuid'])
context = mock_container_get_by_uuid.call_args[0][0]
self.assertIs(True, context.all_projects)
self.assertEqual(200, response.status_int)
self.assertEqual(test_container['uuid'],
response.json['uuid'])
示例10: _action_test
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def _action_test(self, test_container_obj, action, ident_field,
mock_container_action, status_code, query_param=''):
ident = test_container_obj.uuid
get_by_ident_loc = 'zun.objects.Container.get_by_%s' % ident_field
with patch(get_by_ident_loc) as mock_get_by_indent:
mock_get_by_indent.return_value = test_container_obj
response = self.post('/v1/containers/%s/%s/?%s' %
(ident, action, query_param))
self.assertEqual(status_code, response.status_int)
# Only PUT should work, others like GET should fail
self.assertRaises(AppError, self.get,
('/v1/containers/%s/%s/' %
(ident, action)))
if query_param:
value = query_param.split('=')[1]
mock_container_action.assert_called_once_with(
mock.ANY, test_container_obj, value)
else:
mock_container_action.assert_called_once_with(
mock.ANY, test_container_obj)
示例11: test_delete_container_by_uuid_all_projects
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_delete_container_by_uuid_all_projects(self, mock_get_by_uuid,
mock_container_delete,
mock_validate, mock_policy):
mock_policy.return_value = True
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_get_by_uuid.return_value = test_container_obj
container_uuid = test_container.get('uuid')
response = self.delete('/v1/containers/%s/?all_projects=1' %
container_uuid)
self.assertEqual(204, response.status_int)
mock_container_delete.assert_called_once_with(
mock.ANY, test_container_obj, False)
context = mock_container_delete.call_args[0][0]
self.assertIs(True, context.all_projects)
示例12: test_kill_container_by_uuid
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_kill_container_by_uuid(self,
mock_get_by_uuid, mock_container_kill,
mock_validate):
test_container_obj = objects.Container(self.context,
**utils.get_test_container())
mock_container_kill.return_value = test_container_obj
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_get_by_uuid.return_value = test_container_obj
container_uuid = test_container.get('uuid')
url = '/v1/containers/%s/%s/' % (container_uuid, 'kill')
cmd = {'signal': '9'}
response = self.post(url, cmd)
self.assertEqual(202, response.status_int)
mock_container_kill.assert_called_once_with(
mock.ANY, test_container_obj, cmd['signal'])
示例13: test_resize_by_uuid
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_resize_by_uuid(self, mock_get_by_uuid, mock_container_resize,
mock_validate):
test_container_obj = objects.Container(self.context,
**utils.get_test_container())
mock_container_resize.return_value = test_container_obj
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_get_by_uuid.return_value = test_container_obj
container_name = test_container.get('name')
url = '/v1/containers/%s/%s/' % (container_name, 'resize')
cmd = {'h': '100', 'w': '100'}
response = self.post(url, cmd)
self.assertEqual(200, response.status_int)
mock_container_resize.assert_called_once_with(
mock.ANY, test_container_obj, cmd['h'], cmd['w'])
示例14: test_resize_container
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_resize_container(self, mock_get_by_uuid,
mock_resize_container, mock_validate):
test_container_obj = objects.Container(self.context,
**utils.get_test_container())
mock_resize_container.return_value = test_container_obj
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_get_by_uuid.return_value = test_container_obj
container_name = test_container.get('name')
url = '/v1/containers/%s/resize_container/' % container_name
params = {'cpu': 1, 'memory': '512'}
response = self.post(url, params)
self.assertEqual(202, response.status_int)
mock_resize_container.assert_called_once_with(
mock.ANY, test_container_obj, params)
示例15: test_put_archive_by_uuid
# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import ANY [as 别名]
def test_put_archive_by_uuid(self,
mock_get_by_uuid,
container_put_archive,
mock_validate):
container_put_archive.return_value = ""
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_get_by_uuid.return_value = test_container_obj
container_uuid = test_container.get('uuid')
url = '/v1/containers/%s/%s/' % (container_uuid, 'put_archive')
cmd = {'path': '/home/',
'data': '/home/1.tar'}
response = self.post(url, cmd)
self.assertEqual(200, response.status_int)
container_put_archive.assert_called_once_with(
mock.ANY, test_container_obj, cmd['path'], cmd['data'], mock.ANY)