/hyde/tests/ext/test_flattener.py

http://github.com/hyde/hyde · Python · 68 lines · 49 code · 13 blank · 6 comment · 0 complexity · c60349a19e3badf9ddfb89075a4996c5 MD5 · raw file

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