Hi,
I am writing some tests for an application I am developing, in my test
case's setUp I do
self.dummy1 = User.objects.create_user('dummy1', '[email protected]',
self.c = Client()
self.c.login(username='dummy', password='dummy')
In one of the tests I POST some data and then check that the
response.status_code I get is a 302 followed by a GET to the page the
browser would get redirected to (since 1.0 doesn't automatically
follow a redirect).
In a browser the response on this redirected-to page contains some
session data which is rendered on the page. In my test however the
session does not contain this information, which I also verified by
dropping into pdb after the GET:
-> self.assertEquals(response.status_code, 200)
(Pdb) self.c
<django.test.client.Client instance at 0x1d33ad0>
(Pdb) self.c.session
<django.contrib.sessions.backends.file.SessionStore object at
0x203a110>
(Pdb) self.c.session.keys()
['_auth_user_id', '_auth_user_backend']
(Pdb) self.c.session['test'] = 'hello'
(Pdb) self.c.session
<django.contrib.sessions.backends.file.SessionStore object at
0x1eeea30>
(Pdb) self.c.session['test']
*** KeyError: 'test'
(Pdb) self.c.session.save()
(Pdb) self.c.session
<django.contrib.sessions.backends.file.SessionStore object at
0x1eeed90>
(Pdb) self.c.session.keys()
['_auth_user_backend', '_auth_user_id']
(Pdb)
In my settings.py the (what I think) are the relevant entries:
...
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'djangologging.middleware.LoggingMiddleware',
)
...
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.flatpages',
'django.contrib.sessions',
'django.contrib.sites',
...
)
...
CACHE_BACKEND = 'file:///var/tmp/django_cache'
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
SESSION_FILE_PATH = '/var/tmp'
...
This is on Django 1.0. (haven't gotten around to upgrade to 1.0.2 yet,
but at least the release notes wouldn't indicate any problems in this
direction.)
I am sure I am missing something obvious, but haven't been able to
figure it out for two days now - help!
Thanks
Stefan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---