Ejemplo n.º 1
0
    def test_cache_bust_multi_glob(self):
        parent_path = pathlib.Path(self.content_path.name)
        child1_path = pathlib.Path(self.content_path.name, "bust-me.jpg")
        child1_path.touch()
        child2_path = pathlib.Path(self.content_path.name, "page.html")
        child2_path.touch()

        meta_path = pathlib.Path(self.content_path.name, "meta.yaml")
        with meta_path.open("w") as f:
            f.write("cache_bust_glob:\n  - \"*.jpeg\"\n  - \"*.jpg\"")

        parent_node = Node.from_path(parent_path)
        parent_node.meta.update(**self.default_settings)
        self.assertEqual(list(parent_node.children.keys()),
                         ["bust-me.jpg", "page.html"])

        child1_node = parent_node.children["bust-me.jpg"]
        child2_node = parent_node.children["page.html"]

        self.assertEqual(
            child1_node.full_path,
            str(
                pathlib.Path(self.deploy_path.name,
                             "bust-me.{}.jpg".format(EMPTY_DIGEST))))
        self.assertEqual(child2_node.full_path,
                         str(pathlib.Path(self.deploy_path.name, "page.html")))

        self.assertEqual(child1_node.full_url,
                         "/bust-me.{}.jpg".format(EMPTY_DIGEST))
        self.assertEqual(child2_node.full_url, "/page")
Ejemplo n.º 2
0
    def test_from_path(self):
        parent_path = pathlib.Path(self.content_path.name)
        child1_path = pathlib.Path(self.content_path.name, "page1.html")
        child1_path.touch()
        child2_path = pathlib.Path(self.content_path.name, "page2.html")
        child2_path.touch()

        parent_node = Node.from_path(parent_path)
        self.assertEqual(list(parent_node.children.keys()),
                         ["page1.html", "page2.html"])
Ejemplo n.º 3
0
    def test_from_path_and_ignore(self):
        parent_path = pathlib.Path(self.content_path.name)
        child1_path = pathlib.Path(self.content_path.name, "page1.html")
        child1_path.touch()
        child2_path = pathlib.Path(self.content_path.name, "page2.html")
        child2_path.touch()
        child3_path = pathlib.Path(self.content_path.name, "picture.jpg")
        child3_path.touch()

        parent_node = Node.from_path(parent_path, meta={"ignore": "*.html"})
        self.assertEqual(list(parent_node.children.keys()), ["picture.jpg"])
Ejemplo n.º 4
0
    def test_from_path_with_meta(self):
        parent_path = pathlib.Path(self.content_path.name)
        child1_path = pathlib.Path(self.content_path.name, "page1.html")
        child1_path.touch()
        child2_path = pathlib.Path(self.content_path.name, "page2.html")
        child2_path.touch()

        meta_path = pathlib.Path(self.content_path.name, "meta.yaml")
        with meta_path.open("w") as f:
            f.write("test: bob")

        parent_node = Node.from_path(parent_path)
        self.assertEqual(list(parent_node.children.keys()),
                         ["page1.html", "page2.html"])
        self.assertEqual(parent_node.meta["test"], "bob")
Ejemplo n.º 5
0
    def test_get_from_path_not_existing_from_pathlib(self):
        parent_path = pathlib.Path(self.content_path.name)
        pathlib.Path(self.content_path.name, "images").mkdir()
        child1_path = pathlib.Path(self.content_path.name, "images",
                                   "bust-me.jpg")
        child1_path.touch()
        pathlib.Path(self.content_path.name, "pages").mkdir()
        child2_path = pathlib.Path(self.content_path.name, "pages",
                                   "page.html")
        child2_path.touch()

        parent_node = Node.from_path(parent_path)

        child_node = parent_node.children["images"].children["bust-me.jpg"]

        with self.assertRaises(OSError):
            child_node.get_from_path(pathlib.Path("..", "not-a-page.html"))
Ejemplo n.º 6
0
    def test_get_from_path_relative_str_with_dot(self):
        parent_path = pathlib.Path(self.content_path.name)
        pathlib.Path(self.content_path.name, "images").mkdir()
        child1_path = pathlib.Path(self.content_path.name, "images",
                                   "bust-me.jpg")
        child1_path.touch()
        pathlib.Path(self.content_path.name, "pages").mkdir()
        child2_path = pathlib.Path(self.content_path.name, "pages",
                                   "page.html")
        child2_path.touch()

        parent_node = Node.from_path(parent_path)

        child_node = parent_node.children["pages"]
        target_node = parent_node.children["pages"].children["page.html"]

        self.assertEqual(child_node.get_from_path("./page.html"), target_node)
Ejemplo n.º 7
0
    def test_from_path_meta_comes_first(self):
        parent_path = pathlib.Path(self.content_path.name)

        # not sure if default ordering for files is by creation time or by
        # name, so let's write one file here, and another after the meta.yaml
        child1_path = pathlib.Path(self.content_path.name, "1page.html")
        child1_path.touch()

        path = pathlib.Path(self.content_path.name, "meta.yaml")
        with path.open("w") as f:
            f.write(YAML_WITH_IGNORE)

        child2_path = pathlib.Path(self.content_path.name, "page2.html")
        child2_path.touch()

        parent_node = Node.from_path(parent_path, meta={})
        self.assertEqual(list(parent_node.children.keys()), [])
Ejemplo n.º 8
0
    def test_get_from_path_absolute_pathlib(self):
        parent_path = pathlib.Path(self.content_path.name)
        pathlib.Path(self.content_path.name, "images").mkdir()
        child1_path = pathlib.Path(self.content_path.name, "images",
                                   "bust-me.jpg")
        child1_path.touch()
        pathlib.Path(self.content_path.name, "pages").mkdir()
        child2_path = pathlib.Path(self.content_path.name, "pages",
                                   "page.html")
        child2_path.touch()

        parent_node = Node.from_path(parent_path)

        child_node = parent_node.children["images"].children["bust-me.jpg"]
        target_node = parent_node.children["pages"].children["page.html"]

        self.assertEqual(
            child_node.get_from_path(pathlib.Path("/pages/page.html")),
            target_node)
Ejemplo n.º 9
0
    def test_cache_bust_text_file(self):
        parent_path = pathlib.Path(self.content_path.name)
        child_path = pathlib.Path(self.content_path.name, "bust-me.jpg")
        with child_path.open("w") as f:
            f.write(JSON_FILE)

        parent_node = Node.from_path(parent_path)
        parent_node.meta.update(**self.default_settings)
        parent_node.meta["cache_bust_glob"] = "*"
        self.assertEqual(list(parent_node.children.keys()), ["bust-me.jpg"])

        child_node = parent_node.children["bust-me.jpg"]

        self.assertEqual(
            child_node.full_path,
            str(
                pathlib.Path(self.deploy_path.name,
                             "bust-me.{}.jpg".format(JSON_DIGEST))))

        self.assertEqual(child_node.full_url,
                         "/bust-me.{}.jpg".format(JSON_DIGEST))
Ejemplo n.º 10
0
    def test_root_node_is_kept(self):
        parent_path = pathlib.Path(self.content_path.name)
        pathlib.Path(self.content_path.name, "images").mkdir()
        pathlib.Path(self.content_path.name, "pages").mkdir()
        child_path = pathlib.Path(self.content_path.name, "pages", "page.html")
        child_path.touch()

        parent_node = Node.from_path(parent_path)

        self.assertEqual(parent_node.root_node, parent_node)
        self.assertEqual(parent_node.children["pages"].root_node, parent_node)
        self.assertEqual(
            parent_node.children["pages"].children["page.html"].root_node,
            parent_node)
        self.assertEqual(
            parent_node.children["pages"].children["page.html"].parent.
            root_node, parent_node)
        self.assertEqual(
            parent_node.children["pages"].children["page.html"].parent.parent.
            root_node, parent_node)
        self.assertEqual(
            parent_node.children["pages"].children["page.html"].parent.parent.
            root_node, parent_node)