本文整理汇总了Python中senlin.tests.unit.apiv1.shared.request_with_middleware函数的典型用法代码示例。如果您正苦于以下问题:Python request_with_middleware函数的具体用法?Python request_with_middleware怎么用?Python request_with_middleware使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request_with_middleware函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'])
示例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'])
示例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))
示例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'])
示例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'])
示例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'])
示例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'])
示例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'])
示例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'])
示例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'])
示例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'])
示例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'])
示例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))
示例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))
示例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))