Thierry, Thanks for the response and the code sample.
To be clear, the "variables" in accounts/accueil/ are session variables? I assume your view for that URL looks like this: def accueil(request): ... request.session['domaine'] = Domaine.objects.get(nom='DomaineAdmin') ... My problem is that I am trying to _write_ session variables before calling my view. For example: def view(request): if 'foo' not in request.session: return HttpResponseRedirect('failure') return HttpResponse('success') class SessionTestCase(TestCase): def test_view(self): self.client.session['foo'] = 'bar' self.client.get('view') self.assertEqual(self.client.status_code, 200) This fails because Django doesn't properly pass the session to 'view,' and I'm wondering what the best way is to ensure it's passed. On Mar 31, 12:42 am, Thierry Chich <thierry.ch...@gmail.com> wrote: > Le mercredi 31 mars 2010 05:40:43, adambossy a écrit : > > > > > 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" [http:// > > code.djangoproject.com/ticket/10899] > > 2. "test.Client.session.save() raises error for anonymous > > users" [http://code.djangoproject.com/ticket/11475] > > > 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? > > Hi, > Perhaps, you should be more explicit with your problem. I am using the client > and there is no problem at all. > > For instance; > class GeneriqueTestCases(TestCase): > def test_login_admin(self): > > self.failUnlessEqual(self.client.login(username='admin',password='admin'),T > rue) > self.client.logout() > response=self.client.get("/accounts/accueil/") > > self.assertRedirects(response,'/accounts/login/?login=/accounts/accueil/') > > def test_login_domaine(self): > self.client.login(username='admin', password='admin') > response=self.client.get('/accounts/accueil/') > self.assertEqual(response.context['user'].username, 'admin') > d=Domaine.objects.get(nom='DomaineAdmin') > self.assertEqual(self.client.session.get('domaine'),d) > > In the last test, I am explicitely using informations stored in a session. > (However, I have searched a long time before I understand that some variables > was set in the accounts/accueil/ page :-( ) > > Thierry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.