當前位置: 首頁>>代碼示例>>Python>>正文


Python Feed.save方法代碼示例

本文整理匯總了Python中feed.Feed.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Feed.save方法的具體用法?Python Feed.save怎麽用?Python Feed.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在feed.Feed的用法示例。


在下文中一共展示了Feed.save方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: FeedTest

# 需要導入模塊: from feed import Feed [as 別名]
# 或者: from feed.Feed import save [as 別名]
class FeedTest(unittest2.TestCase):
    def setUp(self):
        import time
        self.feed = Feed()
        self.savefeed = Feed()
        self.savefeed.title = "MyTitle"
        self.savefeed.author = "MyAuthor"
        self.savefeed.url = "MyUrl"
        self.savefeed.homepage = "MyHomepage"
        self.savefeed.updated = time.gmtime(time.time())
        self.savefeed.deleted_entry_ids = ["123", "456"]

    def testLoad(self):
        import time
        from base64 import b64encode
        updated = time.gmtime(time.time())
        store = StoreMock()
        store.setValue("Title", "TestTitle")
        store.setValue("Url", "TestUrl")
        store.setValue("Homepage", "Homepage")
        store.setValue("Author", "TestAuthor")
        store.setValue("Updated", updated)
        store.setValue("DeletedEntryIds", ["789","101112"])
        store.beginGroup("Entry_%s" % b64encode("Id1"))
        store.setValue("Title", "T1")
        store.setValue("Updated", updated)
        store.setValue("Author", "Author1")
        store.setValue("Url", "Url1")
        store.setValue("Id", "Id1")
        store.setValue("Content", "Content1")
        store.setValue("Read", True)
        store.endGroup()
        store.beginGroup("Entry_%s" % b64encode("Id2"))
        store.setValue("Title", "T2")
        store.setValue("Updated", updated)
        store.setValue("Author", "Author2")
        store.setValue("Url", "Url2")
        store.setValue("Id", "Id2")
        store.setValue("Content", "Content2")
        store.endGroup()
        self.savefeed.load(store)
        self.assertEqual(self.savefeed.title, "TestTitle")
        self.assertEqual(self.savefeed.updated, updated)
        self.assertEqual(self.savefeed.url, "TestUrl")
        self.assertEqual(self.savefeed.homepage, "Homepage")
        self.assertEqual(self.savefeed.author, "TestAuthor")
        self.assertEqual(self.savefeed.unread, 1)
        self.assertEqual(len(self.savefeed.deleted_entry_ids), 2)
        self.assertEqual(self.savefeed.deleted_entry_ids, ["789","101112"])
        self.assertEqual(len(self.savefeed.entries), 2)

    def testSave(self):
        entry = Entry()
        store = StoreMock()
        self.savefeed.entries.append(entry)
        self.savefeed.save(store)
        self.assertEqual(len(store.childGroups()), 1)
        self.assertEqual(self.savefeed.title, store.value("Title"))
        self.assertEqual(self.savefeed.author, store.value("Author"))
        self.assertEqual(self.savefeed.url, store.value("Url"))
        self.assertEqual(self.savefeed.updated, store.value("Updated"))
        self.assertEqual(self.savefeed.deleted_entry_ids, store.value("DeletedEntryIds", []))

    def testTitle(self):
        self.assertIsNone(self.feed.title)
        self.feed.title = "test"
        self.assertEqual(self.feed.title, "test")

    def testAuthor(self):
        self.assertIsNone(self.feed.author)
        self.feed.author = "test"
        self.assertEqual(self.feed.author, "test")

    def testHomepage(self):
        self.assertIsNone(self.feed.homepage)
        self.feed.homepage = "test"
        self.assertEqual(self.feed.homepage, "test")

    def testFeedUrl(self):
        self.assertIsNone(self.feed.url)
        self.feed.url = "test"
        self.assertEqual(self.feed.url, "test")

    def testUpdated(self):
        import time
        self.assertEqual(self.feed.updated, None)
        updated = time.gmtime(time.time())
        self.feed.updated = updated
        self.assertEqual(self.feed.updated, updated)

    def testAdd(self):
        self.assertEqual(len(self.feed.entries), 0)
        self.feed.entries.append(Entry())
        self.assertEqual(len(self.feed.entries), 1)

    def testRemove(self):
        self.assertEqual(len(self.feed.entries), 0)
        self.assertEqual(len(self.feed.deleted_entry_ids), 0)
        feed = Entry()
        self.feed.entries.append(feed)
#.........這裏部分代碼省略.........
開發者ID:apaku,項目名稱:slimfeed,代碼行數:103,代碼來源:test_feed.py


注:本文中的feed.Feed.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。