cubicweb/test/unittest_utils.py
author Laurent Wouters <lwouters@cenotelie.fr>
Tue, 24 Apr 2018 11:22:17 +0200
changeset 12303 198cb7d7b4ac
parent 12032 c16c1805e973
child 12305 9fd7d496e27e
permissions -rw-r--r--
[utils] Fixed issue in clearing QueryCache When trying to add an item in a full QueryCache, the cache tries to make room. It tries to list and remove non-permanent items with a transient counter (number of times it has been requested). However, there is a pathological case where items could be non-permanent but still not have a transient counter because they were added, but never requested. In some cases, the full cache could be flushed, including the permanent items. This changeset attempts to fix this issue by only dropping the non-permanent items that did not hav a transient counter.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11917
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
     1
# copyright 2003-2017 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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5726
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    18
"""unit tests for module cubicweb.utils"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
11715
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
    20
import base64
11078
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    21
import datetime
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
    22
import decimal
11078
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    23
import doctest
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
    24
import re
11715
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
    25
try:
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
    26
    from unittest2 import TestCase
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
    27
except ImportError:  # Python3
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
    28
    from unittest import TestCase
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
    29
11917
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
    30
from six import PY2
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    31
from six.moves import range
7569
02c338197322 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7277 7568
diff changeset
    32
11917
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
    33
from cubicweb import Binary, Unauthorized
7277
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
    34
from cubicweb.devtools.testlib import CubicWebTC
10933
830f1ea52789 [utils] Drop now-unused SizeConstrainedList
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10609
diff changeset
    35
from cubicweb.utils import (make_uid, UStringIO, RepeatList, HTMLHead,
12032
c16c1805e973 [cleanup] Drop no more used parse_repo_uri function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11917
diff changeset
    36
                            QueryCache)
5726
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    37
from cubicweb.entity import Entity
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
4694
c19366a12281 simplejson may not be available with python 2.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    39
try:
5389
809d3b5b3d31 [python2.6] careful: json-py provides a json package. We don't want that.
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5377
diff changeset
    40
    from cubicweb.utils import CubicWebJsonEncoder, json
4694
c19366a12281 simplejson may not be available with python 2.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    41
except ImportError:
5377
84d14ddfae13 [python2.6] prefer python2.6's builtin json module over simplejson
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5077
diff changeset
    42
    json = None
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
11917
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
    44
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
class MakeUidTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
    def test_1(self):
6415
b0b0f097a72d cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6366
diff changeset
    47
        self.assertNotEqual(make_uid('xyz'), make_uid('abcd'))
b0b0f097a72d cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6366
diff changeset
    48
        self.assertNotEqual(make_uid('xyz'), make_uid('xyz'))
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 720
diff changeset
    49
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
    def test_2(self):
3146
cfc4344023f2 have a better make_uid function, esp. useful for win32 as collisions are frequents with the old one
Aurelien Campeas
parents: 2635
diff changeset
    51
        d = set()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        while len(d)<10000:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
            uid = make_uid('xyz')
3146
cfc4344023f2 have a better make_uid function, esp. useful for win32 as collisions are frequents with the old one
Aurelien Campeas
parents: 2635
diff changeset
    54
            if uid in d:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
                self.fail(len(d))
4694
c19366a12281 simplejson may not be available with python 2.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    56
            if re.match('\d', uid):
c19366a12281 simplejson may not be available with python 2.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    57
                self.fail('make_uid must not return something begining with '
c19366a12281 simplejson may not be available with python 2.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    58
                          'some numeric character, got %s' % uid)
3146
cfc4344023f2 have a better make_uid function, esp. useful for win32 as collisions are frequents with the old one
Aurelien Campeas
parents: 2635
diff changeset
    59
            d.add(uid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7954
diff changeset
    61
7954
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    62
class TestQueryCache(TestCase):
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    63
    def test_querycache(self):
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    64
        c = QueryCache(ceiling=20)
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    65
        # write only
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    66
        for x in range(10):
7954
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    67
            c[x] = x
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    68
        self.assertEqual(c._usage_report(),
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    69
                         {'transientcount': 0,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    70
                          'itemcount': 10,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    71
                          'permanentcount': 0})
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    72
        c = QueryCache(ceiling=10)
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    73
        # we should also get a warning
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    74
        for x in range(20):
7954
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    75
            c[x] = x
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    76
        self.assertEqual(c._usage_report(),
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    77
                         {'transientcount': 0,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    78
                          'itemcount': 10,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    79
                          'permanentcount': 0})
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    80
        # write + reads
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    81
        c = QueryCache(ceiling=20)
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    82
        for n in range(4):
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    83
            for x in range(10):
7954
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    84
                c[x] = x
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    85
                c[x]
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    86
        self.assertEqual(c._usage_report(),
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    87
                         {'transientcount': 10,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    88
                          'itemcount': 10,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    89
                          'permanentcount': 0})
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    90
        c = QueryCache(ceiling=20)
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    91
        for n in range(17):
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
    92
            for x in range(10):
7954
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    93
                c[x] = x
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    94
                c[x]
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    95
        self.assertEqual(c._usage_report(),
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    96
                         {'transientcount': 0,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    97
                          'itemcount': 10,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    98
                          'permanentcount': 10})
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
    99
        c = QueryCache(ceiling=20)
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
   100
        for n in range(17):
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10600
diff changeset
   101
            for x in range(10):
7954
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   102
                c[x] = x
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   103
                if n % 2:
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   104
                    c[x]
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   105
                if x % 2:
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   106
                    c[x]
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   107
        self.assertEqual(c._usage_report(),
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   108
                         {'transientcount': 5,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   109
                          'itemcount': 10,
a3d3220669d6 [cache] replace lgc.cache with something more appropriate (closes #1921713)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7791
diff changeset
   110
                          'permanentcount': 5})
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 720
diff changeset
   111
12303
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   112
    def test_clear_on_overflow(self):
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   113
        """Tests that only non-permanent items in the cache are wiped-out on ceiling overflow
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   114
        """
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   115
        c = QueryCache(ceiling=10)
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   116
        # set 10 values
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   117
        for x in range(10):
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   118
            c[x] = x
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   119
        # arrange for the first 5 to be permanent
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   120
        for x in range(5):
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   121
            for r in range(QueryCache._maxlevel + 2):
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   122
                v = c[x]
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   123
                self.assertEqual(v, x)
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   124
        # Add the 11-th
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   125
        c[10] = 10
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   126
        self.assertEqual(c._usage_report(),
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   127
                         {'transientcount': 0,
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   128
                          'itemcount': 6,
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   129
                          'permanentcount': 5})
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   130
198cb7d7b4ac [utils] Fixed issue in clearing QueryCache
Laurent Wouters <lwouters@cenotelie.fr>
parents: 12032
diff changeset
   131
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
class UStringIOTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    def test_boolean_value(self):
10600
180aa08cad48 [tests] Replace use of deprecated TestCase.assert_
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10236
diff changeset
   134
        self.assertTrue(UStringIO())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   137
class RepeatListTC(TestCase):
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   138
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   139
    def test_base(self):
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   140
        l = RepeatList(3, (1, 3))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   141
        self.assertEqual(l[0], (1, 3))
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   142
        self.assertEqual(l[2], (1, 3))
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   143
        self.assertEqual(l[-1], (1, 3))
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   144
        self.assertEqual(len(l), 3)
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   145
        # XXX
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   146
        self.assertEqual(l[4], (1, 3))
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   147
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7762
diff changeset
   148
        self.assertFalse(RepeatList(0, None))
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   149
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   150
    def test_slice(self):
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   151
        l = RepeatList(3, (1, 3))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   152
        self.assertEqual(l[0:1], [(1, 3)])
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   153
        self.assertEqual(l[0:4], [(1, 3)]*3)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   154
        self.assertEqual(l[:], [(1, 3)]*3)
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   155
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   156
    def test_iter(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   157
        self.assertEqual(list(RepeatList(3, (1, 3))),
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   158
                          [(1, 3)]*3)
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   159
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   160
    def test_add(self):
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   161
        l = RepeatList(3, (1, 3))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   162
        self.assertEqual(l + [(1, 4)], [(1, 3)]*3  + [(1, 4)])
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   163
        self.assertEqual([(1, 4)] + l, [(1, 4)] + [(1, 3)]*3)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   164
        self.assertEqual(l + RepeatList(2, (2, 3)), [(1, 3)]*3 + [(2, 3)]*2)
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   165
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   166
        x = l + RepeatList(2, (1, 3))
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   167
        self.assertIsInstance(x, RepeatList)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   168
        self.assertEqual(len(x), 5)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   169
        self.assertEqual(x[0], (1, 3))
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   170
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   171
        x = l + [(1, 3)] * 2
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   172
        self.assertEqual(x, [(1, 3)] * 5)
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   173
5077
dc448c9ad9dd [rset] cubes such as iliane hi-jack rset description by poping some lines from it. Handle this on RepeatList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5069
diff changeset
   174
    def test_eq(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   175
        self.assertEqual(RepeatList(3, (1, 3)),
5077
dc448c9ad9dd [rset] cubes such as iliane hi-jack rset description by poping some lines from it. Handle this on RepeatList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5069
diff changeset
   176
                          [(1, 3)]*3)
dc448c9ad9dd [rset] cubes such as iliane hi-jack rset description by poping some lines from it. Handle this on RepeatList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5069
diff changeset
   177
dc448c9ad9dd [rset] cubes such as iliane hi-jack rset description by poping some lines from it. Handle this on RepeatList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5069
diff changeset
   178
    def test_pop(self):
dc448c9ad9dd [rset] cubes such as iliane hi-jack rset description by poping some lines from it. Handle this on RepeatList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5069
diff changeset
   179
        l = RepeatList(3, (1, 3))
dc448c9ad9dd [rset] cubes such as iliane hi-jack rset description by poping some lines from it. Handle this on RepeatList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5069
diff changeset
   180
        l.pop(2)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   181
        self.assertEqual(l, [(1, 3)]*2)
5069
135c5d7b89d0 [querier] introduce RepeatList class, used to optimize size of data returned for result set description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4890
diff changeset
   182
5726
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   183
4890
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4694
diff changeset
   184
class JSONEncoderTC(TestCase):
4694
c19366a12281 simplejson may not be available with python 2.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   185
    def setUp(self):
5377
84d14ddfae13 [python2.6] prefer python2.6's builtin json module over simplejson
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5077
diff changeset
   186
        if json is None:
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   187
            self.skipTest('json not available')
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   188
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   189
    def encode(self, value):
5377
84d14ddfae13 [python2.6] prefer python2.6's builtin json module over simplejson
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5077
diff changeset
   190
        return json.dumps(value, cls=CubicWebJsonEncoder)
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   191
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   192
    def test_encoding_dates(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   193
        self.assertEqual(self.encode(datetime.datetime(2009, 9, 9, 20, 30)),
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   194
                          '"2009/09/09 20:30:00"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   195
        self.assertEqual(self.encode(datetime.date(2009, 9, 9)),
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   196
                          '"2009/09/09"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   197
        self.assertEqual(self.encode(datetime.time(20, 30)),
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   198
                          '"20:30:00"')
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   199
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   200
    def test_encoding_decimal(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   201
        self.assertEqual(self.encode(decimal.Decimal('1.2')), '1.2')
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   202
5726
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   203
    def test_encoding_bare_entity(self):
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   204
        e = Entity(None)
6142
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   205
        e.cw_attr_cache['pouet'] = 'hop'
5726
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   206
        e.eid = 2
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   207
        self.assertEqual(json.loads(self.encode(e)),
5726
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   208
                          {'pouet': 'hop', 'eid': 2})
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   209
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   210
    def test_encoding_entity_in_list(self):
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   211
        e = Entity(None)
6142
8bc6eac1fac1 [session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   212
        e.cw_attr_cache['pouet'] = 'hop'
5726
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   213
        e.eid = 2
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   214
        self.assertEqual(json.loads(self.encode([e])),
5726
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   215
                          [{'pouet': 'hop', 'eid': 2}])
c3b99606644d [json] fix json serialization for recent simplejson implementation, and test encoding of entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   216
11715
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
   217
    def test_encoding_binary(self):
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
   218
        for content in (b'he he', b'h\xe9 hxe9'):
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
   219
            with self.subTest(content=content):
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
   220
                encoded = self.encode(Binary(content))
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
   221
                self.assertEqual(base64.b64decode(encoded), content)
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
   222
3231
3ee43e2f8560 [utils] provide a class to extend the default simplejson encoder to be able to dump standard yams attribute types
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2635
diff changeset
   223
    def test_encoding_unknown_stuff(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5726
diff changeset
   224
        self.assertEqual(self.encode(TestCase), 'null')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 720
diff changeset
   225
11714
73201a210007 [test] Make cubicweb/test/unittest_utils.py flake8-clean
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11078
diff changeset
   226
7277
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   227
class HTMLHeadTC(CubicWebTC):
7762
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   228
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   229
    def htmlhead(self, datadir_url):
9657
3ff4c6f80c37 [test] update unittest_utils to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9599
diff changeset
   230
        with self.admin_access.web_request() as req:
3ff4c6f80c37 [test] update unittest_utils to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9599
diff changeset
   231
            base_url = u'http://test.fr/data/'
3ff4c6f80c37 [test] update unittest_utils to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9599
diff changeset
   232
            req.datadir_url = base_url
3ff4c6f80c37 [test] update unittest_utils to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9599
diff changeset
   233
            head = HTMLHead(req)
3ff4c6f80c37 [test] update unittest_utils to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9599
diff changeset
   234
            return head
7762
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   235
7277
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   236
    def test_concat_urls(self):
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   237
        base_url = u'http://test.fr/data/'
7762
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   238
        head = self.htmlhead(base_url)
7277
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   239
        urls = [base_url + u'bob1.js',
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   240
                base_url + u'bob2.js',
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   241
                base_url + u'bob3.js']
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   242
        result = head.concat_urls(urls)
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   243
        expected = u'http://test.fr/data/??bob1.js,bob2.js,bob3.js'
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   244
        self.assertEqual(result, expected)
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   245
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   246
    def test_group_urls(self):
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   247
        base_url = u'http://test.fr/data/'
7762
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   248
        head = self.htmlhead(base_url)
7277
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   249
        urls_spec = [(base_url + u'bob0.js', None),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   250
                     (base_url + u'bob1.js', None),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   251
                     (u'http://ext.com/bob2.js', None),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   252
                     (u'http://ext.com/bob3.js', None),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   253
                     (base_url + u'bob4.css', 'all'),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   254
                     (base_url + u'bob5.css', 'all'),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   255
                     (base_url + u'bob6.css', 'print'),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   256
                     (base_url + u'bob7.css', 'print'),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   257
                     (base_url + u'bob8.css', ('all', u'[if IE 8]')),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   258
                     (base_url + u'bob9.css', ('print', u'[if IE 8]'))
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   259
                     ]
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   260
        result = head.group_urls(urls_spec)
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   261
        expected = [(base_url + u'??bob0.js,bob1.js', None),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   262
                    (u'http://ext.com/bob2.js', None),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   263
                    (u'http://ext.com/bob3.js', None),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   264
                    (base_url + u'??bob4.css,bob5.css', 'all'),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   265
                    (base_url + u'??bob6.css,bob7.css', 'print'),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   266
                    (base_url + u'bob8.css', ('all', u'[if IE 8]')),
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   267
                    (base_url + u'bob9.css', ('print', u'[if IE 8]'))
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   268
                    ]
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   269
        self.assertEqual(list(result), expected)
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   270
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   271
    def test_getvalue_with_concat(self):
9599
13dd3a57dabb [test/utils] repair concat-resources test
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8682
diff changeset
   272
        self.config.global_set_option('concat-resources', True)
7277
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   273
        base_url = u'http://test.fr/data/'
7762
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   274
        head = self.htmlhead(base_url)
7277
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   275
        head.add_js(base_url + u'bob0.js')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   276
        head.add_js(base_url + u'bob1.js')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   277
        head.add_js(u'http://ext.com/bob2.js')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   278
        head.add_js(u'http://ext.com/bob3.js')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   279
        head.add_css(base_url + u'bob4.css')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   280
        head.add_css(base_url + u'bob5.css')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   281
        head.add_css(base_url + u'bob6.css', 'print')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   282
        head.add_css(base_url + u'bob7.css', 'print')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   283
        head.add_ie_css(base_url + u'bob8.css')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   284
        head.add_ie_css(base_url + u'bob9.css', 'print', u'[if lt IE 7]')
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   285
        result = head.getvalue()
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   286
        expected = u"""<head>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   287
<link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/??bob4.css,bob5.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   288
<link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/??bob6.css,bob7.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   289
<!--[if lt IE 8]>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   290
<link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/bob8.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   291
<!--[if lt IE 7]>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   292
<link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/bob9.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   293
<![endif]--> 
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   294
<script type="text/javascript" src="http://test.fr/data/??bob0.js,bob1.js"></script>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   295
<script type="text/javascript" src="http://ext.com/bob2.js"></script>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   296
<script type="text/javascript" src="http://ext.com/bob3.js"></script>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   297
</head>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   298
"""
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   299
        self.assertEqual(result, expected)
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   300
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   301
    def test_getvalue_without_concat(self):
7762
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   302
        self.config.global_set_option('concat-resources', False)
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   303
        try:
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   304
            base_url = u'http://test.fr/data/'
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   305
            head = self.htmlhead(base_url)
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   306
            head.add_js(base_url + u'bob0.js')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   307
            head.add_js(base_url + u'bob1.js')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   308
            head.add_js(u'http://ext.com/bob2.js')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   309
            head.add_js(u'http://ext.com/bob3.js')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   310
            head.add_css(base_url + u'bob4.css')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   311
            head.add_css(base_url + u'bob5.css')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   312
            head.add_css(base_url + u'bob6.css', 'print')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   313
            head.add_css(base_url + u'bob7.css', 'print')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   314
            head.add_ie_css(base_url + u'bob8.css')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   315
            head.add_ie_css(base_url + u'bob9.css', 'print', u'[if lt IE 7]')
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   316
            result = head.getvalue()
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   317
            expected = u"""<head>
7277
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   318
<link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/bob4.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   319
<link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/bob5.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   320
<link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/bob6.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   321
<link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/bob7.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   322
<!--[if lt IE 8]>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   323
<link rel="stylesheet" type="text/css" media="all" href="http://test.fr/data/bob8.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   324
<!--[if lt IE 7]>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   325
<link rel="stylesheet" type="text/css" media="print" href="http://test.fr/data/bob9.css"/>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   326
<![endif]--> 
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   327
<script type="text/javascript" src="http://test.fr/data/bob0.js"></script>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   328
<script type="text/javascript" src="http://test.fr/data/bob1.js"></script>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   329
<script type="text/javascript" src="http://ext.com/bob2.js"></script>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   330
<script type="text/javascript" src="http://ext.com/bob3.js"></script>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   331
</head>
acd7f0e9f276 [etwist] Generates apache's mod_concat-like urls for js and css
Quentin Roquefort <roquefort.quentin@gmail.com>
parents: 6415
diff changeset
   332
"""
7762
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   333
            self.assertEqual(result, expected)
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   334
        finally:
a3f9ba4d44eb [web] add option to make resources-concat optional (implements #1910615)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7569
diff changeset
   335
            self.config.global_set_option('concat-resources', True)
4890
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4694
diff changeset
   336
11078
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   337
11917
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   338
def UnauthorizedTC(TestCase):
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   339
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   340
    def _test(self, func):
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   341
        self.assertEqual(func(Unauthorized()),
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   342
                         'You are not allowed to perform this operation')
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   343
        self.assertEqual(func(Unauthorized('a')),
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   344
                         'a')
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   345
        self.assertEqual(func(Unauthorized('a', 'b')),
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   346
                         'You are not allowed to perform a operation on b')
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   347
        self.assertEqual(func(Unauthorized('a', 'b', 'c')),
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   348
                         'a b c')
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   349
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   350
    def test_str(self):
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   351
        self._test(str)
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   352
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   353
    if PY2:
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   354
        def test_unicode(self):
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   355
            self._test(unicode)
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   356
c38e13988c10 Fix str(Unauthorized)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11715
diff changeset
   357
11078
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   358
def load_tests(loader, tests, ignore):
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   359
    import cubicweb.utils
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   360
    tests.addTests(doctest.DocTestSuite(cubicweb.utils))
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   361
    return tests
de4367ef4e5e [test] Use stdlib doctest module instead of logilab-common class
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11057
diff changeset
   362
7568
c5ee33fb6a3b [test] run and fix utils and uilib doctests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   363
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
if __name__ == '__main__':
11715
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
   365
    import unittest
760d5c0ae08f [utils] Encode Binary value in base64 for JSON export
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11714
diff changeset
   366
    unittest.main()