本文整理汇总了Python中django.http.HttpRequest.COOKIES["c"]方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest.COOKIES["c"]方法的具体用法?Python HttpRequest.COOKIES["c"]怎么用?Python HttpRequest.COOKIES["c"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.COOKIES["c"]方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_signed_cookies_with_binary_key
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import COOKIES["c"] [as 别名]
def test_signed_cookies_with_binary_key(self):
response = HttpResponse()
response.set_signed_cookie("c", "hello")
request = HttpRequest()
request.COOKIES["c"] = response.cookies["c"].value
self.assertEqual(request.get_signed_cookie("c"), "hello")
示例2: test_detects_tampering
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import COOKIES["c"] [as 别名]
def test_detects_tampering(self):
response = HttpResponse()
response.set_signed_cookie("c", "hello")
request = HttpRequest()
request.COOKIES["c"] = response.cookies["c"].value[:-2] + "$$"
with self.assertRaises(signing.BadSignature):
request.get_signed_cookie("c")
示例3: test_can_set_and_read_signed_cookies
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import COOKIES["c"] [as 别名]
def test_can_set_and_read_signed_cookies(self):
response = HttpResponse()
response.set_signed_cookie("c", "hello")
self.assertIn("c", response.cookies)
self.assertTrue(response.cookies["c"].value.startswith("hello:"))
request = HttpRequest()
request.COOKIES["c"] = response.cookies["c"].value
value = request.get_signed_cookie("c")
self.assertEqual(value, "hello")
示例4: test_max_age_argument
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import COOKIES["c"] [as 别名]
def test_max_age_argument(self):
value = "hello"
with freeze_time(123456789):
response = HttpResponse()
response.set_signed_cookie("c", value)
request = HttpRequest()
request.COOKIES["c"] = response.cookies["c"].value
self.assertEqual(request.get_signed_cookie("c"), value)
with freeze_time(123456800):
self.assertEqual(request.get_signed_cookie("c", max_age=12), value)
self.assertEqual(request.get_signed_cookie("c", max_age=11), value)
with self.assertRaises(signing.SignatureExpired):
request.get_signed_cookie("c", max_age=10)
示例5: test_default_argument_suppresses_exceptions
# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import COOKIES["c"] [as 别名]
def test_default_argument_suppresses_exceptions(self):
response = HttpResponse()
response.set_signed_cookie("c", "hello")
request = HttpRequest()
request.COOKIES["c"] = response.cookies["c"].value[:-2] + "$$"
self.assertEqual(request.get_signed_cookie("c", default=None), None)