Hi,

well, I'm new to django (coming from rails hehe), and I'm trying  to
develop using a test-driven approach. I'm facing a problem trying to
emulate an existing session in a "functional" test.

There is a related problem here (http://groups.google.com/group/django-
users/browse_thread/thread/701a39672fc274a9/a75ef6fb3813e5ad), but it
seems to be a little bit outdated, and isn't exactly what I'm looking
for.

I simply want the Client to "fake" some values in the session. I want
to write in my test:

        self.client.session['key'] = 'value'
        self.client.session.save()
        response = self.client.post('/my_url', {}) #here,
request.session['key'] should have 'value'

This code doesn't work. It needs some 'initialization'. What I ended
up doing looks like this:

        #a view that only sets request.session.modified = True in
order to save the session
        #and get the session_cookie
        self.client.get('')
        engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
        session_cookie =
self.client.cookies.get(settings.SESSION_COOKIE_NAME).value
        self.client.session =
engine.SessionStore(session_cookie)

After this "initialization" (I put this on the setUp), the first
snippet works like expected. Is there a better way to do it? I
couldn't figure out anything simpler.

Thanks,
Bruno

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to