|
@@ -2,7 +2,7 @@ import os
|
|
import sys
|
|
import sys
|
|
import pytest
|
|
import pytest
|
|
from bs4 import BeautifulSoup
|
|
from bs4 import BeautifulSoup
|
|
-from tinydb import Query, where
|
|
|
|
|
|
+from tinydb import where
|
|
|
|
|
|
sys.path.insert(0, os.getcwd())
|
|
sys.path.insert(0, os.getcwd())
|
|
from conf import CONFIG
|
|
from conf import CONFIG
|
|
@@ -20,13 +20,12 @@ CONFIG['content_root'] = 'test_root'
|
|
ARCHIVE_SIZE = 10
|
|
ARCHIVE_SIZE = 10
|
|
|
|
|
|
from blogit.blogit import (find_new_posts_and_pages, DataBase,
|
|
from blogit.blogit import (find_new_posts_and_pages, DataBase,
|
|
- Entry, Tag, _sort_entries, _get_last_entries,
|
|
|
|
|
|
+ Entry, Tag, _get_last_entries,
|
|
render_archive, update_index, build)
|
|
render_archive, update_index, build)
|
|
|
|
|
|
import blogit.blogit as m
|
|
import blogit.blogit as m
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
DB = DataBase(os.path.join(CONFIG['content_root'], 'blogit.db'))
|
|
DB = DataBase(os.path.join(CONFIG['content_root'], 'blogit.db'))
|
|
|
|
|
|
# monkey patch to local DB
|
|
# monkey patch to local DB
|
|
@@ -105,6 +104,7 @@ some more content
|
|
""")
|
|
""")
|
|
f.close()
|
|
f.close()
|
|
|
|
|
|
|
|
+
|
|
def write_file(i):
|
|
def write_file(i):
|
|
f = open((os.path.join(CONFIG['content_root'],
|
|
f = open((os.path.join(CONFIG['content_root'],
|
|
'post{0:03d}.md'.format(i))), 'w')
|
|
'post{0:03d}.md'.format(i))), 'w')
|
|
@@ -133,6 +133,7 @@ def test_find_new_posts_and_pages():
|
|
foo = DB.tags.search(where('name')=='foo')
|
|
foo = DB.tags.search(where('name')=='foo')
|
|
assert foo[0]['post_ids'] == list(range(1, 16))
|
|
assert foo[0]['post_ids'] == list(range(1, 16))
|
|
|
|
|
|
|
|
+
|
|
def test_tags():
|
|
def test_tags():
|
|
entries = [
|
|
entries = [
|
|
Entry.entry_from_db(os.path.join(CONFIG['content_root'],
|
|
Entry.entry_from_db(os.path.join(CONFIG['content_root'],
|
|
@@ -156,7 +157,6 @@ def test_tags():
|
|
list(new_tag.entries)
|
|
list(new_tag.entries)
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
def test_slug():
|
|
def test_slug():
|
|
|
|
|
|
t = Tag('foo:bar')
|
|
t = Tag('foo:bar')
|
|
@@ -194,8 +194,9 @@ def test_tag_entries():
|
|
assert len(entries)
|
|
assert len(entries)
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
+
|
|
def test_tag_post_ids():
|
|
def test_tag_post_ids():
|
|
- m ="""\
|
|
|
|
|
|
+ m = """\
|
|
---
|
|
---
|
|
title: Blog post {}
|
|
title: Blog post {}
|
|
author: Famous author
|
|
author: Famous author
|
|
@@ -223,8 +224,6 @@ summary: This is a summary
|
|
e1.render()
|
|
e1.render()
|
|
[t.render() for t in e1.tags]
|
|
[t.render() for t in e1.tags]
|
|
|
|
|
|
- l = _sort_entries([e2, e1])
|
|
|
|
- assert l == [e2, e1]
|
|
|
|
assert len(DB.posts.all()) == 22
|
|
assert len(DB.posts.all()) == 22
|
|
|
|
|
|
|
|
|
|
@@ -243,10 +242,11 @@ def test_tag_render():
|
|
|
|
|
|
assert len(DB.posts.all()) == 22
|
|
assert len(DB.posts.all()) == 22
|
|
|
|
|
|
|
|
+
|
|
def test_get_last_entries():
|
|
def test_get_last_entries():
|
|
|
|
|
|
assert len(DB.posts.all()) == 22
|
|
assert len(DB.posts.all()) == 22
|
|
- le = _get_last_entries(DB, 10)
|
|
|
|
|
|
+ le, all = _get_last_entries(DB, 10)
|
|
assert [e.id for e in le] == list(range(22, 12, -1))
|
|
assert [e.id for e in le] == list(range(22, 12, -1))
|
|
|
|
|
|
|
|
|
|
@@ -256,7 +256,7 @@ def test_render_archive():
|
|
os.path.join(CONFIG['content_root'], e.get('filename')), e.eid) for e in
|
|
os.path.join(CONFIG['content_root'], e.get('filename')), e.eid) for e in
|
|
DB.posts.all()]
|
|
DB.posts.all()]
|
|
|
|
|
|
- render_archive(_sort_entries(entries, reversed=True)[ARCHIVE_SIZE:])
|
|
|
|
|
|
+ render_archive(entries[ARCHIVE_SIZE:])
|
|
# pages should not be in the archive
|
|
# pages should not be in the archive
|
|
with open(os.path.join(CONFIG['output_to'], 'archive', 'index.html')) as html_index:
|
|
with open(os.path.join(CONFIG['output_to'], 'archive', 'index.html')) as html_index:
|
|
soup = BeautifulSoup(html_index.read(), 'html.parser')
|
|
soup = BeautifulSoup(html_index.read(), 'html.parser')
|
|
@@ -264,7 +264,8 @@ def test_render_archive():
|
|
|
|
|
|
|
|
|
|
def test_render_index():
|
|
def test_render_index():
|
|
- update_index(_get_last_entries(DB, 10))
|
|
|
|
|
|
+ le, all_entries = _get_last_entries(DB, 10)
|
|
|
|
+ update_index(le)
|
|
with open(os.path.join(CONFIG['output_to'], 'index.html')) as html_index:
|
|
with open(os.path.join(CONFIG['output_to'], 'index.html')) as html_index:
|
|
soup = BeautifulSoup(html_index.read(), 'html.parser')
|
|
soup = BeautifulSoup(html_index.read(), 'html.parser')
|
|
assert len(soup.find_all(class_='clearfix entry')) == 10
|
|
assert len(soup.find_all(class_='clearfix entry')) == 10
|