本文整理匯總了Python中cyclone.web.RequestHandler.get_argument方法的典型用法代碼示例。如果您正苦於以下問題:Python RequestHandler.get_argument方法的具體用法?Python RequestHandler.get_argument怎麽用?Python RequestHandler.get_argument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cyclone.web.RequestHandler
的用法示例。
在下文中一共展示了RequestHandler.get_argument方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RequestHandlerTest
# 需要導入模塊: from cyclone.web import RequestHandler [as 別名]
# 或者: from cyclone.web.RequestHandler import get_argument [as 別名]
#.........這裏部分代碼省略.........
self.rh.set_header("X-Header", "something")
self.assertTrue("X-Header" in self.rh._headers)
self.rh.clear_header("X-Header")
self.assertTrue("X-Header" not in self.rh._headers)
def test_convert_header_value(self):
value = self.rh._convert_header_value("Value")
self.assertEqual(value, "Value")
def test_convert_unicode_header_value(self):
value = self.rh._convert_header_value(u"Value")
self.assertEqual(value, "Value")
self.assertTrue(type(value) != unicode_type)
def test_convert_unicode_datetime_header_value(self):
now = datetime(2014, 4, 4)
result = self.rh._convert_header_value(now)
self.assertEqual(
result,
"Fri, 04 Apr 2014 00:00:00 GMT"
)
def test_convert_invalid_value(self):
class Nothing:
pass
self.assertRaises(TypeError, self.rh._convert_header_value, Nothing())
def test_convert_long_value(self):
self.assertRaises(
ValueError, self.rh._convert_header_value, "a" * 5000)
def test_get_argument(self):
self.rh.get_arguments = Mock()
self.rh.get_arguments.return_value = ["a"]
self.rh.get_argument("test")
self.rh.get_arguments.assert_called_with("test", strip=True)
self.rh.get_arguments.return_value = None
self.assertEqual(
self.rh.get_argument("arg", "something"),
"something"
)
self.assertRaises(HTTPError, self.rh.get_argument, "arg")
def test_get_arguments(self):
self.rh.request.arguments = {"arg": ["something"]}
val = self.rh.get_arguments("arg")
self.assertEqual(val, ["something"])
def test_cookies(self):
self.rh.request.cookies = "rawr"
self.assertEqual(self.rh.cookies, "rawr")
def test_decode_argument(self):
self.assertEqual(
self.rh.decode_argument("somearg"),
"somearg"
)
def test_get_cookie(self):
morsel = Mock()
morsel.value = "value"
self.rh.request.cookies = {"testcookie": morsel}
val = self.rh.get_cookie("testcookie")
self.assertEqual(val, "value")