Browse Source

fix more bugs and add testing to 100%

Oz N Tiram 9 years ago
parent
commit
d32c727053
2 changed files with 26 additions and 9 deletions
  1. 14 8
      blogit/blogit.py
  2. 12 1
      tests/test_all.py

+ 14 - 8
blogit/blogit.py

@@ -211,9 +211,9 @@ class Entry(object):
     def title(self):
         return self.header['title']
 
-    @property
-    def summary_html(self):
-        return "%s" % markdown2.markdown(self.header.get('summary', "").strip())
+    #@property
+    #def summary_html(self):
+    #    return "%s" % markdown2.markdown(self.header.get('summary', "").strip())
 
     @property
     def summary_atom(self):
@@ -258,10 +258,11 @@ class Entry(object):
         if 'tags' in self.header:  # pages can lack tags
             self.header['tags'] = self.header['tags'].split(',')
 
-        self.date = self.header.get('published', datetime.date.today())
+        self.date = self.header.get('published', datetime.datetime.now())
 
         if isinstance(self.date, unicode):
             self.date = datetime.datetime.strptime(self.date, "%Y-%m-%d")
+
         for k, v in self.header.items():
             try:
                 setattr(self, k, v)
@@ -370,9 +371,9 @@ def build():
     print("\nRendering website now...\n")
     print("entries:")
     tags = dict()
+    entries = list()
     root = CONFIG['content_root']
-    for post_id, post in find_new_posts_and_pages(DB):
-        # entry = post
+    for post, post_id in find_new_posts_and_pages(DB):
         # this method will also parse the post's tags and
         # update the db collection containing the tags.
         if post.render():
@@ -380,6 +381,7 @@ def build():
                 for tag in post.tags:
                     tag.posts = [post_id]
                     tags[tag.name] = tag
+        entries.append(post)
         print("%s" % post.path)
 
     for name, to in tags.iteritems():
@@ -392,8 +394,12 @@ def build():
 
     # update archive
     print("updating archive")
-    render_archive(_sort_entries([Entry(p['filename'])
-                   for p in db.posts.all()])[ARCHIVE_SIZE:10])
+
+    #entries = [Entry.entry_from_db(
+    #    os.path.join(CONFIG['content_root'], e.get('filename'))) for e in
+    #    DB.posts.all()]
+
+    render_archive(_sort_entries(entries, reversed=True)[ARCHIVE_SIZE:])
 
 
 

+ 12 - 1
tests/test_all.py

@@ -5,7 +5,7 @@ from tinydb import Query, where
 
 from blogit.blogit import (CONFIG, find_new_posts_and_pages, DataBase,
                            Entry, Tag, _sort_entries, _get_last_entries,
-                           render_archive)
+                           render_archive, update_index, build)
 
 import blogit.blogit as m
 
@@ -235,6 +235,7 @@ def test_get_last_entries():
     le = _get_last_entries(DB)
     assert [e.id for e in le] == range(22, 12, -1)
 
+
 def test_render_archive():
 
     entries = [Entry.entry_from_db(
@@ -242,3 +243,13 @@ def test_render_archive():
         DB.posts.all()]
 
     render_archive(_sort_entries(entries, reversed=True)[ARCHIVE_SIZE:])
+    # TODO: assertions here
+
+
+def test_render_archive():
+    update_index(_get_last_entries(DB))
+    # TODO: assertions here
+
+
+def test_build():
+    build()