PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/hyde/tests/ext/test_flattener.py

http://github.com/hyde/hyde
Python | 68 lines | 54 code | 8 blank | 6 comment | 0 complexity | c60349a19e3badf9ddfb89075a4996c5 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Use nose
 4`$ pip install nose`
 5`$ nosetests`
 6"""
 7
 8from hyde.generator import Generator
 9from hyde.site import Site
10from hyde.model import Config
11
12from fswrap import File
13
14TEST_SITE = File(__file__).parent.parent.child_folder('_test')
15
16
17class TestFlattner(object):
18
19    def setUp(self):
20        TEST_SITE.make()
21        TEST_SITE.parent.child_folder(
22                    'sites/test_jinja').copy_contents_to(TEST_SITE)
23
24    def tearDown(self):
25        TEST_SITE.delete()
26
27    def test_can_flatten(self):
28        s = Site(TEST_SITE)
29        cfg = """
30        plugins:
31            - hyde.ext.plugins.structure.FlattenerPlugin
32        flattener:
33            items:
34                -
35                    source: blog
36                    target: ''
37        """
38        import yaml
39        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
40        s.load()
41        gen = Generator(s)
42        gen.generate_all()
43
44        assert not s.config.deploy_root_path.child_folder('blog').exists
45        assert File(s.config.deploy_root_path.child('merry-christmas.html')).exists
46
47    def test_flattener_fixes_nodes(self):
48        s = Site(TEST_SITE)
49        cfg = """
50        plugins:
51            - hyde.ext.plugins.structure.FlattenerPlugin
52        flattener:
53            items:
54                -
55                    source: blog
56                    target: ''
57        """
58        import yaml
59        s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
60        s.load()
61        gen = Generator(s)
62        gen.generate_all()
63        blog_node = s.content.node_from_relative_path('blog')
64
65        assert blog_node
66        assert blog_node.url == '/'
67
68