test_all.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import os
  2. from blogit.blogit import DB, CONFIG, find_new_posts_and_pages
  3. CONFIG['content_root'] = 'test_root'
  4. tags = ['foo', 'bar', 'baz', 'bug', 'buf']
  5. shift = lambda l, n: l[-n:] + l[:-n]
  6. post = '''\
  7. ---
  8. title: Blog post {number}
  9. author: Famous author
  10. published: 2015-01-{number}
  11. tags: {tags}
  12. public: yes
  13. chronological: yes
  14. kind: writing
  15. summary: This is a summry of post {number}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus
  16. ---
  17. This is the body of post {number}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
  18. This is a snippet in bash
  19. ```bash
  20. $ for i in `seq 1 10`; do
  21. echo $i
  22. done
  23. VAR="variable"
  24. echo $VAR
  25. # This is a very long long long long long long long long long long comment
  26. ```
  27. This is a snippet in python
  28. ```python
  29. def yay(top):
  30. for i in range(1, top+1):
  31. yield i
  32. for i in yay:
  33. print(i)
  34. ```
  35. '''
  36. try:
  37. os.mkdir(CONFIG['content_root'])
  38. except OSError:
  39. pass
  40. shift_factors = map(lambda x: (x - 1) / 5 +1, range(1,21))
  41. f = open((os.path.join(CONFIG['content_root'],
  42. 'page.md')), 'w')
  43. f.write("""\
  44. ---
  45. title: example page
  46. public: yes
  47. kind: page
  48. template: about.html
  49. ---
  50. # some heading
  51. content paragraph
  52. ## heading 2
  53. some more content
  54. """)
  55. f.close()
  56. def write_file(i):
  57. f = open((os.path.join(CONFIG['content_root'],
  58. 'post{}.md'.format(i))), 'w')
  59. f.write(post.format(**{'number': i,
  60. 'tags': shift(tags, shift_factors[i-1])[:-1]}))
  61. [write_file(i) for i in range(1, 21)]
  62. def test_find_new_posts_and_pages():
  63. entries = [e for e in find_new_posts_and_pages(DB)]
  64. pages = [e[1] for e in entries if str(e[1]).endswith('page.md')]
  65. assert page is not None
  66. os.unlink(DB._db._storage._handle.name)