test_post.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os
  2. import shutil
  3. from tinydb import Query
  4. from blogit.blogit import find_new_posts, DB, Entry, Tag
  5. from blogit.blogit import CONFIG, new_build
  6. post_dummy = """title: Blog post {}
  7. author: Famous author
  8. published: 2015-01-1{}
  9. tags: [python, git, bash, linux]
  10. public: yes
  11. chronological: yes
  12. kind: writing
  13. summary: |
  14. This is a summry of post {}. Donec id elit non mi porta gravida at eget metus. Fusce dapibus
  15. ...
  16. This is the body of post {}. 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.
  17. This is a snippet in bash
  18. ```bash
  19. $ for i in `seq 1 10`; do
  20. echo $i
  21. done
  22. VAR="variable"
  23. echo "\${VAR}"
  24. ```
  25. This is a snippet in python
  26. ```
  27. def yay(top):
  28. for i in range(1, top+1):
  29. yield i
  30. ```
  31. for i in yay:
  32. print(i)
  33. ```
  34. """
  35. def create_posts():
  36. os.mkdir('content')
  37. os.chdir('content')
  38. for p in range(1,4):
  39. with open('post'+str(p)+'.md', 'a') as f:
  40. f.write(post_dummy.format(p,p,p))
  41. os.chdir('..')
  42. def test_tag():
  43. new = list(find_new_posts(DB.posts))
  44. t = Tag('python')
  45. t.posts = [1,2,3]
  46. t.render()
  47. import pytest
  48. def test_raises():
  49. t = Tag('python')
  50. with pytest.raises(ValueError):
  51. t.posts = 1