#10899: easier manipulation of sessions by test client
----------------------------------------+-----------------------------------
Reporter: tallfred | Owner: nobody
Status: reopened | Milestone:
Component: Testing framework | Version: SVN
Resolution: | Keywords:
Stage: Accepted | Has_patch: 1
Needs_docs: 1 | Needs_tests: 0
Needs_better_patch: 0 |
----------------------------------------+-----------------------------------
Changes (by prestontimmons):
* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
Comment:
Smiley Chris,
I attached a new patch that applies cleanly to trunk as of [14099]. It
includes tests and passes the Django test suite. It doesn't have docs yet.
That's because when I went to write them I noticed that this functionality
is already provided in a fairly straightforward manner, with a caveat:
See
http://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.session.
The caveat is that the docs don't explain that the session has to already
be created, by calling a view or another manner, else it returns a
dictionary object rather than a SessionStore. That means if you run the
provided code sample in a test case you get an attribute error:
{{{
#!python
AttributeError: 'dict' object has no attribute 'save'
}}}
Could you give a decision on what to do with this next?
1. Go with the requested behavior of this patch and add the needed docs.
It's a slight improvement over the existing way of setting session
variables, although it's less explicit because the save behavior is
happening behind the scenes.
2. Keep the documented behavior but add the disclaimer that the session
needs to be created by calling a view with the client before editing the
session.
3. Open a different ticket for the existing caveat to be fixed and change
the test client to always return a session store when
'django.contrib.sessions' is installed by creating one if it doesn't
exist.
The changes I made are also on Github:
http://github.com/prestontimmons/django-10899
Thanks.
Preston
--
Ticket URL: <http://code.djangoproject.com/ticket/10899#comment:8>
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.