Oz N Tiram преди 9 години
родител
ревизия
1df89b0ed7
променени са 2 файла, в които са добавени 18 реда и са изтрити 8 реда
  1. 6 4
      blogit/blogit.py
  2. 12 4
      tests/test_all.py

+ 6 - 4
blogit/blogit.py

@@ -169,7 +169,7 @@ class Entry(object):
 
     @classmethod
     def entry_from_db(kls, filename):
-        f = os.path.join(CONFIG['content_root'], filename)
+        f = os.path.join(filename)
         return kls(f)
 
     def __init__(self, path):
@@ -350,13 +350,15 @@ def build():
     tags = dict()
     root = CONFIG['content_root']
     for post_id, post in find_new_posts_and_pages(DB):
-        entry = post
+        # entry = post
+        # this method will also parse the post's tags and
+        # update the DB collection containing the tags.
         if post.render():
             if post.header['kind'] in ['writing', 'link']:
-                for tag in entry.tags:
+                for tag in post.tags:
                     tag.posts = [post_id]
                     tags[tag.name] = tag
-        print("     %s" % entry.path)
+        print("%s" % post.path)
 
     for name, to in tags.iteritems():
         print("updating tag %s" % name)

+ 12 - 4
tests/test_all.py

@@ -1,9 +1,11 @@
 import os
-from blogit.blogit import DB, CONFIG, find_new_posts_and_pages
-
+from blogit.blogit import CONFIG, find_new_posts_and_pages, DataBase
+from blogit.blogit import Entry
 
 CONFIG['content_root'] = 'test_root'
 
+DB = DataBase(os.path.join(CONFIG['content_root'], 'blogit.db'))
+
 tags = ['foo', 'bar', 'baz', 'bug', 'buf']
 
 shift = lambda l, n: l[-n:] + l[:-n]
@@ -88,7 +90,13 @@ def test_find_new_posts_and_pages():
 
     entries = [e for e in find_new_posts_and_pages(DB)]
     pages = [e[1] for e in entries if str(e[1]).endswith('page.md')]
-    assert page is not None
+    assert pages is not None
+
+    assert len(DB.posts.all()) == 20
+
+
+def test_tags():
+    entries = map(Entry.entry_from_db, [e.get('filename') for e in DB.posts.all()])
 
-os.unlink(DB._db._storage._handle.name)
+#os.unlink(DB._db._storage._handle.name)