Beispiel #1
0
    def test_skip_check(self):
        decorator = gae_html.cacheAndRender(skip_check=lambda controller: True)(MockController.get)
        response = decorator(self.controller)
        
        assert response is None
        assert self.controller.called

        from_memcache = memcache.get(MockController.PATH)
        assert from_memcache is None
Beispiel #2
0
    def test_use_datastore(self):
        decorator = gae_html.cacheAndRender(use_datastore=True)(MockController.get)
        response = decorator(self.controller)

        assert response == MockController.MINIFIED
        assert self.controller.called

        from_datastore = gae_html.HTMLCache.get_by_id(MockController.PATH, use_memcache=False)
        assert from_datastore.html == MockController.MINIFIED
Beispiel #3
0
    def test_cached_memcache(self):
        # test what happens when the response is already in memcache
        memcache.set(MockController.PATH, MockController.MINIFIED)

        decorator = gae_html.cacheAndRender()(MockController.get)
        response = decorator(self.controller)

        assert response == MockController.MINIFIED
        assert not self.controller.called
        assert self.controller.response.unicode_body == MockController.MINIFIED
Beispiel #4
0
    def test_cached_datastore(self):
        # test what happens when the response is already in the datastore
        html_cache = gae_html.HTMLCache(id=MockController.PATH, html=MockController.MINIFIED)
        html_cache.put()

        decorator = gae_html.cacheAndRender(use_datastore=True)(MockController.get)
        response = decorator(self.controller)

        assert response == MockController.MINIFIED
        assert not self.controller.called
        assert self.controller.response.unicode_body == MockController.MINIFIED
Beispiel #5
0
    def test_default(self):
        decorator = gae_html.cacheAndRender()(MockController.get)

        response = decorator(self.controller)
        assert response == MockController.MINIFIED
        assert self.controller.called

        # should be in memcache but not datastore by default
        from_memcache = memcache.get(MockController.PATH)
        assert from_memcache == MockController.MINIFIED

        from_datastore = gae_html.HTMLCache.get_by_id(MockController.PATH, use_memcache=False)
        assert from_datastore is None
Beispiel #6
0
    def test_expires(self):
        # we also use the datastore here so that we can check the expires on that
        decorator = gae_html.cacheAndRender(expires=1, use_datastore=True)(MockController.get)
        response = decorator(self.controller)

        assert response == MockController.MINIFIED
        assert self.controller.called

        from_memcache = memcache.get(MockController.PATH)
        assert from_memcache == MockController.MINIFIED

        from_datastore = gae_html.HTMLCache.get_by_id(MockController.PATH, use_memcache=False)
        assert from_datastore is not None
        assert from_datastore.expires == 1

        # sleep and then check the cache again
        sleep(1)

        from_memcache = memcache.get(MockController.PATH)
        assert from_memcache is None
Beispiel #7
0
    def test_include_comments(self):
        decorator = gae_html.cacheAndRender(include_comments=True)(MockController.get)
        response = decorator(self.controller)

        assert response == MockController.MINIFIED_COMMENT
        assert self.controller.called
Beispiel #8
0
    def test_minify(self):
        decorator = gae_html.cacheAndRender(minify=False)(MockController.get)
        response = decorator(self.controller)

        assert response == MockController.HTML
        assert self.controller.called