Mercurial > hg > Feedworm
comparison tests/couchdb/ListDateTimeFieldTests.py @ 170:f0afcd1c5656
implement a couchdb mapping field that stores a datetime instance as a JSON array
author | dirk |
---|---|
date | Fri, 09 Sep 2011 16:22:44 +0200 |
parents | |
children | 460a3062c5e6 |
comparison
equal
deleted
inserted
replaced
169:91a24f499318 | 170:f0afcd1c5656 |
---|---|
1 | |
2 from backend.couchdb.ListDateTimeField import ListDateTimeField | |
3 from couchdb import Server | |
4 from couchdb.mapping import Document, TextField | |
5 from datetime import datetime | |
6 import unittest | |
7 | |
8 class ListDateTimeFieldTests(unittest.TestCase): | |
9 def testToJsonValid(self): | |
10 value = datetime(2011, 9, 7, 15, 21, 0) | |
11 result = ListDateTimeField()._to_json(value) | |
12 self.assertEqual([2011, 9, 7, 15, 21, 0], result) | |
13 | |
14 def testToJsonInvalid(self): | |
15 value = "this is invalid input" | |
16 result = ListDateTimeField()._to_json(value) | |
17 self.assertEqual(value, result) | |
18 | |
19 def testToPythonValid(self): | |
20 value = [2011, 9, 7, 15, 21, 0] | |
21 result = ListDateTimeField()._to_python(value) | |
22 expected = datetime(2011, 9, 7, 15, 21, 0) | |
23 self.assertEqual(expected, result) | |
24 | |
25 def testToPythonInvalid(self): | |
26 value = "this is invalid input" | |
27 result = ListDateTimeField()._to_python(value) | |
28 self.assertEqual(value, result) | |
29 | |
30 def __testRoundTrip(self): | |
31 class Dummy(Document): | |
32 title = TextField() | |
33 date = ListDateTimeField() | |
34 | |
35 server = Server() | |
36 database = server["hello-world"] | |
37 | |
38 dummy = Dummy() | |
39 dummy.title = "created from unit test" | |
40 date = datetime.now().replace(microsecond=0) | |
41 dummy.date = date | |
42 dummy.store(database) | |
43 self.assertNotEqual(None, dummy.id) | |
44 | |
45 dummy2 = Dummy.load(database, dummy.id) | |
46 self.assertNotEqual(None, dummy2) | |
47 self.assertFalse(dummy == dummy2) | |
48 self.assertEqual(date, dummy2.date) | |
49 | |
50 del database[dummy.id] | |
51 | |
52 if __name__ == "__main__": | |
53 #import sys;sys.argv = ['', 'Test.testName'] | |
54 unittest.main() |