So by switching from the development server to a local Apache/MySQL setup I eventually managed to get access to the session data as expected. I then narrowed down that the settings.py for those two environments had different settings for CACHE_BACKEND (don't ask me why):
- Dev. server: CACHE_BACKEND = 'file:///var/tmp/django_cache' - Apache/MySQL: CACHE_BACKEND = 'db://upload_cache_table' If I change the CACHE_BACKEND in the dev server to match Apache/MySQL (i.e. use db://...), sessions also work on the dev server. I am happy if that is all it takes to make it work, but I don't understand why the file CACHE_BACKEND wouldn't work? The docs don't seems to warn about that either. Anyone can explain? Stefan On Apr 27, 9:47 pm, Stefan Wallner <montodes...@googlemail.com> wrote: > 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', 'n...@example.com', > 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! > > ThanksStefan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---