PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/hyde/tests/ext/test_urlcleaner.py

http://github.com/hyde/hyde
Python | 59 lines | 46 code | 7 blank | 6 comment | 0 complexity | f0401c4812b70c92f40714c60124ecbc MD5 | raw file
 1# -*- coding: utf-8 -*-
 2"""
 3Use nose
 4`$ pip install nose`
 5`$ nosetests`
 6"""
 7from hyde.generator import Generator
 8from hyde.model import Config
 9from hyde.site import Site
10
11from fswrap import File, Folder
12import yaml
13
14TEST_SITE = File(__file__).parent.parent.child_folder('_test')
15
16
17class TestUrlCleaner(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_url_cleaner(self):
28           s = Site(TEST_SITE)
29           cfg = """
30           plugins:
31                - hyde.ext.plugins.urls.UrlCleanerPlugin
32           urlcleaner:
33                index_file_names:
34                    - about.html
35                strip_extensions:
36                    - html
37                append_slash: true
38           """
39           s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
40           text = """
41   {% extends "base.html" %}
42
43   {% block main %}
44   <a id="index" href="{{ content_url('about.html') }}"></a>
45   <a id="blog" href="{{ content_url('blog/2010/december/merry-christmas.html') }}"></a>
46   {% endblock %}
47   """
48
49           about2 = File(TEST_SITE.child('content/test.html'))
50           about2.write(text)
51           gen = Generator(s)
52           gen.generate_all()
53
54           from pyquery import PyQuery
55           target = File(Folder(s.config.deploy_root_path).child('test.html'))
56           text = target.read_all()
57           q = PyQuery(text)
58           assert q('a#index').attr("href") == '/'
59           assert q('a#blog').attr("href") == '/blog/2010/december/merry-christmas'