test_blogit2.py 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import shutil
  3. from tinydb import Query
  4. from blogit2 import find_new_posts, DB
  5. post_dummy = """title: Blog post {}
  6. author: Famous author
  7. published: 2015-01-16
  8. tags: [python, git, bash]
  9. public: yes
  10. chronological: yes
  11. kind: writing
  12. summary: |
  13. This is a summry of post {}
  14. ...
  15. This is the body of post {}
  16. """
  17. Posts = Query()
  18. if not DB['posts'].contains(Posts.filename == 'post4.md'):
  19. DB['posts'].insert({'filename': 'post4.md'})
  20. def create_posts():
  21. os.mkdir('content')
  22. os.chdir('content')
  23. for p in range(1,4):
  24. with open('post'+str(p)+'.md', 'a') as f:
  25. f.write(post_dummy.format(p,p,p))
  26. os.chdir('..')
  27. def clean_posts():
  28. if os.path.exists('content'):
  29. shutil.rmtree('content')
  30. def test_find_new_posts():
  31. clean_posts()
  32. create_posts()
  33. new = list(find_new_posts(DB['posts']))
  34. assert len(DB['posts']) == 4
  35. assert len(new) == 3
  36. os.unlink('blogit.db')