changeset 198:460a3062c5e6

create the database if it doesn't exist and drop it after test
author dirk
date Fri, 27 Jan 2012 02:35:46 +0100
parents e604c32f67aa
children 1220e62b63dd
files .settings/org.eclipse.core.resources.prefs tests/couchdb/ListDateTimeFieldTests.py
diffstat 2 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/.settings/org.eclipse.core.resources.prefs	Tue Jan 24 10:08:45 2012 +0100
+++ b/.settings/org.eclipse.core.resources.prefs	Fri Jan 27 02:35:46 2012 +0100
@@ -1,5 +1,6 @@
-#Sat Jul 24 02:23:01 CEST 2010
+#Fri Jan 27 02:15:29 CET 2012
 eclipse.preferences.version=1
+encoding/Feedworm_rc.py=utf-8
 encoding/Ui_AddFeed.py=utf-8
 encoding/Ui_FeedSettings.py=utf-8
 encoding/Ui_MainWindow.py=utf-8
--- a/tests/couchdb/ListDateTimeFieldTests.py	Tue Jan 24 10:08:45 2012 +0100
+++ b/tests/couchdb/ListDateTimeFieldTests.py	Fri Jan 27 02:35:46 2012 +0100
@@ -1,6 +1,7 @@
 
 from backend.couchdb.ListDateTimeField import ListDateTimeField
 from couchdb import Server
+from couchdb.http import ResourceNotFound
 from couchdb.mapping import Document, TextField
 from datetime import datetime
 import unittest
@@ -27,13 +28,13 @@
         result = ListDateTimeField()._to_python(value)
         self.assertEqual(value, result)
 
-    def __testRoundTrip(self):
+    def testRoundTrip(self):
         class Dummy(Document):
             title = TextField()
             date = ListDateTimeField()
 
         server = Server()
-        database = server["hello-world"]
+        database = self._createDatabase(server)
 
         dummy = Dummy()
         dummy.title = "created from unit test"
@@ -47,7 +48,16 @@
         self.assertFalse(dummy == dummy2)
         self.assertEqual(date, dummy2.date)
 
-        del database[dummy.id]
+        del server[database.name]
+
+    def _createDatabase(self, server):
+        databaseName = "feedworm-unit-test"
+        database = None
+        try:
+            database = server[databaseName]
+        except (ResourceNotFound):
+            database = server.create(databaseName)
+        return database
 
 if __name__ == "__main__":
     #import sys;sys.argv = ['', 'Test.testName']