web/test/unittest_controller.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 28 May 2009 09:20:07 +0200
changeset 1977 606923dff11b
parent 1654 57b9fd2462b8
child 2773 b2530e3e0afb
permissions -rw-r--r--
big bunch of copyright / docstring update
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""cubicweb.web.controller unit tests
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1654
diff changeset
     3
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
1016
26387b836099 use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents: 0
diff changeset
     6
from datetime import datetime, date, time
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
from cubicweb.devtools import apptest
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
class BaseControllerTC(apptest.ControllerTC):
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    13
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    14
    def test_parse_datetime_ok(self):
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    15
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    16
                              datetime)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    17
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    18
                              date)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    19
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18', 'Datetime'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    20
                              datetime)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    21
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Datetime'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    22
                              datetime)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    23
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Date'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    24
                              date)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    25
        self.assertIsInstance(self.ctrl.parse_datetime('12:18', 'Time'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    26
                              time)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    27
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    28
    def test_parse_datetime_ko(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
                          self.ctrl.parse_datetime, '2006/06/24 12:188', 'Datetime')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
                          self.ctrl.parse_datetime, '2006/06/240', 'Datetime')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
                          self.ctrl.parse_datetime, '2006/06/24 12:18', 'Date')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
                          self.ctrl.parse_datetime, '2006/24/06', 'Date')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
                          self.ctrl.parse_datetime, '2006/06/240', 'Date')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
                          self.ctrl.parse_datetime, '12:188', 'Time')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    41
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    unittest_main()