Mercurial > hg > Feedworm
view tests/couchdb/ListDateTimeFieldTests.py @ 232:18865de3a87d
all __init__.py files must contain at least an empty line to avoid eric's style checker choking
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 25 Sep 2014 17:10:40 +0200 |
parents | bb3c851b18b1 |
children | 7c719c4f5655 |
line wrap: on
line source
# -*- coding: utf-8 -*- 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 class ListDateTimeFieldTests(unittest.TestCase): def testToJsonValid(self): value = datetime(2011, 9, 7, 15, 21, 0) result = ListDateTimeField()._to_json(value) self.assertEqual([2011, 9, 7, 15, 21, 0], result) def testToJsonInvalid(self): value = "this is invalid input" result = ListDateTimeField()._to_json(value) self.assertEqual(value, result) def testToPythonValid(self): value = [2011, 9, 7, 15, 21, 0] result = ListDateTimeField()._to_python(value) expected = datetime(2011, 9, 7, 15, 21, 0) self.assertEqual(expected, result) def testToPythonInvalid(self): value = "this is invalid input" result = ListDateTimeField()._to_python(value) self.assertEqual(value, result) def testRoundTrip(self): class Dummy(Document): title = TextField() date = ListDateTimeField() server = Server() database = self._createDatabase(server) dummy = Dummy() dummy.title = "created from unit test" date = datetime.now().replace(microsecond=0) dummy.date = date dummy.store(database) self.assertNotEqual(None, dummy.id) dummy2 = Dummy.load(database, dummy.id) self.assertNotEqual(None, dummy2) self.assertFalse(dummy == dummy2) self.assertEqual(date, dummy2.date) 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'] unittest.main()