'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, 'middlewareprefix')
    self.assertEqual(middleware.cache_alias, 'other')
    as_view_decorator = CacheMiddleware(cache_alias=None, key_prefix=None)
    self.assertEqual(as_view_decorator.cache_timeout, 30)
    self.assertEqual(as_view_decorator.key_prefix, '')
    self.assertEqual(as_view_decorator.cache_alias, 'default')
    as_view_decorator_with_custom = CacheMiddleware(cache_timeout=60, cache_alias='other', key_prefix='foo')
    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.cache_alias, 'other')
