本文整理汇总了Python中cyclone.web.RequestHandler.xsrf_form_html方法的典型用法代码示例。如果您正苦于以下问题:Python RequestHandler.xsrf_form_html方法的具体用法?Python RequestHandler.xsrf_form_html怎么用?Python RequestHandler.xsrf_form_html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cyclone.web.RequestHandler
的用法示例。
在下文中一共展示了RequestHandler.xsrf_form_html方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RequestHandlerTest
# 需要导入模块: from cyclone.web import RequestHandler [as 别名]
# 或者: from cyclone.web.RequestHandler import xsrf_form_html [as 别名]
#.........这里部分代码省略.........
self.rh._headers_written = True
self.assertRaises(Exception, self.rh.redirect, "/")
def test_redirect_with_perm(self):
self.rh.flush = Mock()
self.rh._log = Mock()
self.rh.redirect("/", permanent=True)
def test_redirect_with_slashes(self):
self.rh.flush = Mock()
self.rh._log = Mock()
self.assertRaises(
AssertionError,
self.rh.redirect,
"//example.com",
status=400)
def test_redirect_bad_url(self):
self.rh.flush = Mock()
self.rh._log = Mock()
self.rh.request.uri = "foo"
self.rh.redirect("http://foo.com", permanent=True)
def test_write_when_finished(self):
self.rh._finished = True
self.assertRaises(RuntimeError, self.rh.write, "foo")
def test_write_dict(self):
self.rh.write({"foo": "bar"})
self.assertEqual(
self.rh._write_buffer,
['{"foo": "bar"}']
)
def test_create_template_loader(self):
self.rh.application.settings = {"autoescape": True}
res = self.rh.create_template_loader("/foo")
self.assertTrue(res)
def test_finish_already_finished(self):
self.rh._finished = True
self.assertRaises(RuntimeError, self.rh.finish)
def test_finish_304_with_body(self):
self.rh._status_code = 304
self.rh._write_buffer = ""
self.rh.flush = Mock()
self.rh._log = Mock()
self.rh.finish()
def test_send_error(self):
self.rh.flush = Mock()
self.rh._log = Mock()
self.rh.write_error = Mock()
self.rh.send_error()
self.rh.write_error.assert_called_with(500)
def test_write_error(self):
self.rh.flush = Mock()
self.rh._log = Mock()
self.rh.get_error_html = Mock()
exc = [Mock(), Mock()]
self.rh.finish = Mock()
self.rh.write_error(500, exc_info=exc)
def test_locale(self):
self.request.headers = {
"Accept-Language": "en"
}
self.rh.locale
def test_get_user_locale(self):
self.rh.get_user_locale()
def test_get_browser_locale(self):
self.request.headers = {
"Accept-Language": "en"
}
self.rh.get_browser_locale()
def test_current_user(self):
self.rh.current_user
def test_xsrf_token(self):
self.request.cookies = {}
self.rh.xsrf_token
def test_check_xsrf_cookie(self):
self.request.arguments = {self.rh.xsrf_cookie_name: "foo"}
self.request.cookies = {}
self.assertRaises(HTTPError, self.rh.check_xsrf_cookie)
def test_xsrf_form_html(self):
self.request.arguments = {self.rh.xsrf_cookie_name: "foo"}
self.request.cookies = {}
self.rh.xsrf_form_html()
def test_static_url(self):
self.rh.application.settings = {"static_path": "."}
self.rh.static_url("/")