Opened 14 years ago
Closed 14 years ago
#15740 closed Bug (duplicate)
Manipulating the test client session doesn't work as documented
Reported by: | Preston Timmons | Owned by: | |
---|---|---|---|
Component: | Testing framework | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | prestontimmons@… | Triage Stage: | Design decision needed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The example for manipulating session variables at this url does not work as documented:
http://docs.djangoproject.com/en/1.3/topics/testing/#django.test.client.Client.session
def test_something(self): session = self.client.session session['somekey'] = 'test' session.save()
The test client returns a dictionary rather than a session object, unless a session object is manually added to the client or a view is called that initiates a session.
Attached is a patch that modifies the client to return a session object whenever django.contrib.sessions is installed.
Attachments (1)
Change History (9)
by , 14 years ago
Attachment: | 15740.diff added |
---|
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Easy pickings: | unset |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
comment:3 by , 14 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
Hi Jacob,
Thanks for looking at this.
Yes, #10899 would solve this, but #10899 is a feature request to change how the test client session works. This ticket is a subset of #10899 to simply make the test client work as documented.
As long as #10899 isn't finished, I think either this patch should be committed or the docs should be updated to explain why the given example raises an exception.
I'm reopening this for now. If you think the bug isn't worthy to address on its own, I can move on #10899.
comment:4 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:5 by , 14 years ago
I've posted a question about how to deal with this on the django developer list.
http://groups.google.com/group/django-developers/browse_thread/thread/90e422f2a8231670
comment:6 by , 14 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:7 by , 14 years ago
Owner: | removed |
---|
comment:8 by , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I updated the patch on #10899, which also fixes this bug. Jacob's explanation on the developers thread makes sense. I'm putting this back to duplicate status.
This ticket is partially related to this one: http://code.djangoproject.com/ticket/10899.