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'),True)
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 [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.