cubicweb/web/test/unittest_webconfig.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 11754 c7b2b809bf50
child 12267 4ec56c0bcc5c
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:
9326
9d145b4c4e53 [web] make sign_text unicode aware, avoid crash with non-ascii chars. Closes #3289774
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
     1
# -*- coding: utf-8 -*-
9d145b4c4e53 [web] make sign_text unicode aware, avoid crash with non-ascii chars. Closes #3289774
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
     2
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     3
# 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: 4252
diff changeset
     4
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     5
# 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: 4252
diff changeset
     6
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     7
# 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: 4252
diff changeset
     8
# 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: 4252
diff changeset
     9
# 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: 4252
diff changeset
    10
# 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: 4252
diff changeset
    11
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    12
# 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: 4252
diff changeset
    13
# 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: 4252
diff changeset
    14
# 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: 4252
diff changeset
    15
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    16
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    17
# 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: 4252
diff changeset
    18
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
9326
9d145b4c4e53 [web] make sign_text unicode aware, avoid crash with non-ascii chars. Closes #3289774
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
    19
"""cubicweb.web.webconfig unit tests"""
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1802
diff changeset
    20
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
import os
11754
c7b2b809bf50 [test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    22
from unittest import TestCase
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    24
from cubicweb.devtools import ApptestConfiguration, fake
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
11754
c7b2b809bf50 [test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    26
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
class WebconfigTC(TestCase):
11754
c7b2b809bf50 [test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    28
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
    def setUp(self):
10071
4bc099f2a089 [test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents: 9677
diff changeset
    30
        # need explicit None if dirname(__file__) is empty, see
4bc099f2a089 [test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents: 9677
diff changeset
    31
        # ApptestConfiguration.__init__
11269
73ac69970047 [devtools] Simplify test configuration's init
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
    32
        self.config = ApptestConfiguration('data', __file__)
16
a70ece4d9d1a fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    33
        self.config._cubes = ['file']
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
        self.config.load_configuration()
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 16
diff changeset
    35
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
    def test_nonregr_print_css_as_list(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        """make sure PRINT_CSS *must* is a list"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
        config = self.config
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    39
        print_css = config.uiprops['STYLESHEETS_PRINT']
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5907
diff changeset
    40
        self.assertTrue(isinstance(print_css, list))
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    41
        ie_css = config.uiprops['STYLESHEETS_IE']
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5907
diff changeset
    42
        self.assertTrue(isinstance(ie_css, list))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
    def test_locate_resource(self):
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9326
diff changeset
    45
        self.assertIn('FILE_ICON', self.config.uiprops)
5444
f7fdb5dd82f6 [webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    46
        rname = self.config.uiprops['FILE_ICON'].replace(self.config.datadir_url, '')
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9326
diff changeset
    47
        self.assertIn('file', self.config.locate_resource(rname)[0].split(os.sep))
5907
5eba1248e12b [web config] fix old css compat code: we have to modify locate_resource prototype so it return (potentially hacked) file name as well. Should only impact the file cube which has to be released anyway.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5444
diff changeset
    48
        cubicwebcsspath = self.config.locate_resource('cubicweb.css')[0].split(os.sep)
10071
4bc099f2a089 [test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents: 9677
diff changeset
    49
4bc099f2a089 [test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents: 9677
diff changeset
    50
        # 'shared' if tests under apycot
4bc099f2a089 [test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents: 9677
diff changeset
    51
        self.assertTrue('web' in cubicwebcsspath or 'shared' in cubicwebcsspath,
4bc099f2a089 [test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents: 9677
diff changeset
    52
                        'neither "web" nor "shared" found in cubicwebcsspath (%s)'
4bc099f2a089 [test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents: 9677
diff changeset
    53
                        % cubicwebcsspath)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 16
diff changeset
    54
9326
9d145b4c4e53 [web] make sign_text unicode aware, avoid crash with non-ascii chars. Closes #3289774
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
    55
    def test_sign_text(self):
9d145b4c4e53 [web] make sign_text unicode aware, avoid crash with non-ascii chars. Closes #3289774
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
    56
        signature = self.config.sign_text(u'hôp')
9d145b4c4e53 [web] make sign_text unicode aware, avoid crash with non-ascii chars. Closes #3289774
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
    57
        self.assertTrue(self.config.check_text_sign(u'hôp', signature))
9d145b4c4e53 [web] make sign_text unicode aware, avoid crash with non-ascii chars. Closes #3289774
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
    58
11754
c7b2b809bf50 [test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    59
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
if __name__ == '__main__':
11754
c7b2b809bf50 [test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    61
    import unittest
c7b2b809bf50 [test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    62
    unittest.main()