Added tests for cache middlewares constructors.
This commit is contained in:
parent
e39e727ded
commit
abbdd3a622
|
@ -2083,6 +2083,7 @@ class CacheMiddlewareTest(SimpleTestCase):
|
||||||
self.assertEqual(middleware.cache_timeout, 30)
|
self.assertEqual(middleware.cache_timeout, 30)
|
||||||
self.assertEqual(middleware.key_prefix, 'middlewareprefix')
|
self.assertEqual(middleware.key_prefix, 'middlewareprefix')
|
||||||
self.assertEqual(middleware.cache_alias, 'other')
|
self.assertEqual(middleware.cache_alias, 'other')
|
||||||
|
self.assertEqual(middleware.cache, self.other_cache)
|
||||||
|
|
||||||
# If more arguments are being passed in construction, it's being used
|
# If more arguments are being passed in construction, it's being used
|
||||||
# as a decorator. First, test with "defaults":
|
# as a decorator. First, test with "defaults":
|
||||||
|
@ -2092,6 +2093,7 @@ class CacheMiddlewareTest(SimpleTestCase):
|
||||||
self.assertEqual(as_view_decorator.key_prefix, '')
|
self.assertEqual(as_view_decorator.key_prefix, '')
|
||||||
# Value of DEFAULT_CACHE_ALIAS from django.core.cache
|
# Value of DEFAULT_CACHE_ALIAS from django.core.cache
|
||||||
self.assertEqual(as_view_decorator.cache_alias, 'default')
|
self.assertEqual(as_view_decorator.cache_alias, 'default')
|
||||||
|
self.assertEqual(as_view_decorator.cache, self.default_cache)
|
||||||
|
|
||||||
# Next, test with custom values:
|
# Next, test with custom values:
|
||||||
as_view_decorator_with_custom = CacheMiddleware(
|
as_view_decorator_with_custom = CacheMiddleware(
|
||||||
|
@ -2101,6 +2103,21 @@ class CacheMiddlewareTest(SimpleTestCase):
|
||||||
self.assertEqual(as_view_decorator_with_custom.cache_timeout, 60)
|
self.assertEqual(as_view_decorator_with_custom.cache_timeout, 60)
|
||||||
self.assertEqual(as_view_decorator_with_custom.key_prefix, 'foo')
|
self.assertEqual(as_view_decorator_with_custom.key_prefix, 'foo')
|
||||||
self.assertEqual(as_view_decorator_with_custom.cache_alias, 'other')
|
self.assertEqual(as_view_decorator_with_custom.cache_alias, 'other')
|
||||||
|
self.assertEqual(as_view_decorator_with_custom.cache, self.other_cache)
|
||||||
|
|
||||||
|
def test_update_cache_middleware_constructor(self):
|
||||||
|
middleware = UpdateCacheMiddleware(empty_response)
|
||||||
|
self.assertEqual(middleware.cache_timeout, 30)
|
||||||
|
self.assertIsNone(middleware.page_timeout)
|
||||||
|
self.assertEqual(middleware.key_prefix, 'middlewareprefix')
|
||||||
|
self.assertEqual(middleware.cache_alias, 'other')
|
||||||
|
self.assertEqual(middleware.cache, self.other_cache)
|
||||||
|
|
||||||
|
def test_fetch_cache_middleware_constructor(self):
|
||||||
|
middleware = FetchFromCacheMiddleware(empty_response)
|
||||||
|
self.assertEqual(middleware.key_prefix, 'middlewareprefix')
|
||||||
|
self.assertEqual(middleware.cache_alias, 'other')
|
||||||
|
self.assertEqual(middleware.cache, self.other_cache)
|
||||||
|
|
||||||
def test_middleware(self):
|
def test_middleware(self):
|
||||||
middleware = CacheMiddleware(hello_world_view)
|
middleware = CacheMiddleware(hello_world_view)
|
||||||
|
|
Loading…
Reference in New Issue