author | Laurent Peuch <cortex@worlddomination.be> |
Tue, 17 Dec 2019 21:21:55 +0100 | |
changeset 12824 | bc623a3e44e9 |
parent 12315 | 599a144f5b25 |
permissions | -rw-r--r-- |
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 | 21 |
import os |
12267
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
22 |
from os import path |
11754
c7b2b809bf50
[test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11269
diff
changeset
|
23 |
from unittest import TestCase |
0 | 24 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
25 |
from cubicweb.devtools import ApptestConfiguration, fake |
0 | 26 |
|
11754
c7b2b809bf50
[test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11269
diff
changeset
|
27 |
|
0 | 28 |
class WebconfigTC(TestCase): |
11754
c7b2b809bf50
[test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11269
diff
changeset
|
29 |
|
0 | 30 |
def setUp(self): |
10071
4bc099f2a089
[test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents:
9677
diff
changeset
|
31 |
# 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
|
32 |
# ApptestConfiguration.__init__ |
11269
73ac69970047
[devtools] Simplify test configuration's init
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11057
diff
changeset
|
33 |
self.config = ApptestConfiguration('data', __file__) |
16
a70ece4d9d1a
fix tests in web/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
34 |
self.config._cubes = ['file'] |
0 | 35 |
self.config.load_configuration() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
16
diff
changeset
|
36 |
|
0 | 37 |
def test_nonregr_print_css_as_list(self): |
38 |
"""make sure PRINT_CSS *must* is a list""" |
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
self.assertTrue(isinstance(ie_css, list)) |
0 | 44 |
|
45 |
def test_locate_resource(self): |
|
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9326
diff
changeset
|
46 |
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
|
47 |
rname = self.config.uiprops['FILE_ICON'].replace(self.config.datadir_url, '') |
12315
599a144f5b25
[test] Update webconfig's tests accounting for cubicweb-file being now a package
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12268
diff
changeset
|
48 |
self.assertIn('cubicweb_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
|
49 |
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
|
50 |
|
4bc099f2a089
[test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents:
9677
diff
changeset
|
51 |
# 'shared' if tests under apycot |
4bc099f2a089
[test] make unittest_webconfig independant of CWD
David Douard <david.douard@logilab.fr>
parents:
9677
diff
changeset
|
52 |
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
|
53 |
'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
|
54 |
% cubicwebcsspath) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
16
diff
changeset
|
55 |
|
12267
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
56 |
def test_locate_all_files(self): |
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
57 |
wdocfiles = list(self.config.locate_all_files('toc.xml')) |
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
58 |
for fpath in wdocfiles: |
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
59 |
self.assertTrue(path.exists(fpath), fpath) |
12315
599a144f5b25
[test] Update webconfig's tests accounting for cubicweb-file being now a package
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12268
diff
changeset
|
60 |
for expected in [path.join('cubicweb_file', 'wdoc', 'toc.xml'), |
12268
d84bc85f7f70
[config] Avoid relying on shared_dir method when possible
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12267
diff
changeset
|
61 |
path.join('cubicweb', 'web', 'wdoc', 'toc.xml')]: |
12267
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
62 |
for fpath in wdocfiles: |
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
63 |
if fpath.endswith(expected): |
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
64 |
break |
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
65 |
else: |
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
66 |
raise AssertionError('%s not found in %s' % (expected, wdocfiles)) |
4ec56c0bcc5c
[test] Add a test for WebConfiguration.locate_all_files()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11754
diff
changeset
|
67 |
|
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
|
11754
c7b2b809bf50
[test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11269
diff
changeset
|
72 |
|
0 | 73 |
if __name__ == '__main__': |
11754
c7b2b809bf50
[test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11269
diff
changeset
|
74 |
import unittest |
c7b2b809bf50
[test] Use stdlib unittest in unittest_webconfig.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11269
diff
changeset
|
75 |
unittest.main() |