I am trying to test how a view behaves when there is certain data stored in the session. To do so I have created the session in the test method and invoked an interactive shell at the very beginning of the view:
Test Method:
def test_user_with_unused_tests(self):
"User is given a test and sent to test start"
# todo: insure that the user is given a test that he hasn't done
#login
login = self.client.login(username='xxx', password='xxx')
self.failUnless(login)
# build the screener
user = User(username='xxx', password='xxx')
user_screener = UserScreener(user=user)
# put the screener in session
self.client.session['user_screener'] = user_screener
View That Is Tested:
@login_required
def screener_start(request):
import code
code.interact(local=locals())
But apparently the session does not persist between my test method and the call to the view:
Evidence of Nonpersistence:
>>> request.session.values()
[1, 'django.contrib.auth.backends.ModelBackend']
Is there any way to fix this? Am I missing something essential?
I am using Django 1.0.
Thanks ahead of time for your thoughts.