本文整理匯總了Python中collector.Collector.update_item_tag方法的典型用法代碼示例。如果您正苦於以下問題:Python Collector.update_item_tag方法的具體用法?Python Collector.update_item_tag怎麽用?Python Collector.update_item_tag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類collector.Collector
的用法示例。
在下文中一共展示了Collector.update_item_tag方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestCollector
# 需要導入模塊: from collector import Collector [as 別名]
# 或者: from collector.Collector import update_item_tag [as 別名]
class TestCollector(unittest.TestCase):
""" Tests the Collector class.
"""
def setUp(self):
self.co = Collector()
self.feed_info = Manager.get_feeds_info()
def tearDown(self):
rm_data_dir()
def test_add_feed(self):
""" Tests add_feed.
Add feeds with "add_feed":
1- Test if the feeds has been added.
2- Test if the feeds exists in the database.
Try adding a feed already added:
3- Test if the feed has not been added.
"""
for name, url, tag, _ in self.feed_info:
feed = self.co.add_feed(name, url, tag)
self.assertIsNotNone(feed) # 1
self.assertTrue(self.co.has_feed(name)) # 2
name, url, tag = self.feed_info[0][:3]
feed = self.co.add_feed(name, url, tag)
self.assertIsNone(feed) # 3
def test_update_feed(self):
""" Tests update_feed.
Add feeds.
Try updating feed with "update_feed":
1- Test if the feed doesn't need to be updated.
#TODO
Find a way to update a feed in the test.
"""
for name, url, tag, _ in self.feed_info:
self.co.add_feed(name, url, tag)
updated = self.co.update_feed(name)
self.assertFalse(updated) # 1
def test_rm_feed(self):
""" Tests rm_feed.
Add feeds:
1- Test if the feeds exists first.
Remove feeds with "rm_feed".
2- Test if the feeds has been removed.
"""
for name, url, tag, _ in self.feed_info:
self.co.add_feed(name, url, tag)
self.assertTrue(self.co.has_feed(name)) # 1
self.co.rm_feed(name)
self.assertFalse(self.co.has_feed(name)) # 2
def test_update_item_tag(self):
""" Tests update_item_tag.
Add a feed:
1- Test if an item has not the tag attribute.
Add a category with "update_item_tag".
2- Test if the item updated is the same with the id.
3- Test if the item updated has the tag attribute.
4- Test if the item updated has the correct category.
"""
category = "SPORT"
name, url, tag = self.feed_info[0][:3]
feed = self.co.add_feed(name, url, tag)
item_id, item = self.co.get_items(name).next()
self.assertFalse(hasattr(item, "tag")) # 1
self.co.update_item_tag(feed.item_db_filename, item_id, category)
item_id_updated, item_updated = self.co.get_items(name).next()
self.assertEquals(item_id, item_id_updated) # 2
self.assertTrue(hasattr(item_updated, "tag")) # 3
self.assertEquals(item_updated.tag, category) # 4
def test_has_feed(self):
""" Tests has_feed.
Verify with "has_feed" if the feed exists.
1- The feed doesn't exists.
Add a feed.
#.........這裏部分代碼省略.........