Mercurial > hg > Feedworm
comparison 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 |
comparison
equal
deleted
inserted
replaced
198:460a3062c5e6 | 199:1220e62b63dd |
---|---|
1 | 1 |
2 from backend.couchdb.Feed import Feed | 2 from backend.couchdb.Feed import Feed |
3 from backend.couchdb.CouchDbBackend import CouchDbBackend | 3 from couchdb.client import Server |
4 import unittest | 4 import unittest |
5 from couchdb.http import ResourceNotFound | |
5 | 6 |
6 class Test(unittest.TestCase): | 7 DATABASE_NAME = "feedworm-unit-tests" |
8 | |
9 class FeedTests(unittest.TestCase): | |
10 def testCreateFeed(self): | |
11 title = "new feed" | |
12 url = "http://localhost" | |
13 newFeed = Feed.create(url, title) | |
14 newFeed.store(self.database) | |
15 feedId = newFeed.id | |
16 | |
17 feedFromDatabase = self.database[feedId] | |
18 self.assertNotEqual(None, feedFromDatabase) | |
19 self.assertEqual(title, feedFromDatabase["title"]) | |
20 self.assertEqual(url, feedFromDatabase["rss_url"]) | |
21 | |
22 def __testListAllFeeds(self): | |
23 pass | |
24 | |
7 def setUp(self): | 25 def setUp(self): |
8 self.database = CouchDbBackend().database | 26 self._createDatabase() |
9 | 27 |
10 def _testAllFeeds(self): | 28 def tearDown(self): |
11 allFeeds = Feed.all(self.database) | 29 self.server.delete(self.database.name) |
12 self.assertEqual(2, len(allFeeds)) | |
13 | 30 |
14 def testFeedPropertyAccess(self): | 31 def _createDatabase(self): |
15 feed = Feed.all(self.database)[0] | 32 self.server = Server() |
16 self.assertEquals("BBC", feed.title) | 33 try: |
34 self.database = self.server[DATABASE_NAME] | |
35 except (ResourceNotFound): | |
36 self.database = self.server.create(DATABASE_NAME) | |
17 | 37 |
18 if __name__ == "__main__": | 38 if __name__ == "__main__": |
19 #import sys;sys.argv = ['', 'Test.testName'] | 39 #import sys;sys.argv = ['', 'Test.testName'] |
20 unittest.main() | 40 unittest.main() |