Opened 4 years ago

Closed 4 years ago

#15740 closed Bug (duplicate)

Manipulating the test client session doesn't work as documented

Reported by: prestontimmons 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:

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 prestontimmons 4 years ago.

Download all attachments as: .zip

Change History (9)

Changed 4 years ago by prestontimmons

comment:1 Changed 4 years ago by prestontimmons

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 4 years ago by jacob

  • Easy pickings unset
  • Resolution set to duplicate
  • Status changed from new to closed

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 4 years ago by prestontimmons

  • Resolution duplicate deleted
  • Status changed from closed to 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 Changed 4 years ago by mir

  • Owner changed from prestontimmons to mir
  • Status changed from reopened to new

comment:5 Changed 4 years ago by mir

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 4 years ago by jacob

  • Triage Stage changed from Unreviewed to Design decision needed

comment:7 Changed 4 years ago by mir

  • Owner mir deleted

comment:8 Changed 4 years ago by prestontimmons

  • Resolution set to duplicate
  • Status changed from new to 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.

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