Python django.conf.settings.SESSION_SERIALIZER Examples
The following are 9
code examples of django.conf.settings.SESSION_SERIALIZER().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example #1
Source File: base.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def __init__(self, session_key=None): self._session_key = session_key self.accessed = False self.modified = False self.serializer = import_string(settings.SESSION_SERIALIZER)
Example #2
Source File: test_views.py From django-cas-ng with MIT License | 5 votes |
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
Example #3
Source File: test_views.py From django-cas-ng with MIT License | 5 votes |
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
Example #4
Source File: test_views.py From django-cas-ng with MIT License | 5 votes |
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
Example #5
Source File: test_views.py From django-cas-ng with MIT License | 5 votes |
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
Example #6
Source File: base.py From bioforum with MIT License | 5 votes |
def __init__(self, session_key=None): self._session_key = session_key self.accessed = False self.modified = False self.serializer = import_string(settings.SESSION_SERIALIZER)
Example #7
Source File: base.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def __init__(self, session_key=None): self._session_key = session_key self.accessed = False self.modified = False self.serializer = import_string(settings.SESSION_SERIALIZER)
Example #8
Source File: base.py From openhgsenti with Apache License 2.0 | 5 votes |
def __init__(self, session_key=None): self._session_key = session_key self.accessed = False self.modified = False self.serializer = import_string(settings.SESSION_SERIALIZER)
Example #9
Source File: base.py From python2017 with MIT License | 5 votes |
def __init__(self, session_key=None): self._session_key = session_key self.accessed = False self.modified = False self.serializer = import_string(settings.SESSION_SERIALIZER)