PageRenderTime 33ms CodeModel.GetById 28ms 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
Possible License(s): MIT
  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from hyde.generator import Generator
  8. from hyde.model import Config
  9. from hyde.site import Site
  10. from fswrap import File, Folder
  11. import yaml
  12. TEST_SITE = File(__file__).parent.parent.child_folder('_test')
  13. class TestUrlCleaner(object):
  14. def setUp(self):
  15. TEST_SITE.make()
  16. TEST_SITE.parent.child_folder(
  17. 'sites/test_jinja').copy_contents_to(TEST_SITE)
  18. def tearDown(self):
  19. TEST_SITE.delete()
  20. def test_url_cleaner(self):
  21. s = Site(TEST_SITE)
  22. cfg = """
  23. plugins:
  24. - hyde.ext.plugins.urls.UrlCleanerPlugin
  25. urlcleaner:
  26. index_file_names:
  27. - about.html
  28. strip_extensions:
  29. - html
  30. append_slash: true
  31. """
  32. s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
  33. text = """
  34. {% extends "base.html" %}
  35. {% block main %}
  36. <a id="index" href="{{ content_url('about.html') }}"></a>
  37. <a id="blog" href="{{ content_url('blog/2010/december/merry-christmas.html') }}"></a>
  38. {% endblock %}
  39. """
  40. about2 = File(TEST_SITE.child('content/test.html'))
  41. about2.write(text)
  42. gen = Generator(s)
  43. gen.generate_all()
  44. from pyquery import PyQuery
  45. target = File(Folder(s.config.deploy_root_path).child('test.html'))
  46. text = target.read_all()
  47. q = PyQuery(text)
  48. assert q('a#index').attr("href") == '/'
  49. assert q('a#blog').attr("href") == '/blog/2010/december/merry-christmas'