Mercurial > hg > Feedworm
comparison tests/couchdb/ListDateTimeFieldTests.py @ 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 | f0afcd1c5656 |
children | bb3c851b18b1 |
comparison
equal
deleted
inserted
replaced
197:e604c32f67aa | 198:460a3062c5e6 |
---|---|
1 | 1 |
2 from backend.couchdb.ListDateTimeField import ListDateTimeField | 2 from backend.couchdb.ListDateTimeField import ListDateTimeField |
3 from couchdb import Server | 3 from couchdb import Server |
4 from couchdb.http import ResourceNotFound | |
4 from couchdb.mapping import Document, TextField | 5 from couchdb.mapping import Document, TextField |
5 from datetime import datetime | 6 from datetime import datetime |
6 import unittest | 7 import unittest |
7 | 8 |
8 class ListDateTimeFieldTests(unittest.TestCase): | 9 class ListDateTimeFieldTests(unittest.TestCase): |
25 def testToPythonInvalid(self): | 26 def testToPythonInvalid(self): |
26 value = "this is invalid input" | 27 value = "this is invalid input" |
27 result = ListDateTimeField()._to_python(value) | 28 result = ListDateTimeField()._to_python(value) |
28 self.assertEqual(value, result) | 29 self.assertEqual(value, result) |
29 | 30 |
30 def __testRoundTrip(self): | 31 def testRoundTrip(self): |
31 class Dummy(Document): | 32 class Dummy(Document): |
32 title = TextField() | 33 title = TextField() |
33 date = ListDateTimeField() | 34 date = ListDateTimeField() |
34 | 35 |
35 server = Server() | 36 server = Server() |
36 database = server["hello-world"] | 37 database = self._createDatabase(server) |
37 | 38 |
38 dummy = Dummy() | 39 dummy = Dummy() |
39 dummy.title = "created from unit test" | 40 dummy.title = "created from unit test" |
40 date = datetime.now().replace(microsecond=0) | 41 date = datetime.now().replace(microsecond=0) |
41 dummy.date = date | 42 dummy.date = date |
45 dummy2 = Dummy.load(database, dummy.id) | 46 dummy2 = Dummy.load(database, dummy.id) |
46 self.assertNotEqual(None, dummy2) | 47 self.assertNotEqual(None, dummy2) |
47 self.assertFalse(dummy == dummy2) | 48 self.assertFalse(dummy == dummy2) |
48 self.assertEqual(date, dummy2.date) | 49 self.assertEqual(date, dummy2.date) |
49 | 50 |
50 del database[dummy.id] | 51 del server[database.name] |
52 | |
53 def _createDatabase(self, server): | |
54 databaseName = "feedworm-unit-test" | |
55 database = None | |
56 try: | |
57 database = server[databaseName] | |
58 except (ResourceNotFound): | |
59 database = server.create(databaseName) | |
60 return database | |
51 | 61 |
52 if __name__ == "__main__": | 62 if __name__ == "__main__": |
53 #import sys;sys.argv = ['', 'Test.testName'] | 63 #import sys;sys.argv = ['', 'Test.testName'] |
54 unittest.main() | 64 unittest.main() |