entities/test/unittest_base.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Dec 2015 17:44:17 +0100
changeset 11001 37c5c9b3b3bf
parent 10974 6557833657d6
child 11044 00c5ee272a6d
permissions -rw-r--r--
[migration] handle the case where new final entity type is not yet in the schema This may occur on new cube addition. Related to #7569998.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
     2
# copyright 2003-2015 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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
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: 4491
diff changeset
    18
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1642
diff changeset
    19
"""unit tests for cubicweb.entities.base module
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1642
diff changeset
    20
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from logilab.common.decorators import clear_cache
10847
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    24
from logilab.common.registry import yes
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2660
diff changeset
    26
from cubicweb.devtools.testlib import CubicWebTC
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
from cubicweb.entities import AnyEntity
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2660
diff changeset
    31
class BaseEntityTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
    def setup_database(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    34
        with self.admin_access.repo_cnx() as cnx:
9859
fc978ff7f381 [entitiestests/base] don't store an entity on the test case
Julien Cristau <julien.cristau@logilab.fr>
parents: 9858
diff changeset
    35
            self.membereid = self.create_user(cnx, 'member').eid
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    36
            cnx.commit()
1642
12a98b17fb05 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    37
12a98b17fb05 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    38
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
class MetadataTC(BaseEntityTC):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
    def test_creator(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    42
        with self.new_access('member').repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    43
            entity = cnx.create_entity('Bookmark', title=u"hello", path=u'project/cubicweb')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    44
            cnx.commit()
9859
fc978ff7f381 [entitiestests/base] don't store an entity on the test case
Julien Cristau <julien.cristau@logilab.fr>
parents: 9858
diff changeset
    45
            self.assertEqual(entity.creator.eid, self.membereid)
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    46
            self.assertEqual(entity.dc_creator(), u'member')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
    def test_type(self):
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
    49
        # dc_type may be translated
9859
fc978ff7f381 [entitiestests/base] don't store an entity on the test case
Julien Cristau <julien.cristau@logilab.fr>
parents: 9858
diff changeset
    50
        with self.admin_access.client_cnx() as cnx:
fc978ff7f381 [entitiestests/base] don't store an entity on the test case
Julien Cristau <julien.cristau@logilab.fr>
parents: 9858
diff changeset
    51
            member = cnx.entity_from_eid(self.membereid)
fc978ff7f381 [entitiestests/base] don't store an entity on the test case
Julien Cristau <julien.cristau@logilab.fr>
parents: 9858
diff changeset
    52
            self.assertEqual(member.dc_type(), 'CWUser')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
8899
c7a95ebcc093 [entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8694
diff changeset
    54
    def test_cw_etype(self):
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
    55
        # cw_etype is never translated
9859
fc978ff7f381 [entitiestests/base] don't store an entity on the test case
Julien Cristau <julien.cristau@logilab.fr>
parents: 9858
diff changeset
    56
        with self.admin_access.client_cnx() as cnx:
fc978ff7f381 [entitiestests/base] don't store an entity on the test case
Julien Cristau <julien.cristau@logilab.fr>
parents: 9858
diff changeset
    57
            member = cnx.entity_from_eid(self.membereid)
fc978ff7f381 [entitiestests/base] don't store an entity on the test case
Julien Cristau <julien.cristau@logilab.fr>
parents: 9858
diff changeset
    58
            self.assertEqual(member.cw_etype, 'CWUser')
8899
c7a95ebcc093 [entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8694
diff changeset
    59
1102
054dfee29bfc some test for meta attributes (XXX should be in yams)
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    60
    def test_entity_meta_attributes(self):
054dfee29bfc some test for meta attributes (XXX should be in yams)
sylvain.thenault@logilab.fr
parents: 1016
diff changeset
    61
        # XXX move to yams
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5578
diff changeset
    62
        self.assertEqual(self.schema['CWUser'].meta_attributes(), {})
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    63
        self.assertEqual(dict((str(k), v)
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10411
diff changeset
    64
                              for k, v in self.schema['State'].meta_attributes().items()),
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
    65
                         {'description_format': ('format', 'description')})
1642
12a98b17fb05 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    66
8450
11063635c4e4 [fti] allow usage of custom RQL to fetch entities to index (closes #2410509)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7980
diff changeset
    67
    def test_fti_rql_method(self):
10847
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    68
        class EmailAddress(AnyEntity):
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    69
            __regid__ = 'EmailAddress'
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    70
            __select__ = AnyEntity.__select__ & yes(2)
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
    71
10847
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    72
            @classmethod
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    73
            def cw_fti_index_rql_queries(cls, req):
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    74
                return ['EmailAddress Y']
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
    75
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    76
        with self.admin_access.web_request() as req:
10847
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    77
            req.create_entity('EmailAddress', address=u'foo@bar.com')
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    78
            eclass = self.vreg['etypes'].etype_class('EmailAddress')
10847
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    79
            # deprecated
10251
2daa5c6dea4d [entities] make cw_fti_index_rql_queries predictable
Julien Cristau <julien.cristau@logilab.fr>
parents: 9859
diff changeset
    80
            self.assertEqual(['Any X, ADDRESS, ALIAS WHERE X is EmailAddress, '
2daa5c6dea4d [entities] make cw_fti_index_rql_queries predictable
Julien Cristau <julien.cristau@logilab.fr>
parents: 9859
diff changeset
    81
                              'X address ADDRESS, X alias ALIAS'],
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    82
                             eclass.cw_fti_index_rql_queries(req))
8450
11063635c4e4 [fti] allow usage of custom RQL to fetch entities to index (closes #2410509)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7980
diff changeset
    83
10847
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    84
            self.assertEqual(['Any X, ADDRESS, ALIAS ORDERBY X LIMIT 1000 WHERE X is EmailAddress, '
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    85
                              'X address ADDRESS, X alias ALIAS, X eid > 0'],
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    86
                             [rset.rql for rset in eclass.cw_fti_index_rql_limit(req)])
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    87
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    88
            # test backwards compatibility with custom method
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    89
            with self.temporary_appobjects(EmailAddress):
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    90
                self.vreg['etypes'].clear_caches()
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    91
                eclass = self.vreg['etypes'].etype_class('EmailAddress')
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    92
                self.assertEqual(['EmailAddress Y'],
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    93
                                 [rset.rql for rset in eclass.cw_fti_index_rql_limit(req)])
ce5403611cbe [fti] add cw_fti_index_rql_limit method
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    94
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
class EmailAddressTC(BaseEntityTC):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    97
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
    def test_canonical_form(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
    99
        with self.admin_access.repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   100
            email1 = cnx.execute('INSERT EmailAddress X: '
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   101
                                 'X address "maarten.ter.huurne@philips.com"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   102
            email2 = cnx.execute('INSERT EmailAddress X: '
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   103
                                 'X address "maarten@philips.com"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   104
            email3 = cnx.execute('INSERT EmailAddress X: '
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   105
                                 'X address "toto@logilab.fr"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   106
            email1.cw_set(prefered_form=email2)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   107
            self.assertEqual(email1.prefered.eid, email2.eid)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   108
            self.assertEqual(email2.prefered.eid, email2.eid)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   109
            self.assertEqual(email3.prefered.eid, email3.eid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
    def test_mangling(self):
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   112
        query = 'INSERT EmailAddress X: X address "maarten.ter.huurne@philips.com"'
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   113
        with self.admin_access.repo_cnx() as cnx:
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   114
            email = cnx.execute(query).get_entity(0, 0)
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   115
            self.assertEqual(email.display_address(), 'maarten.ter.huurne@philips.com')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   116
            self.assertEqual(email.printable_value('address'), 'maarten.ter.huurne@philips.com')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   117
            self.vreg.config.global_set_option('mangle-emails', True)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   118
            try:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   119
                self.assertEqual(email.display_address(), 'maarten.ter.huurne at philips dot com')
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   120
                self.assertEqual(email.printable_value('address'),
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   121
                                 'maarten.ter.huurne at philips dot com')
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   122
                email = cnx.execute('INSERT EmailAddress X: X address "syt"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   123
                self.assertEqual(email.display_address(), 'syt')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   124
                self.assertEqual(email.printable_value('address'), 'syt')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   125
            finally:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   126
                self.vreg.config.global_set_option('mangle-emails', False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
9211
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
   128
    def test_printable_value_escape(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   129
        with self.admin_access.repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   130
            email = cnx.execute('INSERT EmailAddress X: '
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   131
                                'X address "maarten&ter@philips.com"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   132
            self.assertEqual(email.printable_value('address'),
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   133
                             'maarten&amp;ter@philips.com')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   134
            self.assertEqual(email.printable_value('address', format='text/plain'),
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   135
                             'maarten&ter@philips.com')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   137
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1358
diff changeset
   138
class CWUserTC(BaseEntityTC):
1642
12a98b17fb05 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   139
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
    def test_complete(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   141
        with self.admin_access.repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   142
            e = cnx.execute('CWUser X WHERE X login "admin"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   143
            e.complete()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
    def test_matching_groups(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   146
        with self.admin_access.repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   147
            e = cnx.execute('CWUser X WHERE X login "admin"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   148
            self.assertTrue(e.matching_groups('managers'))
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   149
            self.assertFalse(e.matching_groups('xyz'))
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   150
            self.assertTrue(e.matching_groups(('xyz', 'managers')))
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   151
            self.assertFalse(e.matching_groups(('xyz', 'abcd')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
3830
3b6bbb3a3c3e close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3316
diff changeset
   153
    def test_dc_title_and_name(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   154
        with self.admin_access.repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   155
            e = cnx.execute('CWUser U WHERE U login "member"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   156
            self.assertEqual(e.dc_title(), 'member')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   157
            self.assertEqual(e.name(), 'member')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   158
            e.cw_set(firstname=u'bouah')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   159
            self.assertEqual(e.dc_title(), 'member')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   160
            self.assertEqual(e.name(), u'bouah')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   161
            e.cw_set(surname=u'lôt')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   162
            self.assertEqual(e.dc_title(), 'member')
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   163
            self.assertEqual(e.name(), u'bouah lôt')
3830
3b6bbb3a3c3e close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3316
diff changeset
   164
10396
33e44293b0eb [entities] fix dc_title output for bool(value) == False
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9859
diff changeset
   165
    def test_falsey_dc_title(self):
33e44293b0eb [entities] fix dc_title output for bool(value) == False
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9859
diff changeset
   166
        with self.admin_access.repo_cnx() as cnx:
33e44293b0eb [entities] fix dc_title output for bool(value) == False
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9859
diff changeset
   167
            e = cnx.create_entity('Company', order=0, name=u'pythonian')
33e44293b0eb [entities] fix dc_title output for bool(value) == False
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9859
diff changeset
   168
            cnx.commit()
33e44293b0eb [entities] fix dc_title output for bool(value) == False
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9859
diff changeset
   169
            self.assertEqual(u'0', e.dc_title())
33e44293b0eb [entities] fix dc_title output for bool(value) == False
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9859
diff changeset
   170
3830
3b6bbb3a3c3e close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3316
diff changeset
   171
    def test_allowed_massmail_keys(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   172
        with self.admin_access.repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   173
            e = cnx.execute('CWUser U WHERE U login "member"').get_entity(0, 0)
10402
e3c20f4d1a7c [test] typo in entities test comment
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10396
diff changeset
   174
            # Bytes/Password attributes should be omitted
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   175
            self.assertEqual(
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   176
                e.cw_adapt_to('IEmailable').allowed_massmail_keys(),
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   177
                set(('surname', 'firstname', 'login', 'last_login_time',
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   178
                     'creation_date', 'modification_date', 'cwuri', 'eid'))
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   179
            )
3830
3b6bbb3a3c3e close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3316
diff changeset
   180
7212
040d3597444f [entities/test] add failing test for cw_instantiate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6340
diff changeset
   181
    def test_cw_instantiate_object_relation(self):
040d3597444f [entities/test] add failing test for cw_instantiate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6340
diff changeset
   182
        """ a weird non regression test """
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   183
        with self.admin_access.repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   184
            e = cnx.execute('CWUser U WHERE U login "member"').get_entity(0, 0)
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   185
            cnx.create_entity('CWGroup', name=u'logilab', reverse_in_group=e)
7212
040d3597444f [entities/test] add failing test for cw_instantiate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6340
diff changeset
   186
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
9432
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   188
class HTMLtransformTC(BaseEntityTC):
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   189
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   190
    def test_sanitized_html(self):
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   191
        with self.admin_access.repo_cnx() as cnx:
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   192
            c = cnx.create_entity('Company', name=u'Babar',
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   193
                                  description=u"""
9432
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   194
Title
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   195
=====
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   196
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   197
Elephant management best practices.
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   198
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   199
.. raw:: html
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   200
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   201
   <script>alert("coucou")</script>
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   202
""", description_format=u'text/rest')
9858
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   203
            cnx.commit()
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   204
            c.cw_clear_all_caches()
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   205
            self.assertIn('alert',
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   206
                          c.printable_value('description', format='text/plain'))
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   207
            self.assertNotIn('alert',
4266e13fd5c1 [entitiestests/base] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9440
diff changeset
   208
                             c.printable_value('description', format='text/html'))
9432
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   209
030745ac9873 [entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   210
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2660
diff changeset
   211
class SpecializedEntityClassesTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
    def select_eclass(self, etype):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
        # clear selector cache
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   215
        clear_cache(self.vreg['etypes'], 'etype_class')
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   216
        return self.vreg['etypes'].etype_class(etype)
1642
12a98b17fb05 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   217
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
    def test_etype_class_selection_and_specialization(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
        # no specific class for Subdivisions, the default one should be selected
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
        eclass = self.select_eclass('SubDivision')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
   221
        self.assertTrue(eclass.__autogenerated__)
10974
6557833657d6 a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10973
diff changeset
   222
        # self.assertEqual(eclass.__bases__, (AnyEntity,))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
        # build class from most generic to most specific and make
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
        # sure the most specific is always selected
1358
a7438eb2420c test update
sylvain.thenault@logilab.fr
parents: 1102
diff changeset
   225
        self.vreg._loadedmods[__name__] = {}
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
        for etype in ('Company', 'Division', 'SubDivision'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
            class Foo(AnyEntity):
3450
265331a0920c use __regid__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3369
diff changeset
   228
                __regid__ = etype
4491
a0f48c31b58a kill register_appobject_class method, simplifying autoregistration. Update test accordingly (test which manually registers object should also properly call there __register__ method). Drop the disable-appobjects config file entry: no one used it since its introduction years ago.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   229
            self.vreg.register(Foo)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
            eclass = self.select_eclass('SubDivision')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
   231
            self.assertTrue(eclass.__autogenerated__)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
   232
            self.assertFalse(eclass is Foo)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
            if etype == 'SubDivision':
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5578
diff changeset
   234
                self.assertEqual(eclass.__bases__, (Foo,))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
            else:
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5578
diff changeset
   236
                self.assertEqual(eclass.__bases__[0].__bases__, (Foo,))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
        # check Division eclass is still selected for plain Division entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
        eclass = self.select_eclass('Division')
8899
c7a95ebcc093 [entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8694
diff changeset
   239
        self.assertEqual(eclass.cw_etype, 'Division')
1642
12a98b17fb05 fix tests
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   240
10973
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   241
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   242
class ISerializableTC(CubicWebTC):
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   243
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   244
    def test_serialization(self):
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   245
        with self.admin_access.repo_cnx() as cnx:
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   246
            entity = cnx.create_entity('CWGroup', name=u'tmp')
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   247
            cnx.commit()
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   248
            serializer = entity.cw_adapt_to('ISerializable')
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   249
            expected = {
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   250
                'cw_etype': u'CWGroup',
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   251
                'cw_source': 'system',
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   252
                'cwuri': u'http://testing.fr/cubicweb/%s' % entity.eid,
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   253
                'creation_date': entity.creation_date,
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   254
                'modification_date': entity.modification_date,
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   255
                'name': u'tmp',
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   256
            }
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   257
            self.assertEqual(serializer.serialize(), expected)
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   258
0939ad2edf63 [adapters] Use an adapter for serializing entities to a bare python structure
Rabah Meradi <rabah.meradi@logilab.fr>
parents: 10847
diff changeset
   259
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
    unittest_main()