コード例 #1
0
ファイル: test_cache.py プロジェクト: castaf/Kotti
    def test_request_has_no_context(self):
        from kotti.views.cache import set_cache_headers

        with patch('kotti.views.cache.caching_policy_chooser') as chooser:
            event = MagicMock()
            event.request = {}
            set_cache_headers(event)

            assert chooser.call_count == 0
コード例 #2
0
    def test_request_has_no_context(self):
        from kotti.views.cache import set_cache_headers

        with patch('kotti.views.cache.caching_policy_chooser') as chooser:
            event = MagicMock()
            event.request = {}
            set_cache_headers(event)

            assert chooser.call_count == 0
コード例 #3
0
    def test_header_set_before(self):
        from kotti.views.cache import CACHE_POLICY_HEADER
        from kotti.views.cache import set_cache_headers

        event = MagicMock()
        event.response.headers = {CACHE_POLICY_HEADER: 'Random policy'}

        with patch('kotti.views.cache.caching_policy_chooser') as chooser:
            with pytest.raises(KeyError):
                set_cache_headers(event)

        assert chooser.call_count == 0
コード例 #4
0
ファイル: test_cache.py プロジェクト: MichaelGregory/Kotti
    def test_header_set_before(self):
        from kotti.views.cache import CACHE_POLICY_HEADER
        from kotti.views.cache import set_cache_headers

        event = MagicMock()
        event.response.headers = {CACHE_POLICY_HEADER: 'Random policy'}

        with patch('kotti.views.cache.caching_policy_chooser') as chooser:
            with pytest.raises(KeyError):
                set_cache_headers(event)

        assert chooser.call_count == 0
コード例 #5
0
ファイル: test_cache.py プロジェクト: umeboshi2/Kotti
    def test_caching_policy_chooser(self):
        from kotti.views.cache import set_cache_headers

        with patch("kotti.views.cache.caching_policy_chooser") as chooser:
            chooser.return_value = "Random policy"

            event = MagicMock()
            event.response.headers.get.return_value = None

            with pytest.raises(KeyError):
                set_cache_headers(event)

        chooser.assert_called_with(event.request.context, event.request, event.response)
コード例 #6
0
    def test_caching_policy_chooser(self):
        from kotti.views.cache import set_cache_headers

        with patch('kotti.views.cache.caching_policy_chooser') as chooser:
            chooser.return_value = 'Random policy'

            event = MagicMock()
            event.response.headers.get.return_value = None

            with pytest.raises(KeyError):
                set_cache_headers(event)

        chooser.assert_called_with(event.request.context, event.request,
                                   event.response)
コード例 #7
0
ファイル: test_cache.py プロジェクト: umeboshi2/Kotti
    def test_caching_policy_chooser_raises(self):
        from kotti.views.cache import set_cache_headers

        def raiser(*args, **kw):
            raise Exception()

        with patch("kotti.views.cache.caching_policy_chooser") as chooser:
            chooser.side_effect = raiser

            event = MagicMock()
            event.response.headers.get.return_value = None

            with patch("kotti.views.cache.logger"):
                set_cache_headers(event)

        chooser.assert_called_with(event.request.context, event.request, event.response)
コード例 #8
0
    def test_caching_policy_chooser_raises(self):
        from kotti.views.cache import set_cache_headers

        def raiser(*args, **kw):
            raise Exception()

        with patch('kotti.views.cache.caching_policy_chooser') as chooser:
            chooser.side_effect = raiser

            event = MagicMock()
            event.response.headers.get.return_value = None

            with patch('kotti.views.cache.logger'):
                set_cache_headers(event)

        chooser.assert_called_with(event.request.context, event.request,
                                   event.response)