本文整理匯總了Python中webob.dec方法的典型用法代碼示例。如果您正苦於以下問題:Python webob.dec方法的具體用法?Python webob.dec怎麽用?Python webob.dec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webob
的用法示例。
在下文中一共展示了webob.dec方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _do_test_exception_safety_reflected_in_faults
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def _do_test_exception_safety_reflected_in_faults(self, expose):
class ExceptionWithSafety(exception.ManilaException):
safe = expose
@webob.dec.wsgify
def fail(req):
raise ExceptionWithSafety('some explanation')
api = self._wsgi_app(fail)
resp = webob.Request.blank('/').get_response(api)
self.assertIn('{"computeFault', six.text_type(resp.body), resp.body)
expected = ('ExceptionWithSafety: some explanation' if expose else
'The server has either erred or is incapable '
'of performing the requested operation.')
self.assertIn(expected, six.text_type(resp.body), resp.body)
self.assertEqual(500, resp.status_int, resp.body)
示例2: test_compat_headers
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def test_compat_headers(self):
"""Test that compat headers are set
Compat headers might exist on a super class to support
previous API contracts. This ensures that you can set that to
a list of headers and those values are the same as the
request_id.
"""
@webob.dec.wsgify
def application(req):
return req.environ[request_id.ENV_REQUEST_ID]
app = AltHeader(application)
req = webob.Request.blank('/test')
res = req.get_response(app)
res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
self.assertEqual(res.headers.get("x-compute-req-id"), res_req_id)
self.assertEqual(res.headers.get("x-silly-id"), res_req_id)
示例3: test_global_request_id_set
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def test_global_request_id_set(self):
"""Test that global request_id is set."""
@webob.dec.wsgify
def application(req):
return req.environ[request_id.GLOBAL_REQ_ID]
global_req = "req-%s" % uuid.uuid4()
app = request_id.RequestId(application)
req = webob.Request.blank(
'/test',
headers={"X-OpenStack-Request-ID": global_req})
res = req.get_response(app)
res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
if isinstance(res_req_id, bytes):
res_req_id = res_req_id.decode('utf-8')
# global-request-id in request environ is returned as response body
self.assertEqual(res.body.decode('utf-8'), global_req)
self.assertNotEqual(res.body.decode('utf-8'), res_req_id)
示例4: test_global_request_id_drop
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def test_global_request_id_drop(self):
"""Test that bad format ids are dropped.
This ensures that badly formatted ids are dropped entirely.
"""
@webob.dec.wsgify
def application(req):
return req.environ.get(request_id.GLOBAL_REQ_ID)
global_req = "req-%s-bad" % uuid.uuid4()
app = request_id.RequestId(application)
req = webob.Request.blank(
'/test',
headers={"X-OpenStack-Request-ID": global_req})
res = req.get_response(app)
res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
if isinstance(res_req_id, bytes):
res_req_id = res_req_id.decode('utf-8')
# global-request-id in request environ is returned as response body
self.assertEqual(res.body.decode('utf-8'), '')
示例5: __call__
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def __call__(self, request):
"""WSGI method that controls (de)serialization and method dispatch."""
LOG.info(_LI("%(method)s %(url)s"),
{"method": request.method,
"url": request.url})
# Identify the action, its arguments, and the requested
# content type
action_args = self.get_action_args(request.environ)
action = action_args.pop('action', None)
content_type, body = self.get_body(request)
accept = request.best_match_content_type()
# NOTE(Vek): Splitting the function up this way allows for
# auditing by external tools that wrap the existing
# function. If we try to audit __call__(), we can
# run into troubles due to the @webob.dec.wsgify()
# decorator.
return self._process_stack(request, action, action_args,
content_type, body, accept)
示例6: test_raise
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def test_raise(self):
"""Ensure the ability to raise :class:`Fault` in WSGI-ified methods."""
@webob.dec.wsgify
def raiser(req):
raise wsgi.Fault(webob.exc.HTTPNotFound(explanation='whut?'))
req = webob.Request.blank('/.json')
resp = req.get_response(raiser)
self.assertEqual("application/json", resp.content_type)
self.assertEqual(404, resp.status_int)
self.assertIn(six.b('whut?'), resp.body)
示例7: test_raise_403
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def test_raise_403(self):
"""Ensure the ability to raise :class:`Fault` in WSGI-ified methods."""
@webob.dec.wsgify
def raiser(req):
raise wsgi.Fault(webob.exc.HTTPForbidden(explanation='whut?'))
req = webob.Request.blank('/.json')
resp = req.get_response(raiser)
self.assertEqual("application/json", resp.content_type)
self.assertEqual(403, resp.status_int)
self.assertNotIn(six.b('resizeNotAllowed'), resp.body)
self.assertIn(six.b('forbidden'), resp.body)
示例8: _do_test_exception_mapping
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def _do_test_exception_mapping(self, exception_type, msg):
@webob.dec.wsgify
def fail(req):
raise exception_type(msg)
api = self._wsgi_app(fail)
resp = webob.Request.blank('/').get_response(api)
self.assertIn(msg, six.text_type(resp.body), resp.body)
self.assertEqual(exception_type.code, resp.status_int, resp.body)
if hasattr(exception_type, 'headers'):
for (key, value) in exception_type.headers.items():
self.assertIn(key, resp.headers)
self.assertEqual(value, resp.headers[key])
示例9: test_exception_with_none_code_throws_500
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def test_exception_with_none_code_throws_500(self):
class ExceptionWithNoneCode(Exception):
code = None
@webob.dec.wsgify
def fail(req):
raise ExceptionWithNoneCode()
api = self._wsgi_app(fail)
resp = webob.Request.blank('/').get_response(api)
self.assertEqual(500, resp.status_int)
示例10: test_generate_request_id
# 需要導入模塊: import webob [as 別名]
# 或者: from webob import dec [as 別名]
def test_generate_request_id(self):
@webob.dec.wsgify
def application(req):
return req.environ[request_id.ENV_REQUEST_ID]
app = request_id.RequestId(application)
req = webob.Request.blank('/test')
res = req.get_response(app)
res_req_id = res.headers.get(request_id.HTTP_RESP_HEADER_REQUEST_ID)
if isinstance(res_req_id, bytes):
res_req_id = res_req_id.decode('utf-8')
self.assertThat(res_req_id, matchers.StartsWith('req-'))
# request-id in request environ is returned as response body
self.assertEqual(res.body.decode('utf-8'), res_req_id)