#10899: easier manipulation of sessions by test client
----------------------------------------+-----------------------------------
Reporter: tallfred | Owner: nobody
Status: reopened | Milestone:
Component: Testing framework | Version: SVN
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 1
Needs_docs: 1 | Needs_tests: 1
Needs_better_patch: 1 |
----------------------------------------+-----------------------------------
Changes (by toxik):
* status: closed => reopened
* needs_better_patch: 0 => 1
* resolution: fixed =>
* needs_tests: 0 => 1
* needs_docs: 0 => 1
Comment:
Seems like you got the wrong ticket number, Russell.
As an aside, here's how I access the session in a very session backend
agnostic way:
{{{
#!python
from django.test import TestCase
from django.test.client import ClientHandler
class SessionHandler(ClientHandler):
def get_response(self, request):
response = super(SessionHandler, self).get_response(request)
response.session = request.session.copy()
return response
class SessionTestCase(TestCase):
def _pre_setup(self):
super(SessionTestCase, self)._pre_setup()
self.client.handler = SessionHandler()
class FooTestCase(SessionTestCase):
def test_session_exists(self):
resp = self.client.get("/")
self.assert_(hasattr(resp, "session"))
self.assert_("my_session_key" in resp.session)
self.assertEqual(resp.session["my_session_key"], "Hello world!")
}}}
As you can see, it'd be very easy for the original `ClientHandler` class
to just copy over the session to the response object.
--
Ticket URL: <http://code.djangoproject.com/ticket/10899#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---