On 2/9/07, Manoj  Govindan <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I have written a small test making use of test.Client to simulate a
> 'POST' request to a view. The target view is expected to set a certain
> variable in the session on successful handling of the request. Can
> anyone suggest a suitable mechanism to check in the test if the
> session variable has been set correctly?
>

Sessions are saved in the database, so you could go straight to the
source, and pull the data from the database. However, you can cheat a
little bit and use the same infrastructure that Django uses in the
Sessions middleware:

from django.contrib.sessions.middleware import SessionWrapper

def MyTest(TestCase):
    def testStuff(self):

        ... do stuff ...
        session =
SessionWrapper(self.cookies.get(settings.SESSION_COOKIE_NAME, None))
        self.assertTrue(session['key'], value)

Fair warning - I haven't tested this myself. It _should_ work. :-)

Your question does raise an interesting suggestion - the client
currently persists cookies, but it might be nice for the client to
have easy access to the session, too... The testing framework is still
under development, and we need the suggestions of people in the field
to tell us what we can do to make the test framework better.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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