Commits

Andriy Kornatskyy committed c7be621

Use handler_cache as a synonym for wheezy.http.response_cache.

  • Participants
  • Parent commits 37f1b6c

Comments (0)

Files changed (2)

File src/wheezy/web/caching.py

 """ ``caching`` module.
 """
 
+from wheezy.http import response_cache as handler_cache
 
-def handler_cache(profile):
-    """ Decorator that applies cache profile strategy to the
-        wrapping handler.
-    """
-    def decorate(method):
-        if not profile.enabled:
-            return method
 
-        if profile.request_vary:
-            def cache(handler, *args, **kwargs):
-                response = method(handler, *args, **kwargs)
-                response.cache_profile = profile
-                if response.cache_policy is None:
-                    response.cache_policy = profile.cache_policy()
-                return response
-            return cache
-        else:
-            def no_cache(handler, *args, **kwargs):
-                response = method(handler, *args, **kwargs)
-                if response.cache_policy is None:
-                    response.cache_policy = profile.cache_policy()
-                return response
-            return no_cache
-    return decorate
+assert handler_cache

File src/wheezy/web/tests/test_caching.py

 
 """ Unit tests for ``wheezy.web.caching``.
 """
-
-import unittest
-
-from mock import Mock
-
-
-class HandlerCacheTestCase(unittest.TestCase):
-    """ Test the ``handler_cache``.
-    """
-
-    def test_profile_not_enabled(self):
-        """ Cache profile is disabled.
-        """
-        from wheezy.web.caching import handler_cache
-        mock_profile = Mock()
-        mock_profile.enabled = False
-        mock_method = Mock(return_value='response')
-        handler = handler_cache(mock_profile)(mock_method)
-        assert 'response' == handler('handler')
-
-    def test_no_cache(self):
-        """ No cache strategy, cache policy is defined in response
-            do not overwrite.
-        """
-        from wheezy.web.caching import handler_cache
-        mock_profile = Mock()
-        mock_profile.enabled = True
-        mock_profile.request_vary = None
-        mock_response = Mock()
-        mock_response.cache_policy = 'policy'
-        mock_method = Mock(return_value=mock_response)
-        handler = handler_cache(mock_profile)(mock_method)
-        assert mock_response == handler('handler')
-        assert 'policy' == mock_response.cache_policy
-        mock_method.assert_called_once_with('handler')
-
-    def test_no_cache_apply_cache_policy(self):
-        """ No cache strategy, cache policy is not defined in response,
-            apply cache policy per cache profile.
-        """
-        from wheezy.web.caching import handler_cache
-        mock_profile = Mock()
-        mock_profile.enabled = True
-        mock_profile.request_vary = None
-        mock_profile.cache_policy.return_value = 'policy'
-        mock_response = Mock()
-        mock_response.cache_policy = None
-        mock_method = Mock(return_value=mock_response)
-        handler = handler_cache(mock_profile)(mock_method)
-        assert mock_response == handler('handler')
-        assert 'policy' == mock_response.cache_policy
-        mock_method.assert_called_once_with('handler')
-
-    def test_cache(self):
-        """ Cache strategy, cache policy is defined in response
-            do not overwrite.
-        """
-        from wheezy.web.caching import handler_cache
-        mock_profile = Mock()
-        mock_profile.enabled = True
-        mock_profile.request_vary = 'vary'
-        mock_response = Mock()
-        mock_response.cache_profile = 'profile'
-        mock_response.cache_policy = 'policy'
-        mock_method = Mock(return_value=mock_response)
-        handler = handler_cache(mock_profile)(mock_method)
-        assert mock_response == handler('handler')
-        assert 'policy' == mock_response.cache_policy
-        mock_method.assert_called_once_with('handler')
-        assert mock_profile == mock_response.cache_profile
-
-    def test_cache_apply_cache_policy(self):
-        """ Cache strategy, cache policy is not defined in response,
-            apply cache policy per cache profile.
-        """
-        from wheezy.web.caching import handler_cache
-        mock_profile = Mock()
-        mock_profile.enabled = True
-        mock_profile.request_vary = 'vary'
-        mock_profile.cache_policy.return_value = 'policy'
-        mock_response = Mock()
-        mock_response.cache_profile = 'profile'
-        mock_response.cache_policy = None
-        mock_method = Mock(return_value=mock_response)
-        handler = handler_cache(mock_profile)(mock_method)
-        assert mock_response == handler('handler')
-        assert 'policy' == mock_response.cache_policy
-        mock_method.assert_called_once_with('handler')
-        assert mock_profile == mock_response.cache_profile