annotate tests/couchdb/ListDateTimeFieldTests.py @ 181:1ab48428e2f9

sort the feed entries
author dirk
date Sat, 10 Sep 2011 09:05:14 +0200
parents f0afcd1c5656
children 460a3062c5e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
170
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
1
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
2 from backend.couchdb.ListDateTimeField import ListDateTimeField
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
3 from couchdb import Server
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
4 from couchdb.mapping import Document, TextField
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
5 from datetime import datetime
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
6 import unittest
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
7
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
8 class ListDateTimeFieldTests(unittest.TestCase):
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
9 def testToJsonValid(self):
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
10 value = datetime(2011, 9, 7, 15, 21, 0)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
11 result = ListDateTimeField()._to_json(value)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
12 self.assertEqual([2011, 9, 7, 15, 21, 0], result)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
13
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
14 def testToJsonInvalid(self):
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
15 value = "this is invalid input"
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
16 result = ListDateTimeField()._to_json(value)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
17 self.assertEqual(value, result)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
18
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
19 def testToPythonValid(self):
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
20 value = [2011, 9, 7, 15, 21, 0]
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
21 result = ListDateTimeField()._to_python(value)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
22 expected = datetime(2011, 9, 7, 15, 21, 0)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
23 self.assertEqual(expected, result)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
24
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
25 def testToPythonInvalid(self):
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
26 value = "this is invalid input"
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
27 result = ListDateTimeField()._to_python(value)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
28 self.assertEqual(value, result)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
29
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
30 def __testRoundTrip(self):
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
31 class Dummy(Document):
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
32 title = TextField()
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
33 date = ListDateTimeField()
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
34
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
35 server = Server()
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
36 database = server["hello-world"]
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
37
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
38 dummy = Dummy()
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
39 dummy.title = "created from unit test"
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
40 date = datetime.now().replace(microsecond=0)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
41 dummy.date = date
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
42 dummy.store(database)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
43 self.assertNotEqual(None, dummy.id)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
44
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
45 dummy2 = Dummy.load(database, dummy.id)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
46 self.assertNotEqual(None, dummy2)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
47 self.assertFalse(dummy == dummy2)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
48 self.assertEqual(date, dummy2.date)
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
49
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
50 del database[dummy.id]
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
51
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
52 if __name__ == "__main__":
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
53 #import sys;sys.argv = ['', 'Test.testName']
f0afcd1c5656 implement a couchdb mapping field that stores a datetime instance as a JSON array
dirk
parents:
diff changeset
54 unittest.main()