Opened 13 years ago

Closed 13 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)

15740.diff (1.9 KB) - added by Preston Timmons 13 years ago.

Download all attachments as: .zip

Change History (9)

Changed 13 years ago by Preston Timmons

Attachment: 15740.diff added

comment:1 Changed 13 years ago by Preston Timmons

This ticket is partially related to this one: http://code.djangoproject.com/ticket/10899.

comment:2 Changed 13 years ago by Jacob

Easy pickings: unset
Resolution: duplicate
Status: newclosed

It looks like #10899 would fix this, right? If so, it's a duplicate. I'm marking it as such; feel free to reopen if something about #10899 won't solve this usecase.

comment:3 Changed 13 years ago by Preston Timmons

Resolution: duplicate
Status: closedreopened

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 Changed 13 years ago by Michael Radziej

Owner: changed from Preston Timmons to Michael Radziej
Status: reopenednew

comment:5 Changed 13 years ago by Michael Radziej

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 Changed 13 years ago by Jacob

Triage Stage: UnreviewedDesign decision needed

comment:7 Changed 13 years ago by Michael Radziej

Owner: Michael Radziej deleted

comment:8 Changed 13 years ago by Preston Timmons

Resolution: duplicate
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top