request.template is None instead of what it should be because the response is from the
cache middleware.
Which is fine. My question is there a good way to disable the cache middleware during
tests?
"good" being atleast the following. is automatic, isn't based of value of DEBUG, doesn't
require changing django distro.
Is there a special settings file or other file imported during tests only?
thanks,
njharman
The standard (and recommended) approach if you need slightly different
settings during testing is to create a new settings file just for tests.
It will look something like this:
from settings import *
CACHE_BACKEND = 'simple://'
where "settings" is your normal settings file. This way you only
override the settings you need to. Then you run your tests with
manage.py --settings=test_settings test
Note that if you are looking for a way to entirely ignore the cache
middleware, you probably need to remove it from the middleware list.
Since you test_settings.py file can contain arbitrary Python code in it,
you can do that by examing your existing MIDDLEWARE_CLASSES list,
removing the offending entry and reassigning the result to
MIDDLEWARE_CLASSES.
Regards,
Malcolm
--
Depression is merely anger without enthusiasm.
http://www.pointy-stick.com/blog/
The problem was in incorrect order of middlewares. Cache middleware
must be after session middleware. Personally I think it is bug django
that causes such behavior. Please post your traceback of the failed
tests.
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.cache.CacheMiddleware',
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.middleware.cache.CacheMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)
On Aug 19, 12:43 am, "Placid Publishing, LLC"
> >> njharman- Hide quoted text -
>
> - Show quoted text -
DOH, my bad, I thought this was directed towards me from another post.
SORRY :-|
My site was working fine. My unittests was what were in error.
Yeah there are going to be differences between production and devel. But, personally I
believe unittests should test one thing. Not many things at once such as cache/view/db
(as an aside I'm sort of sad django doesn't have a mock db for view unittests)
So, I think you should test your cache framework and how your app uses it, but, those
tests should not be part of the view unittests.
I was testing that a specific template was being used to render page. With caching the
correct behavior is to not use any template, not to render at all, but rather to pump
contents of cache down the wire.
In my test_settings.py file I have:
# disable cache for testing
MIDDLEWARE_CLASSES.remove('django.middleware.cache.CacheMiddleware')
CACHE_BACKEND = "dummy:///"
Then run
python manage.py --settings=test_settings test
works beautifully.