cubicweb/web/test/unittest_controller.py
author Laura Médioni <laura.medioni@logilab.fr>, Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 03 Nov 2016 15:00:01 +0100
changeset 11794 d8830e2bd2e0
parent 11057 0b59724cb3f2
permissions -rw-r--r--
[req,web] Make it possible to handle page language from URL prefix Adding a short language prefix to URL (like "/en" or "/fr") changes the language the pages are displayed in. This prefix is kept during navigation. This way it is not necessary to do language negotiation, nor to use user preferences to determine which language to apply. This behavior is controlled through a new configuration option "language-mode", which replaces "language-negociation" option and which values may be "http-negotiation", "url-prefix" or "" (to disable language setting and force using "ui.language" property). Migration from previous option is not handled because I could not manage to have it working (users will get prompted with the configuration file diff anyways). Add some tests checking various scenarios. Closes #15743487
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()