7 from logilab.common.testlib import unittest_main |
7 from logilab.common.testlib import unittest_main |
8 |
8 |
9 from cubicweb.devtools import apptest |
9 from cubicweb.devtools import apptest |
10 |
10 |
11 class BaseControllerTC(apptest.ControllerTC): |
11 class BaseControllerTC(apptest.ControllerTC): |
12 def test_parse_datetime(self): |
12 |
13 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18'), datetime) |
13 def test_parse_datetime_ok(self): |
14 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24'), datetime) |
14 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18'), |
15 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18', 'Datetime'), datetime) |
15 datetime) |
16 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Datetime'), datetime) |
16 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24'), |
17 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Date'), date) |
17 date) |
18 self.assertIsInstance(self.ctrl.parse_datetime('12:18', 'Time'), time) |
18 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18', 'Datetime'), |
|
19 datetime) |
|
20 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Datetime'), |
|
21 datetime) |
|
22 self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Date'), |
|
23 date) |
|
24 self.assertIsInstance(self.ctrl.parse_datetime('12:18', 'Time'), |
|
25 time) |
|
26 |
|
27 def test_parse_datetime_ko(self): |
19 self.assertRaises(ValueError, |
28 self.assertRaises(ValueError, |
20 self.ctrl.parse_datetime, '2006/06/24 12:188', 'Datetime') |
29 self.ctrl.parse_datetime, '2006/06/24 12:188', 'Datetime') |
21 self.assertRaises(ValueError, |
30 self.assertRaises(ValueError, |
22 self.ctrl.parse_datetime, '2006/06/240', 'Datetime') |
31 self.ctrl.parse_datetime, '2006/06/240', 'Datetime') |
23 self.assertRaises(ValueError, |
32 self.assertRaises(ValueError, |
26 self.ctrl.parse_datetime, '2006/24/06', 'Date') |
35 self.ctrl.parse_datetime, '2006/24/06', 'Date') |
27 self.assertRaises(ValueError, |
36 self.assertRaises(ValueError, |
28 self.ctrl.parse_datetime, '2006/06/240', 'Date') |
37 self.ctrl.parse_datetime, '2006/06/240', 'Date') |
29 self.assertRaises(ValueError, |
38 self.assertRaises(ValueError, |
30 self.ctrl.parse_datetime, '12:188', 'Time') |
39 self.ctrl.parse_datetime, '12:188', 'Time') |
31 |
40 |
32 if __name__ == '__main__': |
41 if __name__ == '__main__': |
33 unittest_main() |
42 unittest_main() |