hooks/test/unittest_syncschema.py
author Julien Cristau <julien.cristau@logilab.fr>
Fri, 26 Jun 2015 14:04:16 +0200
changeset 10472 7dd84b69c7d4
parent 10442 b2d2099dfae8
child 10813 ab626726a70a
permissions -rw-r--r--
[devtools] avoid warning about source['global-db-name'] sqlite and postgres db handlers store the db template name there.
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
10442
b2d2099dfae8 [test] run unittest_syncschema with postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10436
diff changeset
    24
from cubicweb.devtools import startpgcluster, stoppgcluster, PostgresApptestConfiguration
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
    25
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
    26
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
    27
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
    28
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
    29
10442
b2d2099dfae8 [test] run unittest_syncschema with postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10436
diff changeset
    30
def setUpModule():
b2d2099dfae8 [test] run unittest_syncschema with postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10436
diff changeset
    31
    startpgcluster(__file__)
b2d2099dfae8 [test] run unittest_syncschema with postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10436
diff changeset
    32
b2d2099dfae8 [test] run unittest_syncschema with postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10436
diff changeset
    33
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6412
diff changeset
    34
def tearDownModule(*args):
10442
b2d2099dfae8 [test] run unittest_syncschema with postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10436
diff changeset
    35
    stoppgcluster(__file__)
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
    36
    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
    37
10442
b2d2099dfae8 [test] run unittest_syncschema with postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10436
diff changeset
    38
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    39
class SchemaModificationHooksTC(CubicWebTC):
10442
b2d2099dfae8 [test] run unittest_syncschema with postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10436
diff changeset
    40
    configcls = PostgresApptestConfiguration
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    41
7078
bad26a22fe29 [test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6781
diff changeset
    42
    def setUp(self):
bad26a22fe29 [test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6781
diff changeset
    43
        super(SchemaModificationHooksTC, self).setUp()
8947
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8718
diff changeset
    44
        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
    45
        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
    46
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    47
    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
    48
        dbhelper = self.repo.system_source.dbhelper
10365
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    49
        sqlcursor = cnx.cnxset.cu
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    50
        return dbhelper.index_exists(sqlcursor,
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    51
                                     SQL_PREFIX + etype,
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    52
                                     SQL_PREFIX + attr,
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    53
                                     unique=unique)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    54
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    55
    def _set_perms(self, cnx, eid):
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    56
        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
    57
                    {'x': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    58
        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
    59
                    'G name "managers"', {'x': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    60
        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
    61
                    '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
    62
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    63
    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
    64
        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
    65
                    {'x': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    66
        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
    67
                    {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    68
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    69
    def test_base(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    70
        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
    71
            schema = self.repo.schema
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    72
            self.assertFalse(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    73
            self.assertFalse(schema.has_entity('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    74
            # 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
    75
            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
    76
                               '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
    77
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    78
            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
    79
                        'X final FALSE, X symmetric FALSE')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    80
            self.assertFalse(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    81
            self.assertFalse(schema.has_entity('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    82
            # 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
    83
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    84
            self.assertTrue(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    85
            self.assertTrue(schema.has_relation('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    86
            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
    87
                                  '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
    88
                                  '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
    89
                                   '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
    90
                                  'F name "String"',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    91
                                   {'default': Binary.zpickle('noname')})[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    92
            self._set_attr_perms(cnx, attreid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    93
            concerne2_rdef_eid = cnx.execute(
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    94
                '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
    95
                '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
    96
                '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
    97
            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
    98
            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
    99
            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
   100
            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
   101
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   102
            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
   103
            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
   104
            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
   105
            # 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
   106
            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
   107
            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
   108
            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
   109
            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
   110
            self.assertEqual(rset.rows, [[s2eid]])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   111
            # 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
   112
            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
   113
                                   '   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
   114
                                   '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
   115
            self._set_perms(cnx, rdefeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   116
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   117
            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
   118
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   119
            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
   120
            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
   121
            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
   122
            # 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
   123
            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
   124
            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
   125
            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
   126
            self.assertTrue(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   127
            self.assertTrue(schema.has_relation('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   128
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   129
            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
   130
            self.assertFalse(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   131
            self.assertFalse(schema.has_entity('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   132
            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
   133
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
   134
    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
   135
        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
   136
            META_RTYPES.add('custom_meta')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   137
            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
   138
                         'X final FALSE, X symmetric FALSE')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   139
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   140
            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
   141
                                '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
   142
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   143
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   144
            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
   145
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   146
    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
   147
        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
   148
            META_RTYPES.add('custom_meta')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   149
            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
   150
                         'X final FALSE, X symmetric FALSE')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   151
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   152
            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
   153
                                   '   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
   154
                                   '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
   155
            self._set_perms(cnx, rdefeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   156
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   157
            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
   158
                                '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
   159
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   160
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   161
            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
   162
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   163
    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
   164
        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
   165
            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
   166
            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
   167
                                                         '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
   168
            self.assertEqual(is_etypes, ['Transition'])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   169
            instanceof_etypes = [etype
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   170
                                 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
   171
                                                           '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
   172
                                                           % seid)]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   173
            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
   174
            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
   175
            self.assertNotIn('subdiv', snames)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   176
            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
   177
                                                    'S name N')]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   178
            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
   179
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   180
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   181
    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
   182
        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
   183
            schema = self.repo.schema
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   184
            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
   185
            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
   186
                                        '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
   187
            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
   188
            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
   189
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   190
            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
   191
            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
   192
                        'X name "CWUser", Y name "users"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   193
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   194
            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
   195
                             set(('managers', 'users',)))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   196
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   197
    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
   198
        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
   199
            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
   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', 'guests')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   202
            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
   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', 'guests')))
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')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   209
            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
   210
                        '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
   211
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   212
                             set(('managers', 'users')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   213
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   214
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   215
                             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
   216
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   217
    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
   218
        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
   219
            ueid = cnx.user.eid
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   220
            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
   221
                                                     'in ("managers", "users")')]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   222
            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
   223
            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
   224
            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
   225
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   226
            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
   227
            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
   228
            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
   229
            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
   230
                         % (eeid, groupeids[0], groupeids[1]))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   231
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   232
            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
   233
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   234
    # schema modification hooks tests #########################################
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   235
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   236
    def test_uninline_relation(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   237
        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
   238
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   239
                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
   240
                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
   241
                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
   242
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   243
                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
   244
                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
   245
                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
   246
                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
   247
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   248
                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
   249
                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
   250
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   251
                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
   252
                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
   253
                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
   254
                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
   255
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   256
    def test_indexed_change(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   257
        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
   258
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   259
                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
   260
                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
   261
                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
   262
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   263
                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
   264
                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
   265
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   266
                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
   267
                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
   268
                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
   269
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   270
                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
   271
                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
   272
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   273
    def test_unique_change(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   274
        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
   275
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   276
                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
   277
                                  '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
   278
                                  '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
   279
                                  'E name "Workflow"').rows[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   280
                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
   281
                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
   282
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   283
                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
   284
                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
   285
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   286
                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
   287
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   288
                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
   289
                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
   290
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   291
    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
   292
        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
   293
            cnx.execute('SET DEF cardinality "?1" '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   294
                         '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
   295
                         'RT name "title", E name "Bookmark"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   296
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   297
            # 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
   298
            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
   299
            cnx.commit()
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   300
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   301
    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
   302
        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
   303
            cnx.execute('SET DEF cardinality "11" '
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"')
10436
6493c8bf521d [test] don't leave NULL columns around when making an attribute required
Julien Cristau <julien.cristau@logilab.fr>
parents: 10365
diff changeset
   306
            cnx.execute('SET U surname "Doe" WHERE U surname NULL')
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   307
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   308
            # 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
   309
            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
   310
            cnx.rollback()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   311
            cnx.execute('SET DEF cardinality "?1" '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   312
                         '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
   313
                         'RT name "surname", E name "CWUser"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   314
            cnx.commit()
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   315
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   316
    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
   317
        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
   318
            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
   319
                                   '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
   320
                                   '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
   321
                                   {'default': Binary.zpickle('noname')})[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   322
            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
   323
                               {'x': attreid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   324
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   325
            self.schema.rebuild_infered_relations()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   326
            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
   327
            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
   328
            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
   329
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   330
    def test_change_fulltextindexed(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   331
        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
   332
            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
   333
                                       subject=u'rick.roll@dance.com')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   334
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   335
            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
   336
            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
   337
            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
   338
                               '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
   339
                               '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
   340
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   341
            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
   342
            self.assertFalse(rset)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   343
            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
   344
                               '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
   345
                               'E name "Email", R name "subject"')
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(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
   349
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
   350
    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
   351
        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
   352
            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
   353
            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
   354
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   355
            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
   356
            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
   357
            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
   358
                                'WHERE R name "use_email"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   359
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   360
            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
   361
            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
   362
            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
   363
                                'WHERE R name "use_email"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   364
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   365
            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
   366
            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
   367
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
   368
    def test_update_constraint(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   369
        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
   370
            rdef = self.schema['Transition'].rdef('type')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   371
            cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   372
            if not getattr(cstr, 'eid', None):
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   373
                # 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
   374
                self.skipTest('start me alone')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   375
            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
   376
                         {'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
   377
            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
   378
                        '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
   379
                         {'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
   380
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   381
            cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   382
            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
   383
            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
   384
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   385
if __name__ == '__main__':
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   386
    unittest_main()