本文整理匯總了Python中cyclone.web.RequestHandler.redirect方法的典型用法代碼示例。如果您正苦於以下問題:Python RequestHandler.redirect方法的具體用法?Python RequestHandler.redirect怎麽用?Python RequestHandler.redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cyclone.web.RequestHandler
的用法示例。
在下文中一共展示了RequestHandler.redirect方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RequestHandlerTest
# 需要導入模塊: from cyclone.web import RequestHandler [as 別名]
# 或者: from cyclone.web.RequestHandler import redirect [as 別名]
#.........這裏部分代碼省略.........
def test_set_cookie_already_exists(self):
self.rh._new_cookie = Cookie.SimpleCookie()
self.rh._new_cookie["name"] = "value"
self.rh.set_cookie("name", "value")
def test_set_cookie_domain(self):
self.rh.set_cookie("name", "value", domain="foo.com")
self.assertEqual(
self.rh._new_cookie["name"]['domain'],
"foo.com"
)
def test_set_cookie_expires_days(self):
self.rh.set_cookie("name", "value", expires_days=5, max_age=55)
expires = self.rh._new_cookie["name"]['expires']
self.assertTrue(
email.utils.parsedate(expires) >
time.gmtime(),
)
def test_clear_cookie(self):
morsel = Mock()
self.rh.request.cookies = {"testcookie": morsel}
self.rh.set_cookie("name", "value")
self.rh.clear_cookie("name")
self.assertEqual(None, self.rh.get_cookie("name"))
def test_clear_all_cookies(self):
self.rh.clear_cookie = Mock()
self.rh.request.cookies = {"foo": None}
self.rh.clear_all_cookies()
self.rh.clear_cookie.assert_called_with("foo")
def test_redirect_too_late(self):
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"}']