Opened 15 years ago
Closed 8 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 Changed 15 years ago by
Component: | Uncategorized → Unit test system |
---|
comment:2 Changed 15 years ago by
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 Changed 13 years ago by
Triage Stage: | Design decision needed → Accepted |
---|
comment:4 Changed 13 years ago by
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:7 Changed 12 years ago by
Easy pickings: | unset |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
UI/UX: | unset |
comment:8 Changed 12 years ago by
Cc: | charette.s@… added |
---|
comment:9 Changed 11 years ago by
Cc: | vlastimil@… added |
---|
comment:10 Changed 11 years ago by
Status: | reopened → new |
---|
comment:11 follow-up: 13 Changed 10 years ago by
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 Changed 10 years ago by
Cc: | unai@… added |
---|
comment:13 Changed 10 years ago by
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 Changed 10 years ago by
What if _sesion
arises an exception if no subclass of the session middleware is found?
comment:15 Changed 8 years ago by
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.