فهرست منبع

add more testing for Tag

Oz N Tiram 9 سال پیش
والد
کامیت
54df115f91
2فایلهای تغییر یافته به همراه19 افزوده شده و 7 حذف شده
  1. 7 6
      blogit/blogit.py
  2. 12 1
      tests/test_all.py

+ 7 - 6
blogit/blogit.py

@@ -92,12 +92,13 @@ class Tag(object):
             raise ValueError("post_ids must be of type list")
         Tags = Query()
         tag = self.table.get(Tags.name == self.name)
-        if not tag:  # pragma: no coverage
-            raise ValueError("Tag %s not found" % self.name)
-        if tag:
-            new = set(post_ids) - set(tag['post_ids'])
-            tag['post_ids'].extend(list(new))
-            self.table.update({'post_ids': tag['post_ids']}, eids=[tag.eid])
+
+        # if not tag:  # pragma: no coverage
+        #     raise ValueError("Tag %s not found" % self.name)
+        # else:
+        new = set(post_ids) - set(tag['post_ids'])
+        tag['post_ids'].extend(list(new))
+        self.table.update({'post_ids': tag['post_ids']}, eids=[tag.eid])
 
     @property
     def entries(self):

+ 12 - 1
tests/test_all.py

@@ -4,7 +4,7 @@ import pytest
 
 from blogit.blogit import CONFIG, find_new_posts_and_pages, DataBase
 from blogit.blogit import Entry, Tag
-
+from tinydb import Query
 CONFIG['content_root'] = 'test_root'
 
 DB = DataBase(os.path.join(CONFIG['content_root'], 'blogit.db'))
@@ -125,5 +125,16 @@ def test_slug():
     t = Tag('foo:;bar,.,baz')
     assert t.slug == "foo-bar-baz"
 
+def test_tag_posts():
+
+    example = Tag('example')
+
+    example.posts = [1,2,3]
+    assert [1,2,3] == example.posts
+
+    Filter = Query()
+    t = DB.tags.get(Filter.post_ids == [1, 2, 3])
+    assert t['post_ids'] == [1, 2, 3]
+
 os.unlink(DB._db._storage._handle.name)