本文整理汇总了Python中django.http.request.HttpRequest.session方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest.session方法的具体用法?Python HttpRequest.session怎么用?Python HttpRequest.session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.request.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.session方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_request
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import session [as 别名]
def get_request(self):
request = HttpRequest()
request.META['REMOTE_ADDR'] = '1.2.3.4'
request.method = 'POST'
request.session = SessionStore()
request._messages = default_storage(request)
request.user = AnonymousUser()
return request
示例2: test_user_login
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import session [as 别名]
def test_user_login(user_data, user):
from django.contrib.auth import authenticate, login
from django.http.request import HttpRequest
from django.contrib.sessions.backends.cache import SessionStore
assert user.activate('516bb9061d58280acd0c3900e18feaf5166f02ff')
request = HttpRequest()
request.session = SessionStore()
user = authenticate(
username=user_data['username'],
password=user_data['password'])
login(request, user)
assert user.is_authenticated()
示例3: test_response_whitout_GET
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import session [as 别名]
def test_response_whitout_GET(self):
from django.contrib.messages.storage import default_storage
request = HttpRequest()
request.session = SessionStore('asd')
request._messages = default_storage(request)
response = easy.action_response(request)
self.assertEqual(len(request._messages._queued_messages), 0)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], '.')
示例4: test_not_exist_view
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import session [as 别名]
def test_not_exist_view(self):
from django.contrib.messages.storage import default_storage
request = HttpRequest()
request.session = SessionStore('asd')
request._messages = default_storage(request)
response1 = self.admin.easy_list_view(request, 'not')
response2 = self.admin.easy_object_view(request, 1, 'not')
self.assertEqual(response1.status_code, 302)
self.assertEqual(response2.status_code, 302)
self.assertEqual(len(request._messages._queued_messages), 2)
示例5: test_response_without_querystring
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import session [as 别名]
def test_response_without_querystring(self):
from django.contrib.messages.storage import default_storage
request = HttpRequest()
request.GET = QueryDict('test=asd')
request.session = SessionStore('asd')
request._messages = default_storage(request)
response = easy.action_response(request, 'Some message', keep_querystring=False)
self.assertEqual(len(request._messages._queued_messages), 1)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], '.')
示例6: test_can_read__can
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import session [as 别名]
def test_can_read__can(self):
recipient = 'ggone'
secret_code = 'ssong'
mail = Mail.objects.create(recipient=recipient, secret_code=secret_code,
sender='[email protected]',
subject='hello girls!',
contents='Hello, nice to meet you secretly.')
request = HttpRequest()
request.session = {
'recipient': recipient
}
request.POST['secret_code'] = secret_code
self.assertEqual((True, None), mail.can_read(request))
示例7: has_perm
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import session [as 别名]
from django.test import TestCase
from django.http.request import HttpRequest
from generic_admin.sites import SiteWithTableEditor
from generic_admin.mixins import PermissionsControl, ChangeItemsStateActions, AutoCreateRedirects
from tests.models import MockEntity
class MockSuperUser:
def has_perm(self, perm):
return True
request = HttpRequest()
request.user = MockSuperUser()
request.session = 'session'
messages = FallbackStorage(request)
request._messages = messages
class TestMixins(TestCase):
def setUp(self):
self.entity = MockEntity.objects.create(name='Test')
self.site = SiteWithTableEditor()
def test_permissions_control(self):
ma = PermissionsControl(MockEntity, self.site) # ModelAdmin
permission_checks = [
ma.has_add_permission, ma.has_change_permission, ma.has_delete_permission
]