hooks/test/unittest_syncschema.py
author Julien Cristau <julien.cristau@logilab.fr>
Thu, 15 Jan 2015 18:53:45 +0100
changeset 10204 f8ccae1e271d
parent 9851 42a874c666b1
child 10365 21461f80f348
permissions -rw-r--r--
Add reference from etype table's eid column to the entities table Related to #4846892.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
     1
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 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
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 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/>.
6412
370357e68837 [test] cleanup / unittest2 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6410
diff changeset
    18
"""cubicweb.server.hooks.syncschema unit and functional tests"""
370357e68837 [test] cleanup / unittest2 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6410
diff changeset
    19
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    20
from logilab.common.testlib import unittest_main
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    21
9299
c5eed908117d [schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents: 8947
diff changeset
    22
from cubicweb import ValidationError, Binary
8715
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
    23
from cubicweb.schema import META_RTYPES
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
    24
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
    25
from cubicweb.server.sqlutils import SQL_PREFIX
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    26
from cubicweb.devtools.repotest import schema_eids_idx
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    27
8715
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
    28
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6412
diff changeset
    29
def tearDownModule(*args):
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
    30
    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
    31
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    32
class SchemaModificationHooksTC(CubicWebTC):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    33
7078
bad26a22fe29 [test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6781
diff changeset
    34
    def setUp(self):
bad26a22fe29 [test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6781
diff changeset
    35
        super(SchemaModificationHooksTC, self).setUp()
8947
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8718
diff changeset
    36
        self.repo.set_schema(self.repo.deserialize_schema(), resetvreg=False)
7078
bad26a22fe29 [test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6781
diff changeset
    37
        self.__class__.schema_eids = schema_eids_idx(self.repo.schema)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    38
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    39
    def index_exists(self, cnx, etype, attr, unique=False):
9463
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
    40
        dbhelper = self.repo.system_source.dbhelper
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    41
        with cnx.ensure_cnx_set:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    42
            sqlcursor = cnx.cnxset.cu
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    43
            return dbhelper.index_exists(sqlcursor,
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    44
                                         SQL_PREFIX + etype,
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    45
                                         SQL_PREFIX + attr,
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    46
                                         unique=unique)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    47
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    48
    def _set_perms(self, cnx, eid):
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    49
        cnx.execute('SET X read_permission G WHERE X eid %(x)s, G is CWGroup',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    50
                    {'x': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    51
        cnx.execute('SET X add_permission G WHERE X eid %(x)s, G is CWGroup, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    52
                    'G name "managers"', {'x': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    53
        cnx.execute('SET X delete_permission G WHERE X eid %(x)s, G is CWGroup, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    54
                    'G name "owners"', {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    55
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    56
    def _set_attr_perms(self, cnx, eid):
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    57
        cnx.execute('SET X read_permission G WHERE X eid %(x)s, G is CWGroup',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    58
                    {'x': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    59
        cnx.execute('SET X update_permission G WHERE X eid %(x)s, G is CWGroup, G name "managers"',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    60
                    {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    61
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    62
    def test_base(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    63
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    64
            schema = self.repo.schema
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    65
            self.assertFalse(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    66
            self.assertFalse(schema.has_entity('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    67
            # schema should be update on insertion (after commit)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    68
            eeid = cnx.execute('INSERT CWEType X: X name "Societe2", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    69
                               'X description "", X final FALSE')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    70
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    71
            cnx.execute('INSERT CWRType X: X name "concerne2", X description "", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    72
                        'X final FALSE, X symmetric FALSE')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    73
            self.assertFalse(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    74
            self.assertFalse(schema.has_entity('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    75
            # have to commit before adding definition relations
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    76
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    77
            self.assertTrue(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    78
            self.assertTrue(schema.has_relation('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    79
            attreid = cnx.execute('INSERT CWAttribute X: X cardinality "11", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    80
                                  'X defaultval %(default)s, X indexed TRUE, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    81
                                  'X relation_type RT, X from_entity E, X to_entity F '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    82
                                   'WHERE RT name "name", E name "Societe2", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    83
                                  'F name "String"',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    84
                                   {'default': Binary.zpickle('noname')})[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    85
            self._set_attr_perms(cnx, attreid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    86
            concerne2_rdef_eid = cnx.execute(
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    87
                'INSERT CWRelation X: X cardinality "**", X relation_type RT, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    88
                'X from_entity E, X to_entity E '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    89
                'WHERE RT name "concerne2", E name "Societe2"')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    90
            self._set_perms(cnx, concerne2_rdef_eid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    91
            self.assertNotIn('name', schema['Societe2'].subject_relations())
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    92
            self.assertNotIn('concerne2', schema['Societe2'].subject_relations())
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    93
            self.assertFalse(self.index_exists(cnx, 'Societe2', 'name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    94
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    95
            self.assertIn('name', schema['Societe2'].subject_relations())
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    96
            self.assertIn('concerne2', schema['Societe2'].subject_relations())
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    97
            self.assertTrue(self.index_exists(cnx, 'Societe2', 'name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    98
            # now we should be able to insert and query Societe2
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    99
            s2eid = cnx.execute('INSERT Societe2 X: X name "logilab"')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   100
            cnx.execute('Societe2 X WHERE X name "logilab"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   101
            cnx.execute('SET X concerne2 X WHERE X name "logilab"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   102
            rset = cnx.execute('Any X WHERE X concerne2 Y')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   103
            self.assertEqual(rset.rows, [[s2eid]])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   104
            # check that when a relation definition is deleted, existing relations are deleted
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   105
            rdefeid = cnx.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   106
                                   '   X from_entity E, X to_entity E '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   107
                                   'WHERE RT name "concerne2", E name "CWUser"')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   108
            self._set_perms(cnx, rdefeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   109
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   110
            cnx.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   111
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   112
            self.assertIn('concerne2', schema['CWUser'].subject_relations())
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   113
            self.assertNotIn('concerne2', schema['Societe2'].subject_relations())
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   114
            self.assertFalse(cnx.execute('Any X WHERE X concerne2 Y'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   115
            # schema should be cleaned on delete (after commit)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   116
            cnx.execute('DELETE CWEType X WHERE X name "Societe2"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   117
            cnx.execute('DELETE CWRType X WHERE X name "concerne2"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   118
            self.assertTrue(self.index_exists(cnx, 'Societe2', 'name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   119
            self.assertTrue(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   120
            self.assertTrue(schema.has_relation('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   121
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   122
            self.assertFalse(self.index_exists(cnx, 'Societe2', 'name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   123
            self.assertFalse(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   124
            self.assertFalse(schema.has_entity('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   125
            self.assertNotIn('concerne2', schema['CWUser'].subject_relations())
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   126
8715
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   127
    def test_metartype_with_nordefs(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   128
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   129
            META_RTYPES.add('custom_meta')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   130
            cnx.execute('INSERT CWRType X: X name "custom_meta", X description "", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   131
                         'X final FALSE, X symmetric FALSE')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   132
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   133
            eeid = cnx.execute('INSERT CWEType X: X name "NEWEtype", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   134
                                'X description "", X final FALSE')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   135
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   136
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   137
            META_RTYPES.remove('custom_meta')
8715
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   138
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   139
    def test_metartype_with_somerdefs(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   140
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   141
            META_RTYPES.add('custom_meta')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   142
            cnx.execute('INSERT CWRType X: X name "custom_meta", X description "", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   143
                         'X final FALSE, X symmetric FALSE')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   144
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   145
            rdefeid = cnx.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   146
                                   '   X from_entity E, X to_entity E '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   147
                                   'WHERE RT name "custom_meta", E name "CWUser"')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   148
            self._set_perms(cnx, rdefeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   149
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   150
            eeid = cnx.execute('INSERT CWEType X: X name "NEWEtype", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   151
                                'X description "", X final FALSE')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   152
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   153
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   154
            META_RTYPES.remove('custom_meta')
8715
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   155
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   156
    def test_is_instance_of_insertions(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   157
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   158
            seid = cnx.execute('INSERT Transition T: T name "subdiv"')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   159
            is_etypes = [etype for etype, in cnx.execute('Any ETN WHERE X eid %s, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   160
                                                         'X is ET, ET name ETN' % seid)]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   161
            self.assertEqual(is_etypes, ['Transition'])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   162
            instanceof_etypes = [etype
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   163
                                 for etype, in cnx.execute('Any ETN WHERE X eid %s, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   164
                                                           'X is_instance_of ET, ET name ETN'
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   165
                                                           % seid)]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   166
            self.assertEqual(sorted(instanceof_etypes), ['BaseTransition', 'Transition'])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   167
            snames = [name for name, in cnx.execute('Any N WHERE S is BaseTransition, S name N')]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   168
            self.assertNotIn('subdiv', snames)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   169
            snames = [name for name, in cnx.execute('Any N WHERE S is_instance_of BaseTransition, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   170
                                                    'S name N')]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   171
            self.assertIn('subdiv', snames)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   172
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   173
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   174
    def test_perms_synchronization_1(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   175
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   176
            schema = self.repo.schema
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   177
            self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers', 'users')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   178
            self.assertTrue(cnx.execute('Any X, Y WHERE X is CWEType, X name "CWUser", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   179
                                        'Y is CWGroup, Y name "users"')[0])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   180
            cnx.execute('DELETE X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   181
            self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers', 'users', )))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   182
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   183
            self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers',)))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   184
            cnx.execute('SET X read_permission Y WHERE X is CWEType, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   185
                        'X name "CWUser", Y name "users"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   186
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   187
            self.assertEqual(schema['CWUser'].get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   188
                             set(('managers', 'users',)))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   189
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   190
    def test_perms_synchronization_2(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   191
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   192
            schema = self.repo.schema['in_group'].rdefs[('CWUser', 'CWGroup')]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   193
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   194
                             set(('managers', 'users', 'guests')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   195
            cnx.execute('DELETE X read_permission Y WHERE X relation_type RT, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   196
                        'RT name "in_group", Y name "guests"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   197
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   198
                             set(('managers', 'users', 'guests')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   199
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   200
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   201
                             set(('managers', 'users')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   202
            cnx.execute('SET X read_permission Y WHERE X relation_type RT, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   203
                        'RT name "in_group", Y name "guests"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   204
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   205
                             set(('managers', 'users')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   206
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   207
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   208
                             set(('managers', 'users', 'guests')))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   209
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   210
    def test_nonregr_user_edit_itself(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   211
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   212
            ueid = cnx.user.eid
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   213
            groupeids = [eid for eid, in cnx.execute('CWGroup G WHERE G name '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   214
                                                     'in ("managers", "users")')]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   215
            cnx.execute('DELETE X in_group Y WHERE X eid %s' % ueid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   216
            cnx.execute('SET X surname "toto" WHERE X eid %s' % ueid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   217
            cnx.execute('SET X in_group Y WHERE X eid %s, Y name "managers"' % ueid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   218
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   219
            eeid = cnx.execute('Any X WHERE X is CWEType, X name "CWEType"')[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   220
            cnx.execute('DELETE X read_permission Y WHERE X eid %s' % eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   221
            cnx.execute('SET X final FALSE WHERE X eid %s' % eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   222
            cnx.execute('SET X read_permission Y WHERE X eid %s, Y eid in (%s, %s)'
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   223
                         % (eeid, groupeids[0], groupeids[1]))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   224
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   225
            cnx.execute('Any X WHERE X is CWEType, X name "CWEType"')
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   226
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   227
    # schema modification hooks tests #########################################
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   228
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   229
    def test_uninline_relation(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   230
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   231
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   232
                self.assertTrue(self.schema['state_of'].inlined)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   233
                cnx.execute('SET X inlined FALSE WHERE X name "state_of"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   234
                self.assertTrue(self.schema['state_of'].inlined)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   235
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   236
                self.assertFalse(self.schema['state_of'].inlined)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   237
                self.assertFalse(self.index_exists(cnx, 'State', 'state_of'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   238
                rset = cnx.execute('Any X, Y WHERE X state_of Y')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   239
                self.assertEqual(len(rset), 2) # user states
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   240
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   241
                cnx.execute('SET X inlined TRUE WHERE X name "state_of"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   242
                self.assertFalse(self.schema['state_of'].inlined)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   243
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   244
                self.assertTrue(self.schema['state_of'].inlined)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   245
                self.assertTrue(self.index_exists(cnx, 'State', 'state_of'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   246
                rset = cnx.execute('Any X, Y WHERE X state_of Y')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   247
                self.assertEqual(len(rset), 2)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   248
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   249
    def test_indexed_change(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   250
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   251
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   252
                cnx.execute('SET X indexed FALSE WHERE X relation_type R, R name "name"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   253
                self.assertTrue(self.schema['name'].rdef('Workflow', 'String').indexed)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   254
                self.assertTrue(self.index_exists(cnx, 'Workflow', 'name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   255
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   256
                self.assertFalse(self.schema['name'].rdef('Workflow', 'String').indexed)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   257
                self.assertFalse(self.index_exists(cnx, 'Workflow', 'name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   258
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   259
                cnx.execute('SET X indexed TRUE WHERE X relation_type R, R name "name"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   260
                self.assertFalse(self.schema['name'].rdef('Workflow', 'String').indexed)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   261
                self.assertFalse(self.index_exists(cnx, 'Workflow', 'name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   262
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   263
                self.assertTrue(self.schema['name'].rdef('Workflow', 'String').indexed)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   264
                self.assertTrue(self.index_exists(cnx, 'Workflow', 'name'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   265
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   266
    def test_unique_change(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   267
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   268
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   269
                eid = cnx.execute('INSERT CWConstraint X: X cstrtype CT, DEF constrained_by X '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   270
                                  'WHERE CT name "UniqueConstraint", DEF relation_type RT, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   271
                                  'DEF from_entity E, RT name "name", '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   272
                                  'E name "Workflow"').rows[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   273
                self.assertFalse(self.schema['Workflow'].has_unique_values('name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   274
                self.assertFalse(self.index_exists(cnx, 'Workflow', 'name', unique=True))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   275
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   276
                self.assertTrue(self.schema['Workflow'].has_unique_values('name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   277
                self.assertTrue(self.index_exists(cnx, 'Workflow', 'name', unique=True))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   278
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   279
                cnx.execute('DELETE CWConstraint C WHERE C eid %(eid)s', {'eid': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   280
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   281
                self.assertFalse(self.schema['Workflow'].has_unique_values('name'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   282
                self.assertFalse(self.index_exists(cnx, 'Workflow', 'name', unique=True))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   283
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   284
    def test_required_change_1(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   285
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   286
            cnx.execute('SET DEF cardinality "?1" '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   287
                         'WHERE DEF relation_type RT, DEF from_entity E,'
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   288
                         'RT name "title", E name "Bookmark"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   289
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   290
            # should now be able to add bookmark without title
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   291
            cnx.execute('INSERT Bookmark X: X path "/view"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   292
            cnx.commit()
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   293
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   294
    def test_required_change_2(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   295
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   296
            cnx.execute('SET DEF cardinality "11" '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   297
                         'WHERE DEF relation_type RT, DEF from_entity E,'
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   298
                         'RT name "surname", E name "CWUser"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   299
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   300
            # should not be able anymore to add cwuser without surname
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   301
            self.assertRaises(ValidationError, self.create_user, cnx, "toto")
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   302
            cnx.rollback()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   303
            cnx.execute('SET DEF cardinality "?1" '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   304
                         'WHERE DEF relation_type RT, DEF from_entity E,'
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   305
                         'RT name "surname", E name "CWUser"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   306
            cnx.commit()
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   307
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   308
    def test_add_attribute_to_base_class(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   309
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   310
            attreid = cnx.execute('INSERT CWAttribute X: X cardinality "11", X defaultval %(default)s, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   311
                                   'X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   312
                                   'WHERE RT name "messageid", E name "BaseTransition", F name "String"',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   313
                                   {'default': Binary.zpickle('noname')})[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   314
            assert cnx.execute('SET X read_permission Y WHERE X eid %(x)s, Y name "managers"',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   315
                               {'x': attreid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   316
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   317
            self.schema.rebuild_infered_relations()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   318
            self.assertIn('Transition', self.schema['messageid'].subjects())
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   319
            self.assertIn('WorkflowTransition', self.schema['messageid'].subjects())
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   320
            cnx.execute('Any X WHERE X is_instance_of BaseTransition, X messageid "hop"')
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   321
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   322
    def test_change_fulltextindexed(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   323
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   324
            target = cnx.create_entity(u'Email', messageid=u'1234',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   325
                                       subject=u'rick.roll@dance.com')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   326
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   327
            rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   328
            self.assertIn(target.eid, [item[0] for item in rset])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   329
            assert cnx.execute('SET A fulltextindexed FALSE '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   330
                               'WHERE E is CWEType, E name "Email", A is CWAttribute,'
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   331
                               'A from_entity E, A relation_type R, R name "subject"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   332
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   333
            rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   334
            self.assertFalse(rset)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   335
            assert cnx.execute('SET A fulltextindexed TRUE '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   336
                               'WHERE A from_entity E, A relation_type R, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   337
                               'E name "Email", R name "subject"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   338
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   339
            rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   340
            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
   341
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
   342
    def test_change_fulltext_container(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   343
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   344
            target = cnx.create_entity(u'EmailAddress', address=u'rick.roll@dance.com')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   345
            target.cw_set(reverse_use_email=cnx.user)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   346
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   347
            rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   348
            self.assertIn(cnx.user.eid, [item[0] for item in rset])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   349
            assert cnx.execute('SET R fulltext_container NULL '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   350
                                'WHERE R name "use_email"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   351
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   352
            rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   353
            self.assertIn(target.eid, [item[0] for item in rset])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   354
            assert cnx.execute('SET R fulltext_container "subject" '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   355
                                'WHERE R name "use_email"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   356
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   357
            rset = cnx.execute('Any X WHERE X has_text "rick.roll"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   358
            self.assertIn(cnx.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
   359
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
   360
    def test_update_constraint(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   361
        with self.admin_access.repo_cnx() as cnx:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   362
            rdef = self.schema['Transition'].rdef('type')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   363
            cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   364
            if not getattr(cstr, 'eid', None):
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   365
                # bug in schema reloading, constraint's eid not restored
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   366
                self.skipTest('start me alone')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   367
            cnx.execute('SET X value %(v)s WHERE X eid %(x)s',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   368
                         {'x': cstr.eid, 'v': u"u'normal', u'auto', u'new'"})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   369
            cnx.execute('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   370
                        'EDEF constrained_by X WHERE CT name %(ct)s, EDEF eid %(x)s',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   371
                         {'ct': 'SizeConstraint', 'value': u'max=10', 'x': rdef.eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   372
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   373
            cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   374
            self.assertEqual(cstr.values, (u'normal', u'auto', u'new'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   375
            cnx.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
   376
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   377
if __name__ == '__main__':
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   378
    unittest_main()