diff tests/couchdb/FeedTests.py @ 199:1220e62b63dd

implement a somewhat useful unit test for the Feed class
author dirk
date Fri, 27 Jan 2012 02:51:36 +0100
parents 7217b060b39c
children a122d42bfe72
line wrap: on
line diff
--- a/tests/couchdb/FeedTests.py	Fri Jan 27 02:35:46 2012 +0100
+++ b/tests/couchdb/FeedTests.py	Fri Jan 27 02:51:36 2012 +0100
@@ -1,19 +1,39 @@
 
 from backend.couchdb.Feed import Feed
-from backend.couchdb.CouchDbBackend import CouchDbBackend
+from couchdb.client import Server
 import unittest
+from couchdb.http import ResourceNotFound
+
+DATABASE_NAME = "feedworm-unit-tests"
 
-class Test(unittest.TestCase):
-    def setUp(self):
-        self.database = CouchDbBackend().database
+class FeedTests(unittest.TestCase):
+    def testCreateFeed(self):
+        title = "new feed"
+        url = "http://localhost"
+        newFeed = Feed.create(url, title)
+        newFeed.store(self.database)
+        feedId = newFeed.id
 
-    def _testAllFeeds(self):
-        allFeeds = Feed.all(self.database)
-        self.assertEqual(2, len(allFeeds))
+        feedFromDatabase = self.database[feedId]
+        self.assertNotEqual(None, feedFromDatabase)
+        self.assertEqual(title, feedFromDatabase["title"])
+        self.assertEqual(url, feedFromDatabase["rss_url"])
+
+    def __testListAllFeeds(self):
+        pass
 
-    def testFeedPropertyAccess(self):
-        feed = Feed.all(self.database)[0]
-        self.assertEquals("BBC", feed.title)
+    def setUp(self):
+        self._createDatabase()
+
+    def tearDown(self):
+        self.server.delete(self.database.name)
+
+    def _createDatabase(self):
+        self.server = Server()
+        try:
+            self.database = self.server[DATABASE_NAME]
+        except (ResourceNotFound):
+            self.database = self.server.create(DATABASE_NAME)
 
 if __name__ == "__main__":
     #import sys;sys.argv = ['', 'Test.testName']