本文整理汇总了Python中senlin.tests.unit.apiv1.shared.request_with_middleware函数的典型用法代码示例。如果您正苦于以下问题:Python request_with_middleware函数的具体用法?Python request_with_middleware怎么用?Python request_with_middleware使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request_with_middleware函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_node_create_with_bad_profile
def test_node_create_with_bad_profile(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
body = {
'node': {
'name': 'test_node',
'profile_id': 'bad-profile',
'cluster_id': None,
'role': None,
'metadata': {},
}
}
req = self._post('/nodes', json.dumps(body))
error = senlin_exc.ProfileNotFound(profile='bad-profile')
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, tenant_id=self.project,
body=body)
mock_call.assert_called_once_with(req.context,
('node_create', body['node']))
self.assertEqual(404, resp.json['code'])
self.assertEqual('ProfileNotFound', resp.json['error']['type'])
self.assertIsNone(resp.json['error']['traceback'])
开发者ID:KongJustin,项目名称:senlin,代码行数:26,代码来源:test_nodes.py
示例2: test_receiver_create_unapplicable_action
def test_receiver_create_unapplicable_action(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
action = 'BAD'
body = {
'receiver': {
'name': 'test_receiver',
'type': 'webhook',
'cluster_id': 'FAKE_CLUSTER',
'action': action,
}
}
req = self._post('/receivers', jsonutils.dumps(body))
msg = 'Action BAD is not applicable clusters.'
error = senlin_exc.BadRequest(msg=msg)
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, body=body)
expected = body['receiver']
type_name = expected.pop('type')
expected['type_name'] = type_name
expected['actor'] = None
expected['params'] = None
mock_call.assert_called_once_with(req.context,
('receiver_create', expected))
self.assertEqual(400, resp.json['code'])
self.assertEqual('BadRequest', resp.json['error']['type'])
开发者ID:gongwayne,项目名称:Openstack,代码行数:31,代码来源:test_receivers.py
示例3: test_index_err_denied_policy
def test_index_err_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, "index", False)
req = self._get("/events")
resp = shared.request_with_middleware(fault.FaultWrapper, self.controller.index, req, tenant_id=self.project)
self.assertEqual(403, resp.status_int)
self.assertIn("403 Forbidden", six.text_type(resp))
开发者ID:KongJustin,项目名称:senlin,代码行数:7,代码来源:test_events.py
示例4: test_receiver_create_with_bad_type
def test_receiver_create_with_bad_type(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
r_type = 'unsupported'
body = {
'receiver': {
'name': 'test_receiver',
'type': r_type,
'cluster_id': 'FAKE_CLUSTER',
'action': 'test_action',
}
}
req = self._post('/receivers', jsonutils.dumps(body))
msg = _('receiver obj_type (%s) is unsupported.') % r_type
error = senlin_exc.BadRequest(msg=msg)
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, body=body)
expected_args = body['receiver']
type_name = expected_args.pop('type')
expected_args['type_name'] = type_name
expected_args['actor'] = None
expected_args['params'] = None
mock_call.assert_called_once_with(req.context,
('receiver_create', expected_args))
self.assertEqual(400, resp.json['code'])
self.assertEqual('BadRequest', resp.json['error']['type'])
开发者ID:gongwayne,项目名称:Openstack,代码行数:31,代码来源:test_receivers.py
示例5: test_node_update_invalid_profile
def test_node_update_invalid_profile(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'update', True)
nid = 'aaaa-bbbb-cccc'
body = {
'node': {
'name': 'test_node',
'profile_id': 'profile-not-exist',
'role': None,
'metadata': {},
}
}
req = self._patch('/nodes/%(node_id)s' % {'node_id': nid},
jsonutils.dumps(body))
error = senlin_exc.ProfileNotFound(profile=nid)
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=shared.to_remote_error(error))
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.update,
req, node_id=nid, body=body)
mock_call.assert_called_with(
req.context,
('node_update', {
'identity': nid,
'name': 'test_node',
'profile_id': 'profile-not-exist',
'role': None,
'metadata': {},
})
)
self.assertEqual(404, resp.json['code'])
self.assertEqual('ProfileNotFound', resp.json['error']['type'])
开发者ID:gongwayne,项目名称:Openstack,代码行数:34,代码来源:test_nodes.py
示例6: test_profile_create_with_bad_type
def test_profile_create_with_bad_type(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
type_name = 'unknown_type'
body = {
'profile': {
'name': 'test_profile',
'spec': {
'type': type_name,
'version': '1.0',
'properties': {'param': 'value'},
},
'spec': {'param': 'value'},
'metadata': {},
}
}
req = self._post('/profiles', jsonutils.dumps(body))
error = senlin_exc.ProfileTypeNotFound(profile_type=type_name)
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, body=body)
mock_call.assert_called_once_with(req.context,
('profile_create', body['profile']))
self.assertEqual(404, resp.json['code'])
self.assertEqual('ProfileTypeNotFound', resp.json['error']['type'])
开发者ID:gongwayne,项目名称:Openstack,代码行数:29,代码来源:test_profiles.py
示例7: test_node_create_with_bad_cluster
def test_node_create_with_bad_cluster(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
body = {
'node': {
'name': 'test_node',
'profile_id': 'xxxx-yyyy-zzzz',
'cluster_id': 'non-existent-cluster',
'role': None,
'metadata': {},
}
}
req = self._post('/nodes', jsonutils.dumps(body))
error = senlin_exc.ClusterNotFound(cluster='non-existent-cluster')
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, body=body)
mock_call.assert_called_once_with(req.context,
('node_create', body['node']))
self.assertEqual(404, resp.json['code'])
self.assertEqual('ClusterNotFound', resp.json['error']['type'])
开发者ID:gongwayne,项目名称:Openstack,代码行数:25,代码来源:test_nodes.py
示例8: test_webhook_create_with_obj_id_notfound
def test_webhook_create_with_obj_id_notfound(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
obj_id = 'false_obj_id'
body = {
'webhook': {
'name': 'test_webhook',
'obj_type': 'cluster',
'obj_id': obj_id,
'action': 'test_action',
'credential': {
'user_id': 'test_user_id',
'password': 'test_pass',
},
'params': {
'test_param': 'test_value'
},
}
}
req = self._post('/webhooks', json.dumps(body))
error = senlin_exc.ClusterNotFound(cluster=obj_id)
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, tenant_id=self.project,
body=body)
expected_args = body['webhook']
mock_call.assert_called_once_with(req.context,
('webhook_create', expected_args))
self.assertEqual(404, resp.json['code'])
self.assertEqual('ClusterNotFound', resp.json['error']['type'])
self.assertIsNone(resp.json['error']['traceback'])
开发者ID:KongJustin,项目名称:senlin,代码行数:35,代码来源:test_webhooks.py
示例9: test_policy_create_with_spec_validation_failed
def test_policy_create_with_spec_validation_failed(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
body = {
'policy': {
'name': 'test_policy',
'spec': {
'type': 'policy_type',
'version': '1.0',
'properties': {'param': 'value'}
},
}
}
req = self._post('/policies', jsonutils.dumps(body))
msg = 'Spec validation error (param): value'
error = senlin_exc.SpecValidationFailed(message=msg)
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, body=body)
expected_args = body['policy']
mock_call.assert_called_once_with(req.context,
('policy_create', expected_args))
self.assertEqual(400, resp.json['code'])
self.assertEqual('SpecValidationFailed', resp.json['error']['type'])
开发者ID:gongwayne,项目名称:Openstack,代码行数:28,代码来源:test_policies.py
示例10: test_webhook_create_credential_missing
def test_webhook_create_credential_missing(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
body = {
'webhook': {
'name': 'test_webhook',
'obj_type': 'test_obj_type',
'obj_id': 'test_obj_id',
'action': 'test_action',
'credential': None,
'params': {
'test_param': 'test_value'
},
}
}
req = self._post('/webhooks', json.dumps(body))
msg = _('The credential parameter is missing')
error = senlin_exc.SenlinBadRequest(msg=msg)
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, tenant_id=self.project,
body=body)
expected_args = body['webhook']
mock_call.assert_called_once_with(req.context,
('webhook_create', expected_args))
self.assertEqual(400, resp.json['code'])
self.assertEqual('SenlinBadRequest', resp.json['error']['type'])
self.assertIsNone(resp.json['error']['traceback'])
开发者ID:KongJustin,项目名称:senlin,代码行数:32,代码来源:test_webhooks.py
示例11: test_receiver_create_with_cluster_id_notfound
def test_receiver_create_with_cluster_id_notfound(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
cluster_id = 'FAKE_ID'
body = {
'receiver': {
'name': 'test_receiver',
'type': 'webhook',
'cluster_id': cluster_id,
'action': 'test_action',
}
}
req = self._post('/receivers', jsonutils.dumps(body))
error = senlin_exc.ClusterNotFound(cluster=cluster_id)
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
side_effect=error)
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, body=body)
expected_args = body['receiver']
type_name = expected_args.pop('type')
expected_args['type_name'] = type_name
expected_args['actor'] = None
expected_args['params'] = None
mock_call.assert_called_once_with(req.context,
('receiver_create', expected_args))
self.assertEqual(404, resp.json['code'])
self.assertEqual('ClusterNotFound', resp.json['error']['type'])
开发者ID:gongwayne,项目名称:Openstack,代码行数:30,代码来源:test_receivers.py
示例12: test_create_with_spec_validation_failed
def test_create_with_spec_validation_failed(self, mock_call, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'create', True)
body = {
'trigger': {
'name': 'test_trigger',
'spec': {'type': 'alarm_type', 'param': 'value'},
'enabled': True,
}
}
req = self._post('/triggers', jsonutils.dumps(body))
msg = 'Spec validation error (param): value'
error = senlin_exc.SpecValidationFailed(message=msg)
mock_call.side_effect = error
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.create,
req, tenant_id=self.project,
body=body)
mock_call.assert_called_once_with(
req.context,
('trigger_create',
{'name': 'test_trigger', 'description': None,
'spec': {'type': 'alarm_type', 'param': 'value'},
'enabled': True, 'state': None, 'severity': None}))
self.assertEqual(400, resp.json['code'])
self.assertEqual('SpecValidationFailed', resp.json['error']['type'])
self.assertIsNone(resp.json['error']['traceback'])
开发者ID:KongJustin,项目名称:senlin,代码行数:29,代码来源:test_triggers.py
示例13: test_node_index_denied_policy
def test_node_index_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'index', False)
req = self._get('/nodes')
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.index, req)
self.assertEqual(403, resp.status_int)
self.assertIn('403 Forbidden', six.text_type(resp))
开发者ID:gongwayne,项目名称:Openstack,代码行数:8,代码来源:test_nodes.py
示例14: test_profile_type_list_err_denied_policy
def test_profile_type_list_err_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'index', False)
req = self._get('/profile_types')
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.index,
req, tenant_id=self.project)
self.assertEqual(403, resp.status_int)
self.assertIn('403 Forbidden', six.text_type(resp))
开发者ID:KongJustin,项目名称:senlin,代码行数:9,代码来源:test_profile_types.py
示例15: test_profile_type_get_err_denied_policy
def test_profile_type_get_err_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'get', False)
type_name = 'BogusProfileType'
req = self._get('/profile_types/%(type)s' % {'type': type_name})
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.get,
req, type_name=type_name)
self.assertEqual(403, resp.status_int)
self.assertIn('403 Forbidden', six.text_type(resp))
开发者ID:gongwayne,项目名称:Openstack,代码行数:10,代码来源:test_profile_types.py
示例16: test_event_get_denied_policy
def test_event_get_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, "get", False)
event_id = "non-existent-event"
req = self._get("/events/%(event_id)s" % {"event_id": event_id})
resp = shared.request_with_middleware(
fault.FaultWrapper, self.controller.get, req, tenant_id=self.project, event_id=event_id
)
self.assertEqual(403, resp.status_int)
self.assertIn("403 Forbidden", six.text_type(resp))
开发者ID:KongJustin,项目名称:senlin,代码行数:11,代码来源:test_events.py
示例17: test_cluster_policy_index_denied_policy
def test_cluster_policy_index_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, "index", False)
cid = "FAKE_CLUSTER"
req = self._get("/cluster_policy/%s" % cid)
resp = shared.request_with_middleware(
fault.FaultWrapper, self.controller.index, req, tenant_id=self.project, cluster_id=cid
)
self.assertEqual(403, resp.status_int)
self.assertIn("403 Forbidden", six.text_type(resp))
开发者ID:KongJustin,项目名称:senlin,代码行数:11,代码来源:test_cluster_policies.py
示例18: test_policy_delete_err_denied_policy
def test_policy_delete_err_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'delete', False)
pid = 'aaaa-bbbb-cccc'
req = self._delete('/policies/%(policy_id)s' % {'policy_id': pid})
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.delete,
req, policy_id=pid)
self.assertEqual(403, resp.status_int)
self.assertIn('403 Forbidden', six.text_type(resp))
开发者ID:gongwayne,项目名称:Openstack,代码行数:11,代码来源:test_policies.py
示例19: test_policy_get_denied_policy
def test_policy_get_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'get', False)
pid = 'non-existent-policy'
req = self._get('/policies/%(policy_id)s' % {'policy_id': pid})
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.get,
req, policy_id=pid)
self.assertEqual(403, resp.status_int)
self.assertIn('403 Forbidden', six.text_type(resp))
开发者ID:gongwayne,项目名称:Openstack,代码行数:11,代码来源:test_policies.py
示例20: test_policy_type_schema_err_denied_policy
def test_policy_type_schema_err_denied_policy(self, mock_enforce):
self._mock_enforce_setup(mock_enforce, 'schema', False)
type_name = 'BogusPolicyType'
req = self._get('/policy_types/%(type)s' % {'type': type_name})
resp = shared.request_with_middleware(fault.FaultWrapper,
self.controller.schema,
req, tenant_id=self.project,
type_name=type_name)
self.assertEqual(403, resp.status_int)
self.assertIn('403 Forbidden', six.text_type(resp))
开发者ID:KongJustin,项目名称:senlin,代码行数:11,代码来源:test_policy_types.py
注:本文中的senlin.tests.unit.apiv1.shared.request_with_middleware函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论