web/test/unittest_breadcrumbs.py
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 29 Jun 2015 16:58:43 +0200
changeset 10463 9add9b7f9df7
parent 9843 888a8b406124
permissions -rw-r--r--
[server/test] fix random error in unittest_security When entering a new Connection, we cache the user and its 'login' attribute (with no permissions checking). This test makes 'CWUser.login' unreadable by guests, and then proceeds to make sure the 'anon' user can actually not read any 'login' attribute. However, due to the above cnx initialization, anon's login is actually cached, hence readable. This happens to make the test fail sometimes depending on the order in which CWUser entities are returned, because one of them has .complete() called, which as a side effect sets the attribute cache to None for unreadable attributes. Call .complete() on both entities to reset the login cache. While this is still highly debatable, at least it's consistent.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9843
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
     1
# copyright 2003-2014 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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
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: 5291
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5569
cb14af012a96 [adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    18
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3227
diff changeset
    19
from cubicweb.devtools.testlib import CubicWebTC
3179
0684544f6d0d from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    20
5569
cb14af012a96 [adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    21
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3227
diff changeset
    22
class BreadCrumbsTC(CubicWebTC):
3179
0684544f6d0d from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
0684544f6d0d from 3.5 branch; XXX the test depends on an eid value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    24
    def test_base(self):
9643
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    25
        with self.admin_access.web_request() as req:
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    26
            f1 = req.create_entity('Folder', name=u'par&ent')
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    27
            f2 = req.create_entity('Folder', name=u'chi&ld')
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    28
            req.cnx.execute('SET F2 filed_under F1 WHERE F1 eid %(f1)s, F2 eid %(f2)s',
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    29
                            {'f1' : f1.eid, 'f2' : f2.eid})
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    30
            req.cnx.commit()
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    31
            self.assertEqual(f2.view('breadcrumbs'),
9843
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    32
                             '<a href="http://testing.fr/cubicweb/folder/%s" title="">'
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    33
                             'chi&amp;ld</a>' % f2.eid)
9643
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    34
            childrset = f2.as_rset()
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    35
            ibc = self.vreg['ctxcomponents'].select('breadcrumbs', req, rset=childrset)
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    36
            l = []
421604863753 [web/test] port unittest_breadcrumbs to 3.19 test api
Julien Cristau <julien.cristau@logilab.fr>
parents: 7980
diff changeset
    37
            ibc.render(l.append)
9843
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    38
            self.assertMultiLineEqual('<span id="breadcrumbs" class="pathbar">&#160;&gt;&#160;'
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    39
                                      '<a href="http://testing.fr/cubicweb/Folder">Folder_plural</a>'
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    40
                                      '&#160;&gt;&#160;<a href="http://testing.fr/cubicweb/folder/%s" '
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    41
                                      'title="">par&amp;ent</a>&#160;&gt;&#160;\n'
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    42
                                      '<a href="http://testing.fr/cubicweb/folder/%s" title="">'
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    43
                                      'chi&amp;ld</a></span>' % (f1.eid, f2.eid),
888a8b406124 [webtests/breadcrumbs] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9643
diff changeset
    44
                                      ''.join(l))
4172
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    45
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    46
if __name__ == '__main__':
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    47
    from logilab.common.testlib import unittest_main
4d4cef034eec all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3460
diff changeset
    48
    unittest_main()