コード例 #1
0
    def test_setcookie_after_reload(self, monkeypatch):
        self._monkeypatch_web(monkeypatch)
        self._monkeypatch_hooks(monkeypatch)

        p = invalidation.InvalidationProcessor(
            prefixes=['/templates'],
            cookie_name="invalidation_cookie",
            timeout=60)

        # save a doc
        doc = {"key": "/templates/site.tmpl", "type": "/type/template"}
        web.ctx.site.save(doc)

        p.reload()

        # A cookie must be set when there is a recent update known to the processor
        p(lambda: None)

        assert self.cookie == {
            "name":
            "invalidation_cookie",
            "expires":
            p.expire_time,
            "value":
            web.ctx.site.get("/templates/site.tmpl").last_modified.isoformat()
        }
コード例 #2
0
    def test_reload_on_cookie(self, monkeypatch):
        self._monkeypatch_web(monkeypatch)
        self._monkeypatch_hooks(monkeypatch)

        p = invalidation.InvalidationProcessor(
            prefixes=['/templates'], cookie_name="invalidation_cookie")

        # save a doc
        doc = {"key": "/templates/site.tmpl", "type": "/type/template"}
        web.ctx.site.save(doc)

        # call the processor
        p(lambda: None)

        # no cookie, no hook call
        assert self.hook.call_count == 0

        web.ctx.env[
            'HTTP_COOKIE'] = "invalidation_cookie=" + datetime.datetime.utcnow(
            ).isoformat()
        p(lambda: None)

        # cookie is set, hook call is expetected
        assert self.hook.call_count == 1
        assert self.hook.recent_doc.dict() == web.ctx.site.get(
            "/templates/site.tmpl").dict()
コード例 #3
0
    def test_reload_on_timeout(self, monkeypatch):
        # create the processor at 60 seconds past in time
        mock_now = datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
        monkeypatch.setattr(datetime, "datetime", MockDatetime(mock_now))

        p = invalidation.InvalidationProcessor(prefixes=['/templates'], timeout=60)

        # come back to real time
        monkeypatch.undo()

        # monkeypatch web
        self._monkeypatch_web(monkeypatch)
        self._monkeypatch_hooks(monkeypatch)

        # save a doc
        doc = {
            "key": "/templates/site.tmpl",
            "type": "/type/template"
        }
        web.ctx.site.save(doc)

        # call the processor
        p(lambda: None)
        assert self.hook.call_count == 1
        assert self.hook.recent_doc.dict() == web.ctx.site.get("/templates/site.tmpl").dict()
コード例 #4
0
    def test_reload(self, monkeypatch):
        """If reload is called and there are some modifications, each hook should get called."""
        self._monkeypatch_web(monkeypatch)
        self._monkeypatch_hooks(monkeypatch)

        # create the processor
        p = invalidation.InvalidationProcessor(prefixes=['/templates/'])

        # save a doc after creating the processor
        doc = {"key": "/templates/site.tmpl", "type": "/type/template"}
        web.ctx.site.save(doc)

        # reload and make sure the hook gets called
        p.reload()

        assert self.hook.call_count == 1
        assert (
            self.hook.recent_doc.dict()
            == web.ctx.site.get("/templates/site.tmpl").dict()
        )

        # last_update_time must get updated
        assert (
            p.last_update_time == web.ctx.site.get("/templates/site.tmpl").last_modified
        )
コード例 #5
0
    def test_is_timeout(self, monkeypatch):
        # create the processor at 60 seconds past in time
        mock_now = datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
        monkeypatch.setattr(datetime, "datetime", MockDatetime(mock_now))

        p = invalidation.InvalidationProcessor(prefixes=['/templates'], timeout=60)

        # come back to real time
        monkeypatch.undo()

        # monkeypatch web
        self._monkeypatch_web(monkeypatch)
        self._monkeypatch_hooks(monkeypatch)

        p.reload()

        # until next 60 seconds, is_timeout must be false.
        assert p.is_timeout() == False