本文整理匯總了Python中django.conf.settings.SESSION_SERIALIZER屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.SESSION_SERIALIZER屬性的具體用法?Python settings.SESSION_SERIALIZER怎麽用?Python settings.SESSION_SERIALIZER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.SESSION_SERIALIZER屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_SERIALIZER [as 別名]
def __init__(self, session_key=None):
self._session_key = session_key
self.accessed = False
self.modified = False
self.serializer = import_string(settings.SESSION_SERIALIZER)
示例2: test_login_authenticate_and_create_user
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_SERIALIZER [as 別名]
def test_login_authenticate_and_create_user(monkeypatch, django_user_model, settings):
"""
Test the case where the login view authenticates a new user.
"""
# No need to test the message framework
settings.CAS_LOGIN_MSG = None
# Make sure we use our backend
settings.AUTHENTICATION_BACKENDS = ['django_cas_ng.backends.CASBackend']
# Json serializer was havinga hard time
settings.SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
def mock_verify(ticket, service):
return 'test@example.com', {'ticket': ticket, 'service': service}, None
monkeypatch.setattr('cas.CASClientV2.verify_ticket', mock_verify)
factory = RequestFactory()
request = factory.get('/login/', {'ticket': 'fake-ticket',
'service': 'fake-service'})
# Create a session object from the middleware
process_request_for_middleware(request, SessionMiddleware)
# Create a user object from middleware
process_request_for_middleware(request, AuthenticationMiddleware)
response = LoginView().get(request)
assert response.status_code == 302
assert response['Location'] == '/'
assert django_user_model.objects.get(username='test@example.com').is_authenticated is True
示例3: test_login_authenticate_do_not_create_user
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_SERIALIZER [as 別名]
def test_login_authenticate_do_not_create_user(monkeypatch, django_user_model, settings):
"""
Test the case where the login view authenticates a user, but does not
create a user based on the CAS_CREATE_USER setting.
"""
# No need to test the message framework
settings.CAS_CREATE_USER = False
# No need to test the message framework
settings.CAS_LOGIN_MSG = None
# Make sure we use our backend
settings.AUTHENTICATION_BACKENDS = ['django_cas_ng.backends.CASBackend']
# Json serializer was havinga hard time
settings.SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
def mock_verify(ticket, service):
return 'test@example.com', {'ticket': ticket, 'service': service}, None
monkeypatch.setattr('cas.CASClientV2.verify_ticket', mock_verify)
factory = RequestFactory()
request = factory.get('/login/', {'ticket': 'fake-ticket',
'service': 'fake-service'})
# Create a session object from the middleware
process_request_for_middleware(request, SessionMiddleware)
# Create a user object from middleware
process_request_for_middleware(request, AuthenticationMiddleware)
with pytest.raises(PermissionDenied):
LoginView().get(request)
assert django_user_model.objects.filter(username='test@example.com').exists() is False
示例4: test_login_proxy_callback
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_SERIALIZER [as 別名]
def test_login_proxy_callback(monkeypatch, django_user_model, settings):
"""
Test the case where the login view has a pgtiou.
"""
# No need to test the message framework
settings.CAS_PROXY_CALLBACK = True
# No need to test the message framework
settings.CAS_LOGIN_MSG = None
# Make sure we use our backend
settings.AUTHENTICATION_BACKENDS = ['django_cas_ng.backends.CASBackend']
# Json serializer was havinga hard time
settings.SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
def mock_verify(ticket, service):
return 'test@example.com', {'ticket': ticket, 'service': service}, None
monkeypatch.setattr('cas.CASClientV2.verify_ticket', mock_verify)
factory = RequestFactory()
request = factory.get('/login/', {'ticket': 'fake-ticket',
'service': 'fake-service'})
# Create a session object from the middleware
process_request_for_middleware(request, SessionMiddleware)
# Create a user object from middleware
process_request_for_middleware(request, AuthenticationMiddleware)
request.session['pgtiou'] = 'fake-pgtiou'
request.session.save()
user = django_user_model.objects.create_user('test@example.com', '')
assert user is not None
pgt = ProxyGrantingTicket.objects.create(session_key=request.session.session_key,
user=user, pgtiou='fake-pgtiou',
pgt='fake-pgt')
assert pgt is not None
response = LoginView().get(request)
assert response.status_code == 302
assert django_user_model.objects.get(username='test@example.com').is_authenticated is True
assert ProxyGrantingTicket.objects.filter(pgtiou='fake-pgtiou').exists() is True
assert ProxyGrantingTicket.objects.filter(pgtiou='fake-pgtiou').count() == 1
示例5: test_login_redirect_based_on_cookie
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_SERIALIZER [as 別名]
def test_login_redirect_based_on_cookie(monkeypatch, django_user_model, settings):
"""
Test the case where the login view authenticates a new user and redirects them based on cookie.
"""
# No need to test the message framework
settings.CAS_LOGIN_MSG = None
# Make sure we use our backend
settings.AUTHENTICATION_BACKENDS = ['django_cas_ng.backends.CASBackend']
# Json serializer was havinga hard time
settings.SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
# Store next as cookie
settings.CAS_STORE_NEXT = True
def mock_verify(ticket, service):
return 'test@example.com', {'ticket': ticket, 'service': service}, None
monkeypatch.setattr('cas.CASClientV2.verify_ticket', mock_verify)
factory = RequestFactory()
request = factory.get('/login/', {'ticket': 'fake-ticket',
'service': 'fake-service'})
# Create a session object from the middleware
process_request_for_middleware(request, SessionMiddleware)
# Create a user object from middleware
process_request_for_middleware(request, AuthenticationMiddleware)
# Add the next pointer
request.session['CASNEXT'] = '/admin/'
response = LoginView().get(request)
assert response.status_code == 302
assert response['Location'] == '/admin/'
assert 'CASNEXT' not in request.session
assert django_user_model.objects.get(username='test@example.com').is_authenticated is True