cubicweb/web/test/unittest_controller.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Sat, 16 Jan 2016 13:48:51 +0100
changeset 11057 0b59724cb3f2
parent 9644 web/test/unittest_controller.py@2683c9f9a6b7
permissions -rw-r--r--
Reorganize source tree to have a "cubicweb" top-level package Basically: mkdir cubicweb hg mv *.py -X setup.py cubicweb hg mv dataimport devtools entities etwist ext hooks i18n misc schemas server skeleton sobjects test web wsgi cubicweb Other changes: * adjust path to cubicweb-ctl in devtools tests * update setup.py to avoid importing __pkginfo__ (exec it instead), replace os.path.walk by os.walk and prepend `modname` here and there * update tox.ini to account for new test locations * update doc/conf.py so that it still finds __pkginfo__.py and CWDIR in doc/Makefile
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
"""cubicweb.web.controller unit tests
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
1016
26387b836099 use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    22
from datetime import datetime, date, time
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    26
from cubicweb.devtools import testlib
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    28
class BaseControllerTC(testlib.CubicWebTC):
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    29
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    30
    def test_parse_datetime_ok(self):
9644
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    31
        with self.admin_access.web_request() as req:
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    32
            ctrl = self.vreg['controllers'].select('view', req)
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    33
            pd = ctrl._cw.parse_datetime
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    34
            self.assertIsInstance(pd('2006/06/24 12:18'), datetime)
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    35
            self.assertIsInstance(pd('2006/06/24'), date)
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    36
            self.assertIsInstance(pd('2006/06/24 12:18', 'Datetime'), datetime)
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    37
            self.assertIsInstance(pd('2006/06/24', 'Datetime'), datetime)
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    38
            self.assertIsInstance(pd('2006/06/24', 'Date'), date)
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    39
            self.assertIsInstance(pd('12:18', 'Time'), time)
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    40
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    41
    def test_parse_datetime_ko(self):
9644
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    42
        with self.admin_access.web_request() as req:
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    43
            ctrl = self.vreg['controllers'].select('view', req)
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    44
            pd = ctrl._cw.parse_datetime
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    45
            self.assertRaises(ValueError,
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    46
                              pd, '2006/06/24 12:188', 'Datetime')
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    47
            self.assertRaises(ValueError,
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    48
                              pd, '2006/06/240', 'Datetime')
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    49
            self.assertRaises(ValueError,
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    50
                              pd, '2006/06/24 12:18', 'Date')
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    51
            self.assertRaises(ValueError,
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    52
                              pd, '2006/24/06', 'Date')
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    53
            self.assertRaises(ValueError,
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    54
                              pd, '2006/06/240', 'Date')
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    55
            self.assertRaises(ValueError,
2683c9f9a6b7 [web/test] move unittest_controller to RepoAccess test API
Julien Cristau <julien.cristau@logilab.fr>
parents: 5424
diff changeset
    56
                              pd, '12:188', 'Time')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    57
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    unittest_main()