Pārlūkot izejas kodu

fix how entries are sorted

Oz N Tiram 9 gadi atpakaļ
vecāks
revīzija
912f4dfeae
2 mainītis faili ar 11 papildinājumiem un 4 dzēšanām
  1. 3 0
      blogit/blogit.py
  2. 8 4
      tests/test_all.py

+ 3 - 0
blogit/blogit.py

@@ -258,8 +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())
 
+        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)

+ 8 - 4
tests/test_all.py

@@ -4,7 +4,8 @@ import pytest
 from tinydb import Query, where
 
 from blogit.blogit import CONFIG, find_new_posts_and_pages, DataBase
-from blogit.blogit import Entry, Tag
+from blogit.blogit import Entry, Tag, _sort_entries
+
 import blogit.blogit as m
 
 
@@ -185,7 +186,7 @@ def test_tag_post_ids():
 ---
 title: Blog post
 author: Famous author
-published: 2015-01-12
+published: 2015-01-{}
 tags: tag1, tag2
 public: yes
 chronological: yes
@@ -194,9 +195,9 @@ summary: This is a summry
 ---
 """
     with open(os.path.join(CONFIG['content_root'], 'e.md'), 'w') as f:
-        f.write(m)
+        f.write(m.format(9))
     with open(os.path.join(CONFIG['content_root'], 'f.md'), 'w') as f:
-        f.write(m)
+        f.write(m.format(11))
 
     e1 = Entry(os.path.join(CONFIG['content_root'], 'e.md'))
     e1.tags
@@ -208,6 +209,9 @@ summary: This is a summry
     e1.render()
     [t.render() for t in e1.tags]
 
+    l = _sort_entries([e2, e1])
+    assert l == [e2, e1]
+
 
 def test_tag_render():