web/test/unittest_controller.py
author Katia Saurfelt <katia.saurfelt@logilab.fr>
Tue, 19 May 2009 12:07:03 +0200
branchstable
changeset 1866 118c7528d08f
parent 1654 57b9fd2462b8
child 1977 606923dff11b
permissions -rw-r--r--
merge
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
1016
26387b836099 use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents: 0
diff changeset
     5
from datetime import datetime, date, time
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
from cubicweb.devtools import apptest
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
class BaseControllerTC(apptest.ControllerTC):
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    12
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    13
    def test_parse_datetime_ok(self):
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    14
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    15
                              datetime)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    16
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    17
                              date)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    18
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24 12:18', 'Datetime'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    19
                              datetime)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    20
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Datetime'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    21
                              datetime)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    22
        self.assertIsInstance(self.ctrl.parse_datetime('2006/06/24', 'Date'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    23
                              date)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    24
        self.assertIsInstance(self.ctrl.parse_datetime('12:18', 'Time'),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    25
                              time)
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    26
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    27
    def test_parse_datetime_ko(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
                          self.ctrl.parse_datetime, '2006/06/24 12:188', 'Datetime')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
                          self.ctrl.parse_datetime, '2006/06/240', 'Datetime')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
                          self.ctrl.parse_datetime, '2006/06/24 12:18', 'Date')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
                          self.ctrl.parse_datetime, '2006/24/06', 'Date')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
                          self.ctrl.parse_datetime, '2006/06/240', 'Date')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
        self.assertRaises(ValueError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
                          self.ctrl.parse_datetime, '12:188', 'Time')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    40
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    unittest_main()