Exemplo n.º 1
0
    def test_off_switch(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = False

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'op1'}

        @implementer(ICachingOperation)
        @adapter(Interface, Interface)
        class DummyOperation(object):
            def __init__(self, published, request):
                self.published = published
                self.request = request

            def interceptResponse(self, rulename, response):
                return None

            def modifyResponse(self, rulename, response):
                response['X-Mutated'] = rulename

        provideAdapter(DummyOperation, name='op1')

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Exemplo n.º 2
0
    def test_no_registry(self):
        provideAdapter(DefaultRulesetLookup)

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Exemplo n.º 3
0
    def test_no_registry(self):
        provideAdapter(DefaultRulesetLookup)

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Exemplo n.º 4
0
    def test_no_records(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEquals({"PUBLISHED": view}, dict(request))
        self.assertEquals({}, dict(request.response))
Exemplo n.º 5
0
    def test_no_published_object(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        response = DummyResponse()
        request = DummyRequest(None, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': None}, dict(request))
        self.assertEqual({}, dict(request.response))
Exemplo n.º 6
0
    def test_no_published_object(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        response = DummyResponse()
        request = DummyRequest(None, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': None}, dict(request))
        self.assertEqual({}, dict(request.response))
Exemplo n.º 7
0
    def test_no_mapping(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEquals({'PUBLISHED': view}, dict(request))
        self.assertEquals({}, dict(request.response))
Exemplo n.º 8
0
    def test_no_lookup_adapter(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'dummy'}

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Exemplo n.º 9
0
    def test_no_cache_rule(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        settings.operationMapping = {"testrule": "dummy"}

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEquals({"PUBLISHED": view}, dict(request))
        self.assertEquals({}, dict(request.response))
Exemplo n.º 10
0
    def test_no_mapping(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEquals({'PUBLISHED': view}, dict(request))
        self.assertEquals({}, dict(request.response))
Exemplo n.º 11
0
    def test_no_lookup_adapter(self):
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'dummy'}

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))
Exemplo n.º 12
0
    def test_operation_name_not_found(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, "testrule")
        settings.operationMapping = {"foo": "bar"}

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEquals({"PUBLISHED": view}, dict(request))
        self.assertEquals({"X-Cache-Rule": ["testrule"]}, dict(request.response))
Exemplo n.º 13
0
    def test_match_method(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyResource, 'testrule')
        settings.operationMapping = {'testrule': 'op1'}

        class DummyOperation(object):
            implements(ICachingOperation)
            adapts(Interface, Interface)

            def __init__(self, published, request):
                self.published = published
                self.request = request

            def interceptResponse(self, rulename, response):
                return None

            def modifyResponse(self, rulename, response):
                response.addHeader('X-Cache-Foo', 'test')

        provideAdapter(DummyOperation, name="op1")

        resource = DummyResource()
        response = DummyResponse()
        request = DummyRequest(resource.index_html, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEquals({'PUBLISHED': resource.index_html}, dict(request))
        self.assertEquals(
            {
                'X-Cache-Rule': ['testrule'],
                'X-Cache-Operation': ['op1'],
                'X-Cache-Foo': ['test']
            }, dict(request.response))
Exemplo n.º 14
0
    def test_operation_not_found(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'notfound'}

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({'X-Cache-Rule': ['testrule']},
                         dict(request.response))
Exemplo n.º 15
0
    def test_match_method(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyResource, "testrule")
        settings.operationMapping = {"testrule": "op1"}

        class DummyOperation(object):
            implements(ICachingOperation)
            adapts(Interface, Interface)

            def __init__(self, published, request):
                self.published = published
                self.request = request

            def interceptResponse(self, rulename, response):
                return None

            def modifyResponse(self, rulename, response):
                response.addHeader("X-Cache-Foo", "test")

        provideAdapter(DummyOperation, name="op1")

        resource = DummyResource()
        response = DummyResponse()
        request = DummyRequest(resource.index_html, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEquals({"PUBLISHED": resource.index_html}, dict(request))
        self.assertEquals(
            {"X-Cache-Rule": ["testrule"], "X-Cache-Operation": ["op1"], "X-Cache-Foo": ["test"]},
            dict(request.response),
        )
Exemplo n.º 16
0
    def test_match_method(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyResource, 'testrule')
        settings.operationMapping = {'testrule': 'op1'}

        @implementer(ICachingOperation)
        @adapter(Interface, Interface)
        class DummyOperation(object):

            def __init__(self, published, request):
                self.published = published
                self.request = request

            def interceptResponse(self, rulename, response):
                return None

            def modifyResponse(self, rulename, response):
                response.addHeader('X-Cache-Foo', 'test')

        provideAdapter(DummyOperation, name='op1')

        resource = DummyResource()
        response = DummyResponse()
        request = DummyRequest(resource.index_html, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': resource.index_html}, dict(request))
        self.assertEqual({'X-Cache-Rule': ['testrule'],
                          'X-Cache-Operation': ['op1'],
                          'X-Cache-Foo': ['test']}, dict(request.response))
Exemplo n.º 17
0
    def test_operation_not_found(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = True

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'notfound'}

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual(
            {'X-Cache-Rule': ['testrule']},
            dict(request.response)
        )
Exemplo n.º 18
0
    def test_off_switch(self):
        provideAdapter(DefaultRulesetLookup)
        provideUtility(Registry(), IRegistry)
        registry = getUtility(IRegistry)
        registry.registerInterface(ICacheSettings)
        settings = registry.forInterface(ICacheSettings)
        settings.enabled = False

        z3c.caching.registry.register(DummyView, 'testrule')
        settings.operationMapping = {'testrule': 'op1'}

        @implementer(ICachingOperation)
        @adapter(Interface, Interface)
        class DummyOperation(object):

            def __init__(self, published, request):
                self.published = published
                self.request = request

            def interceptResponse(self, rulename, response):
                return None

            def modifyResponse(self, rulename, response):
                response['X-Mutated'] = rulename

        provideAdapter(DummyOperation, name='op1')

        view = DummyView()
        response = DummyResponse()
        request = DummyRequest(view, response)
        setRequest(request)

        modifyStreamingResponse(DummyStreamingEvent(response))

        self.assertEqual({'PUBLISHED': view}, dict(request))
        self.assertEqual({}, dict(request.response))