test_list.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import unittest
  2. import shutil
  3. import os
  4. import makesite
  5. from test import path
  6. class PagesTest(unittest.TestCase):
  7. def setUp(self):
  8. self.site_path = path.temppath('site')
  9. def tearDown(self):
  10. shutil.rmtree(self.site_path)
  11. def test_list(self):
  12. posts = [{'content': 'Foo'}, {'content': 'Bar'}]
  13. dst = os.path.join(self.site_path, 'list.txt')
  14. list_layout = '<div>{{ content }}</div>'
  15. item_layout = '<p>{{ content }}</p>'
  16. makesite.make_list(posts, dst, list_layout, item_layout)
  17. with open(os.path.join(self.site_path, 'list.txt')) as f:
  18. self.assertEqual(f.read(), '<div><p>Foo</p><p>Bar</p></div>')
  19. def test_list_params(self):
  20. posts = [{'content': 'Foo', 'title': 'foo'},
  21. {'content': 'Bar', 'title': 'bar'}]
  22. dst = os.path.join(self.site_path, 'list.txt')
  23. list_layout = '<div>{{ key }}:{{ title }}:{{ content }}</div>'
  24. item_layout = '<p>{{ key }}:{{ title }}:{{ content }}</p>'
  25. makesite.make_list(posts, dst, list_layout, item_layout,
  26. key='val', title='lorem')
  27. with open(os.path.join(self.site_path, 'list.txt')) as f:
  28. text = f.read()
  29. self.assertEqual(text,
  30. '<div>val:lorem:<p>val:foo:Foo</p><p>val:bar:Bar</p></div>')
  31. def test_dst_params(self):
  32. posts = [{'content': 'Foo'}, {'content': 'Bar'}]
  33. dst = os.path.join(self.site_path, '{{ key }}.txt')
  34. list_layout = '<div>{{ content }}</div>'
  35. item_layout = '<p>{{ content }}</p>'
  36. makesite.make_list(posts, dst, list_layout, item_layout, key='val')
  37. expected_path = os.path.join(self.site_path, 'val.txt')
  38. self.assertTrue(os.path.isfile(expected_path))
  39. with open(expected_path) as f:
  40. self.assertEqual(f.read(), '<div><p>Foo</p><p>Bar</p></div>')