#7416 closed (fixed)
Test Client Loses session when login is called
Reported by: | Owned by: | Eric Holscher | |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If data is put into the session by a view during a test, and then subsequently in the same test the client.login method is used on the test client, the client loses all session data previously in it.
It appears to be due to this line:
http://code.djangoproject.com/browser/django/trunk/django/test/client.py?rev=7583#L258
I quickly changed that line to:
request.session = self.session# engine.SessionStore()
Which seems more correct, but I haven't run the tests to see if it's right or not.
Attachments (2)
Change History (7)
by , 16 years ago
Attachment: | testclient-session.diff added |
---|
comment:1 by , 16 years ago
Has patch: | set |
---|---|
milestone: | → 1.0 |
Needs tests: | set |
Owner: | changed from | to
Status: | new → assigned |
Added a simple patch. Probably needs to be better, but this is a bug, line 56-57 in init of contrib/auth:
request.session[SESSION_KEY] = user.id
request.session[BACKEND_SESSION_KEY] = user.backend
Sets the existing session with the user Id.
comment:2 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 16 years ago
Attached is a project and app that show the bug in the trunk version. The patch above fixes it. I didn't test too much more, but it appears to be working. I don't know if request.session is ever None (if it is, will that raise an error?)
comment:4 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Simple patch implementing this.