web/test/unittest_controller.py
author sylvain.thenault@logilab.fr
Thu, 23 Apr 2009 16:08:40 +0200
branchtls-sprint
changeset 1447 a1ca676294f0
parent 1016 26387b836099
child 1654 57b9fd2462b8
permissions -rw-r--r--
don't use a singleton rest parser which may leads to concurrency bugs

"""cubicweb.web.controller unit tests

"""

from datetime import datetime, date, time

from logilab.common.testlib import unittest_main

from cubicweb.devtools import apptest

class BaseControllerTC(apptest.ControllerTC):
    def test_parse_datetime(self):
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18'), datetime)
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24'), datetime)
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18', 'Datetime'), datetime)
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Datetime'), datetime)
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Date'), date)
        self.assertIsInstance(self.ctrl.parse_datetime('12:18', 'Time'), time)
        self.assertRaises(ValueError,
                          self.ctrl.parse_datetime, '2006/06/24 12:188', 'Datetime')
        self.assertRaises(ValueError,
                          self.ctrl.parse_datetime, '2006/06/240', 'Datetime')
        self.assertRaises(ValueError,
                          self.ctrl.parse_datetime, '2006/06/24 12:18', 'Date')
        self.assertRaises(ValueError,
                          self.ctrl.parse_datetime, '2006/24/06', 'Date')
        self.assertRaises(ValueError,
                          self.ctrl.parse_datetime, '2006/06/240', 'Date')
        self.assertRaises(ValueError,
                          self.ctrl.parse_datetime, '12:188', 'Time')
        
if __name__ == '__main__':
    unittest_main()