Mercurial > hg > Feedworm
changeset 136:7217b060b39c
implement a Feed class that can be used to query feed and that wraps view results
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Tue, 23 Aug 2011 04:15:46 +0200 |
parents | b2ef673607e3 |
children | 5b131f82057d |
files | backend/couchdb/Feed.py tests/couchdb/FeedTests.py tests/couchdb/__init__.py |
diffstat | 2 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend/couchdb/Feed.py Tue Aug 23 04:15:46 2011 +0200 @@ -0,0 +1,12 @@ + +class Feed(object): + @staticmethod + def all(database): + viewResults = database.view("feedtest/feeds") + return [Feed(row) for row in viewResults] + + def __init__(self, row): + self.row = row + + def __getattr__(self, key): + return self.row.value[key]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/couchdb/FeedTests.py Tue Aug 23 04:15:46 2011 +0200 @@ -0,0 +1,20 @@ + +from backend.couchdb.Feed import Feed +from backend.couchdb.CouchDbBackend import CouchDbBackend +import unittest + +class Test(unittest.TestCase): + def setUp(self): + self.database = CouchDbBackend().database + + def _testAllFeeds(self): + allFeeds = Feed.all(self.database) + self.assertEqual(2, len(allFeeds)) + + def testFeedPropertyAccess(self): + feed = Feed.all(self.database)[0] + self.assertEquals("BBC", feed.title) + +if __name__ == "__main__": + #import sys;sys.argv = ['', 'Test.testName'] + unittest.main() \ No newline at end of file