WebFaction
Community site: login faq

I expect some error to be raised when a user tries to access a username/password protected page with an expired session. To test this in a unittest, I set the session expire age to -1 seconds:

from django.test.client import RequestFactory
from django.utils.importlib import import_module
from django.conf import settings

settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file'
engine = import_module(settings.SESSION_ENGINE)

request = RequestFactory().get('')
request.user = an_authenticated_User_object
request.session = engine.SessionStore()
request.session.set_expiry(-1)
request.session.save()

Calling my view using this request does not raise any error. Also, user.is_authenticated() still returns True. Should I implement any verification like session.get_expiry_age() >= 0 or does Django do this for me and how then should I unittest for this expired session? Perhaps there is even a default view method like there is for erroneous CSRF-tokens (csrf_failure()) that is supposed to catch expired sessions?

asked 26 Mar '14, 17:54

expdesign
2338
accept rate: 0%

edited 26 Mar '14, 18:51

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×9
×5
×2

question asked: 26 Mar '14, 17:54

question was seen: 4,918 times

last updated: 26 Mar '14, 18:51

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM