hooks/test/unittest_syncschema.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 28 Apr 2010 10:06:01 +0200
branchstable
changeset 5421 8167de96c523
parent 4984 6cb91be7707f
child 5423 e15abfdcce38
child 5424 8ecbcbff9777
permissions -rw-r--r--
proper licensing information (LGPL-2.1). Hope I get it right this time.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
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: 4984
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: 4984
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: 4984
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: 4984
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: 4984
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: 4984
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: 4984
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: 4984
diff changeset
    10
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
    11
# logilab-common is distributed in the hope that it will be useful, but WITHOUT
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
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: 4984
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: 4984
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: 4984
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: 4984
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: 4984
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    18
from logilab.common.testlib import TestCase, unittest_main
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    19
4689
4eb1f4490538 [test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4681
diff changeset
    20
from cubicweb import ValidationError
4eb1f4490538 [test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4681
diff changeset
    21
from cubicweb.devtools.testlib import CubicWebTC
4eb1f4490538 [test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4681
diff changeset
    22
from cubicweb.server.sqlutils import SQL_PREFIX
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
    23
from cubicweb.devtools.repotest import schema_eids_idx, restore_schema_eids_idx
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    24
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
    25
def teardown_module(*args):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
    26
    del SchemaModificationHooksTC.schema_eids
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
    27
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    28
class SchemaModificationHooksTC(CubicWebTC):
4691
ae468fae9965 [test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4689
diff changeset
    29
    reset_schema = True
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    30
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    31
    @classmethod
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    32
    def init_config(cls, config):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    33
        super(SchemaModificationHooksTC, cls).init_config(config)
4691
ae468fae9965 [test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4689
diff changeset
    34
        # we have to read schema from the database to get eid for schema entities
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    35
        config._cubes = None
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    36
        cls.repo.fill_schema()
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
    37
        cls.schema_eids = schema_eids_idx(cls.repo.schema)
4691
ae468fae9965 [test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4689
diff changeset
    38
ae468fae9965 [test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4689
diff changeset
    39
    @classmethod
ae468fae9965 [test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4689
diff changeset
    40
    def _refresh_repo(cls):
ae468fae9965 [test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4689
diff changeset
    41
        super(SchemaModificationHooksTC, cls)._refresh_repo()
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
    42
        restore_schema_eids_idx(cls.repo.schema, cls.schema_eids)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    43
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    44
    def index_exists(self, etype, attr, unique=False):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    45
        self.session.set_pool()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    46
        dbhelper = self.session.pool.source('system').dbhelper
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    47
        sqlcursor = self.session.pool['system']
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    48
        return dbhelper.index_exists(sqlcursor, SQL_PREFIX + etype, SQL_PREFIX + attr, unique=unique)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    49
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    50
    def _set_perms(self, eid):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    51
        self.execute('SET X read_permission G WHERE X eid %(x)s, G is CWGroup',
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    52
                     {'x': eid}, 'x')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    53
        self.execute('SET X add_permission G WHERE X eid %(x)s, G is CWGroup, G name "managers"',
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    54
                     {'x': eid}, 'x')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    55
        self.execute('SET X delete_permission G WHERE X eid %(x)s, G is CWGroup, G name "owners"',
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    56
                     {'x': eid}, 'x')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    57
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    58
    def _set_attr_perms(self, eid):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    59
        self.execute('SET X read_permission G WHERE X eid %(x)s, G is CWGroup',
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    60
                     {'x': eid}, 'x')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    61
        self.execute('SET X update_permission G WHERE X eid %(x)s, G is CWGroup, G name "managers"',
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    62
                     {'x': eid}, 'x')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    63
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    64
    def test_base(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    65
        schema = self.repo.schema
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    66
        self.session.set_pool()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    67
        dbhelper = self.session.pool.source('system').dbhelper
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    68
        sqlcursor = self.session.pool['system']
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    69
        self.failIf(schema.has_entity('Societe2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    70
        self.failIf(schema.has_entity('concerne2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    71
        # schema should be update on insertion (after commit)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    72
        eeid = self.execute('INSERT CWEType X: X name "Societe2", X description "", X final FALSE')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    73
        self._set_perms(eeid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    74
        self.execute('INSERT CWRType X: X name "concerne2", X description "", X final FALSE, X symmetric FALSE')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    75
        self.failIf(schema.has_entity('Societe2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    76
        self.failIf(schema.has_entity('concerne2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    77
        # have to commit before adding definition relations
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    78
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    79
        self.failUnless(schema.has_entity('Societe2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    80
        self.failUnless(schema.has_relation('concerne2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    81
        attreid = self.execute('INSERT CWAttribute X: X cardinality "11", X defaultval "noname", '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    82
                               '   X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    83
                               'WHERE RT name "name", E name "Societe2", F name "String"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    84
        self._set_attr_perms(attreid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    85
        concerne2_rdef_eid = self.execute(
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    86
            'INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    87
            'WHERE RT name "concerne2", E name "Societe2"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    88
        self._set_perms(concerne2_rdef_eid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    89
        self.failIf('name' in schema['Societe2'].subject_relations())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    90
        self.failIf('concerne2' in schema['Societe2'].subject_relations())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    91
        self.failIf(self.index_exists('Societe2', 'name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    92
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    93
        self.failUnless('name' in schema['Societe2'].subject_relations())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    94
        self.failUnless('concerne2' in schema['Societe2'].subject_relations())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    95
        self.failUnless(self.index_exists('Societe2', 'name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    96
        # now we should be able to insert and query Societe2
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    97
        s2eid = self.execute('INSERT Societe2 X: X name "logilab"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    98
        self.execute('Societe2 X WHERE X name "logilab"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    99
        self.execute('SET X concerne2 X WHERE X name "logilab"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   100
        rset = self.execute('Any X WHERE X concerne2 Y')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   101
        self.assertEquals(rset.rows, [[s2eid]])
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   102
        # check that when a relation definition is deleted, existing relations are deleted
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   103
        rdefeid = self.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   104
                               '   X from_entity E, X to_entity E '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   105
                               'WHERE RT name "concerne2", E name "CWUser"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   106
        self._set_perms(rdefeid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   107
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   108
        self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid}, 'x')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   109
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   110
        self.failUnless('concerne2' in schema['CWUser'].subject_relations())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   111
        self.failIf('concerne2' in schema['Societe2'].subject_relations())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   112
        self.failIf(self.execute('Any X WHERE X concerne2 Y'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   113
        # schema should be cleaned on delete (after commit)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   114
        self.execute('DELETE CWEType X WHERE X name "Societe2"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   115
        self.execute('DELETE CWRType X WHERE X name "concerne2"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   116
        self.failUnless(self.index_exists('Societe2', 'name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   117
        self.failUnless(schema.has_entity('Societe2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   118
        self.failUnless(schema.has_relation('concerne2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   119
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   120
        self.failIf(self.index_exists('Societe2', 'name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   121
        self.failIf(schema.has_entity('Societe2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   122
        self.failIf(schema.has_entity('concerne2'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   123
        self.failIf('concerne2' in schema['CWUser'].subject_relations())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   124
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   125
    def test_is_instance_of_insertions(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   126
        seid = self.execute('INSERT Transition T: T name "subdiv"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   127
        is_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is ET, ET name ETN' % seid)]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   128
        self.assertEquals(is_etypes, ['Transition'])
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   129
        instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   130
        self.assertEquals(sorted(instanceof_etypes), ['BaseTransition', 'Transition'])
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   131
        snames = [name for name, in self.execute('Any N WHERE S is BaseTransition, S name N')]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   132
        self.failIf('subdiv' in snames)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   133
        snames = [name for name, in self.execute('Any N WHERE S is_instance_of BaseTransition, S name N')]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   134
        self.failUnless('subdiv' in snames)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   135
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   136
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   137
    def test_perms_synchronization_1(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   138
        schema = self.repo.schema
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   139
        self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users')))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   140
        self.failUnless(self.execute('Any X, Y WHERE X is CWEType, X name "CWUser", Y is CWGroup, Y name "users"')[0])
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   141
        self.execute('DELETE X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   142
        self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users', )))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   143
        self.commit()
4681
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4667
diff changeset
   144
        self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers',)))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   145
        self.execute('SET X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   146
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   147
        self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users',)))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   148
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   149
    def test_perms_synchronization_2(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   150
        schema = self.repo.schema['in_group'].rdefs[('CWUser', 'CWGroup')]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   151
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests')))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   152
        self.execute('DELETE X read_permission Y WHERE X relation_type RT, RT name "in_group", Y name "guests"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   153
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests')))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   154
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   155
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users')))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   156
        self.execute('SET X read_permission Y WHERE X relation_type RT, RT name "in_group", Y name "guests"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   157
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users')))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   158
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   159
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests')))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   160
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   161
    def test_nonregr_user_edit_itself(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   162
        ueid = self.session.user.eid
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   163
        groupeids = [eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   164
        self.execute('DELETE X in_group Y WHERE X eid %s' % ueid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   165
        self.execute('SET X surname "toto" WHERE X eid %s' % ueid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   166
        self.execute('SET X in_group Y WHERE X eid %s, Y name "managers"' % ueid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   167
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   168
        eeid = self.execute('Any X WHERE X is CWEType, X name "CWEType"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   169
        self.execute('DELETE X read_permission Y WHERE X eid %s' % eeid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   170
        self.execute('SET X final FALSE WHERE X eid %s' % eeid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   171
        self.execute('SET X read_permission Y WHERE X eid %s, Y eid in (%s, %s)'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   172
                     % (eeid, groupeids[0], groupeids[1]))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   173
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   174
        self.execute('Any X WHERE X is CWEType, X name "CWEType"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   175
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   176
    # schema modification hooks tests #########################################
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   177
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   178
    def test_uninline_relation(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   179
        self.session.set_pool()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   180
        dbhelper = self.session.pool.source('system').dbhelper
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   181
        sqlcursor = self.session.pool['system']
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   182
        self.failUnless(self.schema['state_of'].inlined)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   183
        try:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   184
            self.execute('SET X inlined FALSE WHERE X name "state_of"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   185
            self.failUnless(self.schema['state_of'].inlined)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   186
            self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   187
            self.failIf(self.schema['state_of'].inlined)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   188
            self.failIf(self.index_exists('State', 'state_of'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   189
            rset = self.execute('Any X, Y WHERE X state_of Y')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   190
            self.assertEquals(len(rset), 2) # user states
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   191
        finally:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   192
            self.execute('SET X inlined TRUE WHERE X name "state_of"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   193
            self.failIf(self.schema['state_of'].inlined)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   194
            self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   195
            self.failUnless(self.schema['state_of'].inlined)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   196
            self.failUnless(self.index_exists('State', 'state_of'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   197
            rset = self.execute('Any X, Y WHERE X state_of Y')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   198
            self.assertEquals(len(rset), 2)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   199
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   200
    def test_indexed_change(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   201
        self.session.set_pool()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   202
        dbhelper = self.session.pool.source('system').dbhelper
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   203
        sqlcursor = self.session.pool['system']
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   204
        try:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   205
            self.execute('SET X indexed FALSE WHERE X relation_type R, R name "name"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   206
            self.failUnless(self.schema['name'].rdef('Workflow', 'String').indexed)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   207
            self.failUnless(self.index_exists('Workflow', 'name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   208
            self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   209
            self.failIf(self.schema['name'].rdef('Workflow', 'String').indexed)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   210
            self.failIf(self.index_exists('Workflow', 'name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   211
        finally:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   212
            self.execute('SET X indexed TRUE WHERE X relation_type R, R name "name"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   213
            self.failIf(self.schema['name'].rdef('Workflow', 'String').indexed)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   214
            self.failIf(self.index_exists('Workflow', 'name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   215
            self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   216
            self.failUnless(self.schema['name'].rdef('Workflow', 'String').indexed)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   217
            self.failUnless(self.index_exists('Workflow', 'name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   218
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   219
    def test_unique_change(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   220
        self.session.set_pool()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   221
        dbhelper = self.session.pool.source('system').dbhelper
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   222
        sqlcursor = self.session.pool['system']
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   223
        try:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   224
            self.execute('INSERT CWConstraint X: X cstrtype CT, DEF constrained_by X '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   225
                         'WHERE CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   226
                         'RT name "name", E name "Workflow"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   227
            self.failIf(self.schema['Workflow'].has_unique_values('name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   228
            self.failIf(self.index_exists('Workflow', 'name', unique=True))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   229
            self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   230
            self.failUnless(self.schema['Workflow'].has_unique_values('name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   231
            self.failUnless(self.index_exists('Workflow', 'name', unique=True))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   232
        finally:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   233
            self.execute('DELETE DEF constrained_by X WHERE X cstrtype CT, '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   234
                         'CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   235
                         'RT name "name", E name "Workflow"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   236
            self.failUnless(self.schema['Workflow'].has_unique_values('name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   237
            self.failUnless(self.index_exists('Workflow', 'name', unique=True))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   238
            self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   239
            self.failIf(self.schema['Workflow'].has_unique_values('name'))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   240
            self.failIf(self.index_exists('Workflow', 'name', unique=True))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   241
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   242
    def test_required_change_1(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   243
        self.execute('SET DEF cardinality "?1" '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   244
                     'WHERE DEF relation_type RT, DEF from_entity E,'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   245
                     'RT name "title", E name "Bookmark"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   246
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   247
        # should now be able to add bookmark without title
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   248
        self.execute('INSERT Bookmark X: X path "/view"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   249
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   250
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   251
    def test_required_change_2(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   252
        self.execute('SET DEF cardinality "11" '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   253
                     'WHERE DEF relation_type RT, DEF from_entity E,'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   254
                     'RT name "surname", E name "CWUser"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   255
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   256
        # should not be able anymore to add cwuser without surname
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   257
        self.assertRaises(ValidationError, self.create_user, "toto")
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   258
        self.execute('SET DEF cardinality "?1" '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   259
                     'WHERE DEF relation_type RT, DEF from_entity E,'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   260
                     'RT name "surname", E name "CWUser"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   261
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   262
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   263
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   264
    def test_add_attribute_to_base_class(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   265
        attreid = self.execute('INSERT CWAttribute X: X cardinality "11", X defaultval "noname", X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   266
                               'WHERE RT name "messageid", E name "BaseTransition", F name "String"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   267
        assert self.execute('SET X read_permission Y WHERE X eid %(x)s, Y name "managers"',
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   268
                     {'x': attreid}, 'x')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   269
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   270
        self.schema.rebuild_infered_relations()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   271
        self.failUnless('Transition' in self.schema['messageid'].subjects())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   272
        self.failUnless('WorkflowTransition' in self.schema['messageid'].subjects())
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   273
        self.execute('Any X WHERE X is_instance_of BaseTransition, X messageid "hop"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   274
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   275
    def test_change_fulltextindexed(self):
4826
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   276
        req = self.request()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   277
        target = req.create_entity(u'Email', messageid=u'1234',
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   278
                                   subject=u'rick.roll@dance.com')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   279
        self.commit()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   280
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   281
        self.assertIn(target.eid, [item[0] for item in rset])
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   282
        assert req.execute('SET A fulltextindexed FALSE '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   283
                            'WHERE E is CWEType, E name "Email", A is CWAttribute,'
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   284
                            'A from_entity E, A relation_type R, R name "subject"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   285
        self.commit()
4840
c02a340cd1da cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4826
diff changeset
   286
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
4826
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   287
        self.failIf(rset)
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   288
        assert req.execute('SET A fulltextindexed TRUE '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   289
                           'WHERE A from_entity E, A relation_type R, '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   290
                           'E name "Email", R name "subject"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   291
        self.commit()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   292
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   293
        self.assertIn(target.eid, [item[0] for item in rset])
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   294
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   295
    def test_change_fulltext_container(self):
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   296
        req = self.request()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   297
        target = req.create_entity(u'EmailAddress', address=u'rick.roll@dance.com')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   298
        target.set_relations(reverse_use_email=req.user)
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   299
        self.commit()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   300
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   301
        self.assertIn(req.user.eid, [item[0] for item in rset])
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   302
        assert self.execute('SET R fulltext_container NULL '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   303
                            'WHERE R name "use_email"')
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   304
        self.commit()
4840
c02a340cd1da cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4826
diff changeset
   305
        rset = self.execute('Any X WHERE X has_text "rick.roll"')
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   306
        self.assertIn(target.eid, [item[0] for item in rset])
4826
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   307
        assert self.execute('SET R fulltext_container "subject" '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   308
                            'WHERE R name "use_email"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   309
        self.commit()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   310
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   311
        self.assertIn(req.user.eid, [item[0] for item in rset])
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   312
4927
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   313
    def test_update_constraint(self):
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   314
        rdef = self.schema['Transition'].rdef('type')
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   315
        cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   316
        if not getattr(cstr, 'eid', None):
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   317
            self.skip('start me alone') # bug in schema reloading, constraint's eid not restored
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   318
        self.execute('SET X value %(v)s WHERE X eid %(x)s',
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   319
                     {'x': cstr.eid, 'v': u"u'normal', u'auto', u'new'"}, 'x')
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   320
        self.execute('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   321
                     'WHERE CT name %(ct)s, EDEF eid %(x)s',
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   322
                     {'ct': 'SizeConstraint', 'value': u'max=10', 'x': rdef.eid}, 'x')
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   323
        self.commit()
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   324
        cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   325
        self.assertEquals(cstr.values, (u'normal', u'auto', u'new'))
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   326
        self.execute('INSERT Transition T: T name "hop", T type "new"')
4968
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   327
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   328
if __name__ == '__main__':
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   329
    unittest_main()