当前位置: 首页>>代码示例>>Python>>正文


Python HttpRequest.session方法代码示例

本文整理汇总了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
开发者ID:nijel,项目名称:weblate,代码行数:10,代码来源:test_ratelimit.py

示例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()
开发者ID:l0rda,项目名称:regme,代码行数:14,代码来源:test_documents.py

示例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'], '.')
开发者ID:ebertti,项目名称:django-admin-easy,代码行数:14,代码来源:tests.py

示例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)
开发者ID:GabLeRoux,项目名称:django-admin-easy,代码行数:15,代码来源:tests.py

示例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'], '.')
开发者ID:ebertti,项目名称:django-admin-easy,代码行数:15,代码来源:tests.py

示例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))
开发者ID:triplepy,项目名称:sh8email-django,代码行数:16,代码来源:test_models.py

示例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
        ]
开发者ID:fidals,项目名称:refarm-site,代码行数:32,代码来源:test_admin_models.py


注:本文中的django.http.request.HttpRequest.session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。