web/test/unittest_controller.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 """cubicweb.web.controller unit tests
       
    19 
       
    20 """
       
    21 
       
    22 from datetime import datetime, date, time
       
    23 
       
    24 from logilab.common.testlib import unittest_main
       
    25 
       
    26 from cubicweb.devtools import testlib
       
    27 
       
    28 class BaseControllerTC(testlib.CubicWebTC):
       
    29 
       
    30     def test_parse_datetime_ok(self):
       
    31         with self.admin_access.web_request() as req:
       
    32             ctrl = self.vreg['controllers'].select('view', req)
       
    33             pd = ctrl._cw.parse_datetime
       
    34             self.assertIsInstance(pd('2006/06/24 12:18'), datetime)
       
    35             self.assertIsInstance(pd('2006/06/24'), date)
       
    36             self.assertIsInstance(pd('2006/06/24 12:18', 'Datetime'), datetime)
       
    37             self.assertIsInstance(pd('2006/06/24', 'Datetime'), datetime)
       
    38             self.assertIsInstance(pd('2006/06/24', 'Date'), date)
       
    39             self.assertIsInstance(pd('12:18', 'Time'), time)
       
    40 
       
    41     def test_parse_datetime_ko(self):
       
    42         with self.admin_access.web_request() as req:
       
    43             ctrl = self.vreg['controllers'].select('view', req)
       
    44             pd = ctrl._cw.parse_datetime
       
    45             self.assertRaises(ValueError,
       
    46                               pd, '2006/06/24 12:188', 'Datetime')
       
    47             self.assertRaises(ValueError,
       
    48                               pd, '2006/06/240', 'Datetime')
       
    49             self.assertRaises(ValueError,
       
    50                               pd, '2006/06/24 12:18', 'Date')
       
    51             self.assertRaises(ValueError,
       
    52                               pd, '2006/24/06', 'Date')
       
    53             self.assertRaises(ValueError,
       
    54                               pd, '2006/06/240', 'Date')
       
    55             self.assertRaises(ValueError,
       
    56                               pd, '12:188', 'Time')
       
    57 
       
    58 if __name__ == '__main__':
       
    59     unittest_main()