How do I properly unit test a Django session?

Posted by thebossman on Stack Overflow See other posts from Stack Overflow or by thebossman
Published on 2010-03-31T02:30:51Z Indexed on 2010/03/31 2:33 UTC
Read the original article Hit count: 444

The behavior of Django sessions changes between "standard" views code and test code, making it unclear how test code is written for sessions. Googling this yields two relevant discussions about this issue:

  1. Easier manipulation of sessions by test client

  2. test.Client.session.save() raises error for anonymous users

I'm confused because both tickets have different ways of dealing with this problem and they were both Accepted. I assume this means they were patched and the behavior is now different. I also don't know to which versions these patches would pertain.

If I'm writing a unit test in Django 1.0, how would I set up my session store for sessions to work as they do in the browser?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-sessions