'Ensure the constructor is correctly distinguishing between usage of CacheMiddleware as
Middleware vs. usage of CacheMiddleware as view decorator and setting attributes
appropriately.'

def test_constructor(self):

    middleware = CacheMiddleware()
    self.assertEqual(middleware.cache_timeout, 30)
    self.assertEqual(middleware.key_prefix, u'middlewareprefix')
    self.assertEqual(middleware.cache_alias, u'other')
    self.assertEqual(middleware.cache_anonymous_only, False)
    as_view_decorator = CacheMiddleware(cache_alias=None, key_prefix=None)
    self.assertEqual(as_view_decorator.cache_timeout, 300)
    self.assertEqual(as_view_decorator.key_prefix, u'')
    self.assertEqual(as_view_decorator.cache_alias, u'default')
    self.assertEqual(as_view_decorator.cache_anonymous_only, False)
    as_view_decorator_with_custom = CacheMiddleware(cache_anonymous_only=True, cache_timeout=60, cache_alias=u'other', key_prefix=u'foo')
    self.assertEqual(as_view_decorator_with_custom.cache_timeout, 60)
    self.assertEqual(as_view_decorator_with_custom.key_prefix, u'foo')
    self.assertEqual(as_view_decorator_with_custom.cache_alias, u'other')
    self.assertEqual(as_view_decorator_with_custom.cache_anonymous_only, True)
