本文整理汇总了Python中webob.response.Response.text方法的典型用法代码示例。如果您正苦于以下问题:Python Response.text方法的具体用法?Python Response.text怎么用?Python Response.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.response.Response
的用法示例。
在下文中一共展示了Response.text方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exec_controller_ok
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def test_exec_controller_ok(self):
'''This test case ensures that requested route is executed - success scenario.'''
global_headers = {"X-Custom-Header1": "header1",
"X-Custom-Header2": "header2"}
def get(key):
if key == "installed_middleware":
return ["fantastico.middleware.tests.test_fantastico_app.MockedMiddleware"]
if key == "global_response_headers":
return global_headers
self._settings_facade.get = get
app_middleware = FantasticoApp(self._settings_facade_cls)
response = Response()
response.content_type = "text/html"
response.text = "Hello world"
self._controller.exec_logic = lambda request: response
self.assertEqual([b"Hello world"], app_middleware(self._environ, Mock()))
self.assertTrue(self._environ["test_wrapped_ok"])
self.assertEqual(global_headers["X-Custom-Header1"], response.headers["X-Custom-Header1"])
self.assertEqual(global_headers["X-Custom-Header2"], response.headers["X-Custom-Header2"])
示例2: display_test
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def display_test(self, request):
'''This method handles **/dummy/route/loader/test route**. It is expected to receive a response with status code 400.
We do this for being able to test rendering and also avoid false positive security scans messages.'''
response = Response(status_code=400)
if "text/html" in request.content_type:
response.content_type = "application/html; charset=UTF-8"
else:
response.content_type = request.content_type or "application/html; charset=UTF-8"
response.text = "Hello world."
return response
示例3: test_mistmatch_content_headers
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def test_mistmatch_content_headers(self):
'''This test case makes sure an exception is raised whenever client browser does not accept response
content type.'''
self._settings_facade.get = Mock(return_value=["fantastico.middleware.tests.test_fantastico_app.MockedMiddleware"])
response = Response()
response.content_type = "not supported"
response.text = "Hello world"
self._controller.exec_logic = lambda request: response
app_middleware = FantasticoApp(self._settings_facade_cls)
self.assertRaises(FantasticoContentTypeError, app_middleware, *[self._environ, Mock()])
self.assertTrue(self._environ["test_wrapped_ok"])
示例4: test_response_ok
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def test_response_ok(self):
'''Test case that ensures response object behaves as expected. If this pass it guarantees webob version does not
break fantastico functionality.'''
response = Response()
self.assertEqual(200, response.status_code)
self.assertEqual("text/html", response.content_type)
response.charset = "utf8"
self.assertEqual("utf8", response.charset)
response.text = "test content"
self.assertEqual(b"test content", response.body)
response.body = b"test content"
self.assertEqual(b"test content", response.body)
response.status = 404
self.assertEqual(404, response.status_code)
response.content_type = "application/json"
self.assertEqual("application/json", response.content_type)
示例5: test_write_unicode
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def test_write_unicode():
res = Response()
res.text = text_(b'La Pe\xc3\xb1a', 'utf-8')
res.write(text_(b'a'))
assert res.text, text_(b'La Pe\xc3\xb1aa' == 'utf-8')
示例6: test_text_set_no_default_body_encoding
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def test_text_set_no_default_body_encoding():
res = Response()
res.charset = None
res.default_body_encoding = None
with pytest.raises(AttributeError):
res.text = text_("abc")
示例7: test_text_set_no_charset
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def test_text_set_no_charset():
res = Response()
res.charset = None
res.text = text_("abc")
assert res.text == "abc"
示例8: upload_file
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def upload_file(self, request):
response = Response()
response.text = "Hello world."
return response
示例9: say_hello
# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import text [as 别名]
def say_hello(self, request):
response = Response()
response.text = "Hello world."
return response