本文整理汇总了Python中webob.exc.HTTPInternalServerError方法的典型用法代码示例。如果您正苦于以下问题:Python exc.HTTPInternalServerError方法的具体用法?Python exc.HTTPInternalServerError怎么用?Python exc.HTTPInternalServerError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.exc
的用法示例。
在下文中一共展示了exc.HTTPInternalServerError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unmapped_tacker_error_with_json
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_unmapped_tacker_error_with_json(self):
msg = u'\u7f51\u7edc'
class TestException(n_exc.TackerException):
message = msg
expected_res = {'body': {
'TackerError': {
'type': 'TestException',
'message': msg,
'detail': ''}}}
controller = mock.MagicMock()
controller.test.side_effect = TestException()
resource = webtest.TestApp(wsgi_resource.Resource(controller))
environ = {'wsgiorg.routing_args': (None, {'action': 'test',
'format': 'json'})}
res = resource.get('', extra_environ=environ, expect_errors=True)
self.assertEqual(exc.HTTPInternalServerError.code, res.status_int)
self.assertEqual(expected_res,
wsgi.JSONDeserializer().deserialize(res.body))
示例2: test_unmapped_tacker_error_localized
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_unmapped_tacker_error_localized(self, mock_translation):
msg_translation = 'Translated error'
mock_translation.return_value = msg_translation
msg = _('Unmapped error')
class TestException(n_exc.TackerException):
message = msg
controller = mock.MagicMock()
controller.test.side_effect = TestException()
resource = webtest.TestApp(wsgi_resource.Resource(controller))
environ = {'wsgiorg.routing_args': (None, {'action': 'test',
'format': 'json'})}
res = resource.get('', extra_environ=environ, expect_errors=True)
self.assertEqual(exc.HTTPInternalServerError.code, res.status_int)
self.assertIn(msg_translation,
str(wsgi.JSONDeserializer().deserialize(res.body)))
示例3: test_unhandled_error_with_json
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_unhandled_error_with_json(self):
expected_res = {'body': {'TackerError':
{'detail': '',
'message':
_('Request Failed: internal server error'
' while processing your request.'),
'type': 'HTTPInternalServerError'}}}
controller = mock.MagicMock()
controller.test.side_effect = Exception()
resource = webtest.TestApp(wsgi_resource.Resource(controller))
environ = {'wsgiorg.routing_args': (None, {'action': 'test',
'format': 'json'})}
res = resource.get('', extra_environ=environ, expect_errors=True)
self.assertEqual(exc.HTTPInternalServerError.code, res.status_int)
self.assertEqual(expected_res,
wsgi.JSONDeserializer().deserialize(res.body))
示例4: __call__
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def __call__(self, req):
action = req.urlvars.get("action")
try:
try:
method = getattr(self, "json_" + action)
except AttributeError:
raise exc.HTTPNotFound("No action '%s'" % action)
resp = method(req)
if isinstance(resp, (dict, list)):
try:
resp = json.dumps(resp, sort_keys=True)
except (TypeError, ValueError, IndexError, AttributeError) as json_exc:
raise exc.HTTPInternalServerError("JSON serialization error (%s)" % json_exc)
if isinstance(resp, basestring):
resp = Response(body=resp, content_type="application/json")
except exc.HTTPException as http_exc:
resp = http_exc
return resp
示例5: test_protectables_instances_show_Invalid
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_protectables_instances_show_Invalid(
self,
mock_get_all,
mock_show_protectable_instance):
req = fakes.HTTPRequest.blank('/v1/protectables')
mock_get_all.return_value = ["OS::Keystone::Project"]
mock_show_protectable_instance.side_effect = \
exception.ProtectableResourceNotFound
self.assertRaises(exc.HTTPNotFound,
self.controller.instances_show,
req,
'OS::Keystone::Project',
'efc6a88b-9096-4bb6-8634-cda182a6e12a')
mock_show_protectable_instance.side_effect = exception.KarborException
self.assertRaises(exc.HTTPInternalServerError,
self.controller.instances_show,
req,
'OS::Keystone::Project',
'efc6a88b-9096-4bb6-8634-cda182a6e12a')
mock_show_protectable_instance.return_value = None
self.assertRaises(exc.HTTPInternalServerError,
self.controller.instances_show,
req,
'OS::Keystone::Project',
'efc6a88b-9096-4bb6-8634-cda182a6e12a')
示例6: test_subnet_create_subnet_db_error
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_subnet_create_subnet_db_error(self):
fake_sn_id = 'fake_sn_id'
req = fakes.HTTPRequest.blank('/subnets', version="2.51")
context = req.environ['manila.context']
body = {
'share-network-subnet': self._setup_create_test_request_body()
}
mock_sn_get = self.mock_object(db_api, 'share_network_get')
mock__validate_subnet = self.mock_object(
self.controller, '_validate_subnet')
mock_db_subnet_create = self.mock_object(
db_api, 'share_network_subnet_create',
mock.Mock(side_effect=db_exception.DBError()))
expected_data = copy.deepcopy(body['share-network-subnet'])
expected_data['availability_zone_id'] = fake_az['id']
expected_data.pop('availability_zone')
self.assertRaises(exc.HTTPInternalServerError,
self.controller.create,
req,
fake_sn_id,
body)
mock_sn_get.assert_called_once_with(context, fake_sn_id)
self.mock_az_get.assert_called_once_with(context, fake_az['name'])
mock__validate_subnet.assert_called_once_with(
context, fake_sn_id, az=fake_az)
mock_db_subnet_create.assert_called_once_with(
context, expected_data
)
示例7: test_create_db_api_exception
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_create_db_api_exception(self):
with mock.patch.object(db_api,
'share_network_create',
mock.Mock(side_effect=db_exception.DBError)):
self.assertRaises(webob_exc.HTTPInternalServerError,
self.controller.create,
self.req,
self.body)
示例8: test_create_error_on_subnet_creation
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_create_error_on_subnet_creation(self):
data = {
'neutron_net_id': 'fake',
'neutron_subnet_id': 'fake',
'id': fake_share_network['id']
}
subnet_data = copy.deepcopy(data)
self.mock_object(db_api, 'share_network_create',
mock.Mock(return_value=fake_share_network))
self.mock_object(db_api, 'share_network_subnet_create',
mock.Mock(side_effect=db_exception.DBError()))
self.mock_object(db_api, 'share_network_delete')
body = {share_networks.RESOURCE_NAME: data}
self.assertRaises(webob_exc.HTTPInternalServerError,
self.controller.create,
self.req,
body)
db_api.share_network_create.assert_called_once_with(self.context, data)
subnet_data['share_network_id'] = data['id']
subnet_data.pop('id')
db_api.share_network_subnet_create.assert_called_once_with(
self.context, subnet_data)
db_api.share_network_delete.assert_called_once_with(
self.context, fake_share_network['id'])
示例9: convert_exception_to_http_exc
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def convert_exception_to_http_exc(e, faults, language):
serializer = wsgi.JSONDictSerializer()
e = translate(e, language)
body = serializer.serialize(
{'TackerError': get_exception_data(e)})
kwargs = {'body': body, 'content_type': 'application/json'}
if isinstance(e, exc.HTTPException):
# already an HTTP error, just update with content type and body
e.body = body
e.content_type = kwargs['content_type']
return e
if isinstance(e, (exceptions.TackerException, netaddr.AddrFormatError,
oslo_policy.PolicyNotAuthorized)):
for fault in faults:
if isinstance(e, fault):
mapped_exc = faults[fault]
break
else:
mapped_exc = exc.HTTPInternalServerError
return mapped_exc(**kwargs)
if isinstance(e, NotImplementedError):
# NOTE(armando-migliaccio): from a client standpoint
# it makes sense to receive these errors, because
# extensions may or may not be implemented by
# the underlying plugin. So if something goes south,
# because a plugin does not implement a feature,
# returning 500 is definitely confusing.
kwargs['body'] = serializer.serialize(
{'NotImplementedError': get_exception_data(e)})
return exc.HTTPNotImplemented(**kwargs)
# NOTE(jkoelker) Everything else is 500
# Do not expose details of 500 error to clients.
msg = _('Request Failed: internal server error while '
'processing your request.')
msg = translate(msg, language)
kwargs['body'] = serializer.serialize(
{'TackerError': get_exception_data(exc.HTTPInternalServerError(msg))})
return exc.HTTPInternalServerError(**kwargs)
示例10: test_get_vnf_package_vnfd_failed_with_internal_server_error
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_get_vnf_package_vnfd_failed_with_internal_server_error(
self, mock_vnf_by_id, mock_get_vnf_package_vnfd):
mock_vnf_by_id.return_value = fakes.return_vnfpkg_obj()
mock_get_vnf_package_vnfd.side_effect = tacker_exc.FailedToGetVnfdData
req = fake_request.HTTPRequest.blank(
'/vnf_packages/%s/vnfd'
% constants.UUID)
req.headers['Accept'] = 'application/zip'
req.method = 'GET'
resp = req.get_response(self.app)
self.assertRaises(exc.HTTPInternalServerError,
self.controller.get_vnf_package_vnfd,
req, constants.UUID)
self.assertEqual(http_client.INTERNAL_SERVER_ERROR, resp.status_code)
示例11: test_no_route_args
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_no_route_args(self):
controller = mock.MagicMock()
resource = webtest.TestApp(wsgi_resource.Resource(controller))
environ = {}
res = resource.get('', extra_environ=environ, expect_errors=True)
self.assertEqual(exc.HTTPInternalServerError.code, res.status_int)
示例12: json_engine
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def json_engine(self, req): # pylint: disable=R0201,W0613
""" Return torrent engine data.
"""
try:
return stats.engine_data(config.engine)
except (error.LoggableError, xmlrpc.ERRORS) as torrent_exc:
raise exc.HTTPInternalServerError(str(torrent_exc))
示例13: commits_html
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def commits_html(self, **kw):
if self.req.new_commits is not None:
with self.req.push_downstream_context():
downstream_app = c.app
return SCMLogWidget().display(value=self.req.commits, app=downstream_app)
task_status = self.req.commits_task_status()
if task_status is None:
raise exc.HTTPNotFound
elif task_status == 'error':
raise exc.HTTPInternalServerError
elif task_status in ('busy', 'ready'):
raise exc.HTTPAccepted
示例14: _raise_unknown_exception
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def _raise_unknown_exception(self, exception_instance):
LOG.exception('An unknown exception happened')
value = exception_instance.msg if isinstance(
exception_instance, exception.KarborException) else type(
exception_instance)
msg = (_('Unexpected API Error. Please report this at '
'http://bugs.launchpad.net/karbor/ and attach the '
'Karbor API log if possible.\n%s') % value)
raise exc.HTTPInternalServerError(explanation=msg)
示例15: test_create_operation_receive_unknown_except
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPInternalServerError [as 别名]
def test_create_operation_receive_unknown_except(self):
self.remote_operation_api._create_operation_exception =\
exception.TriggerNotFound(id=None)
param = self.default_create_operation_param.copy()
body = self._get_create_operation_request_body(param)
self.assertRaises(exc.HTTPInternalServerError,
self.controller.create,
self.req, body=body)
self.remote_operation_api._create_operation_exception = None