Opened 16 years ago
Closed 9 years ago
#7836 closed Bug (fixed)
django.test.client._session should check for session middleware instead
Reported by: | Trevor Caira | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | charette.s@…, vlastimil@…, unai@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The django test client class allows you to use self.client.session
only if you have 'django.contrib.sessions'
in your INSTALLED_APPS
setting. That is, it assumes you are using sessions if and only if you have the sessions app installed.
This assumption breaks down when you are using the sessions middleware independently of the sessions app, for instance if you are using a cache backend for sessions.
I propose that django.test.client._session
check for the sessions middleware class in MIDDLEWARE_CLASSES
instead of the sessions app in INSTALLED_APPS
to make it easier for people using the session middleware independently of the sessions app to use self.client.sesssion
in tests.
Change History (15)
comment:1 by , 16 years ago
Component: | Uncategorized → Unit test system |
---|
comment:2 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 by , 14 years ago
Triage Stage: | Design decision needed → Accepted |
---|
comment:4 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:7 by , 13 years ago
Easy pickings: | unset |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
UI/UX: | unset |
comment:8 by , 12 years ago
Cc: | added |
---|
comment:9 by , 12 years ago
Cc: | added |
---|
comment:10 by , 12 years ago
Status: | reopened → new |
---|
follow-up: 13 comment:11 by , 11 years ago
I'm probably missing something, where's the need of checking if some kind of session middleware exists? If not present, wouldn't {}
be returned anyways?
BTW, shouldn't it be better if the engine module import happen outside _session
and instead of checking for if coockie
if cookie is not None
is checked?
comment:12 by , 11 years ago
Cc: | added |
---|
comment:13 by , 11 years ago
Replying to unaizalakain:
I'm probably missing something, where's the need of checking if some kind of session middleware exists? If not present, wouldn't
{}
be returned anyways?
In application, the attribute request.session
is created by SessionMiddleware
. If missing you will get AttributeError
.
In tests, you get either empty dictionary or SessionStore
.
The problem here is no error is indicated by client when you don't have sessions installed, but client.login
does not do a valid login. This is problem which is not quite easy to find.
BTW, shouldn't it be better if the engine module import happen outside
_session
and instead of checking forif coockie
if cookie is not None
is checked?
It wouldn't. You can change settings for the test and you want the test to use yours.
comment:14 by , 11 years ago
What if _sesion
arises an exception if no subclass of the session middleware is found?
comment:15 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I think that the recent commit 21dd98a3 fixing #25699 is also fixing this issue.
This looks like a reasonable request.