hooks/test/unittest_syncschema.py
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 18 May 2015 20:00:06 +0200
changeset 10436 6493c8bf521d
parent 10365 21461f80f348
child 10442 b2d2099dfae8
permissions -rw-r--r--
[test] don't leave NULL columns around when making an attribute required It doesn't matter on sqlite (it doesn't do ALTER COLUMN), but when running this test on postgresql it fails to add the 'NOT NULL' constraint otherwise.
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
10365
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    41
        sqlcursor = cnx.cnxset.cu
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    42
        return dbhelper.index_exists(sqlcursor,
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    43
                                     SQL_PREFIX + etype,
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    44
                                     SQL_PREFIX + attr,
21461f80f348 [connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9851
diff changeset
    45
                                     unique=unique)
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 _set_perms(self, cnx, eid):
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    48
        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
    49
                    {'x': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    50
        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
    51
                    'G name "managers"', {'x': eid})
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    52
        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
    53
                    '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
    54
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    55
    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
    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 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
    59
                    {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    60
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    61
    def test_base(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    62
        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
    63
            schema = self.repo.schema
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    64
            self.assertFalse(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    65
            self.assertFalse(schema.has_entity('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    66
            # 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
    67
            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
    68
                               '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
    69
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    70
            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
    71
                        'X final FALSE, X symmetric FALSE')
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
            # 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
    75
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    76
            self.assertTrue(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    77
            self.assertTrue(schema.has_relation('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    78
            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
    79
                                  '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
    80
                                  '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
    81
                                   '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
    82
                                  'F name "String"',
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    83
                                   {'default': Binary.zpickle('noname')})[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    84
            self._set_attr_perms(cnx, attreid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    85
            concerne2_rdef_eid = cnx.execute(
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    86
                '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
    87
                '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
    88
                '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
    89
            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
    90
            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
    91
            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
    92
            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
    93
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    94
            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
    95
            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
    96
            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
    97
            # 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
    98
            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
    99
            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
   100
            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
   101
            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
   102
            self.assertEqual(rset.rows, [[s2eid]])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   103
            # 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
   104
            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
   105
                                   '   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
   106
                                   '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
   107
            self._set_perms(cnx, rdefeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   108
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   109
            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
   110
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   111
            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
   112
            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
   113
            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
   114
            # 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
   115
            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
   116
            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
   117
            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
   118
            self.assertTrue(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   119
            self.assertTrue(schema.has_relation('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   120
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   121
            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
   122
            self.assertFalse(schema.has_entity('Societe2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   123
            self.assertFalse(schema.has_entity('concerne2'))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   124
            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
   125
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
   126
    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
   127
        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
   128
            META_RTYPES.add('custom_meta')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   129
            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
   130
                         'X final FALSE, X symmetric FALSE')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   131
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   132
            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
   133
                                '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
   134
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   135
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   136
            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
   137
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
    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
   139
        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
   140
            META_RTYPES.add('custom_meta')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   141
            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
   142
                         'X final FALSE, X symmetric FALSE')
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
            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
   145
                                   '   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
   146
                                   '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
   147
            self._set_perms(cnx, rdefeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   148
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   149
            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
   150
                                '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
   151
            self._set_perms(cnx, eeid)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   152
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   153
            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
   154
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   155
    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
   156
        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
   157
            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
   158
            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
   159
                                                         '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
   160
            self.assertEqual(is_etypes, ['Transition'])
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   161
            instanceof_etypes = [etype
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   162
                                 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
   163
                                                           '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
   164
                                                           % seid)]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   165
            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
   166
            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
   167
            self.assertNotIn('subdiv', snames)
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   168
            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
   169
                                                    'S name N')]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   170
            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
   171
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
    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
   174
        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
   175
            schema = self.repo.schema
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   176
            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
   177
            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
   178
                                        '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
   179
            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
   180
            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
   181
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   182
            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
   183
            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
   184
                        'X name "CWUser", Y name "users"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   185
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   186
            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
   187
                             set(('managers', 'users',)))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   188
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   189
    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
   190
        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
   191
            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
   192
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   193
                             set(('managers', 'users', 'guests')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   194
            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
   195
                        '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
   196
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   197
                             set(('managers', 'users', 'guests')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   198
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   199
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   200
                             set(('managers', 'users')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   201
            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
   202
                        '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
   203
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   204
                             set(('managers', 'users')))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   205
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   206
            self.assertEqual(schema.get_groups('read'),
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   207
                             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
   208
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   209
    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
   210
        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
   211
            ueid = cnx.user.eid
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   212
            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
   213
                                                     'in ("managers", "users")')]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   214
            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
   215
            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
   216
            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
   217
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   218
            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
   219
            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
   220
            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
   221
            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
   222
                         % (eeid, groupeids[0], groupeids[1]))
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   223
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   224
            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
   225
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   226
    # schema modification hooks tests #########################################
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   227
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   228
    def test_uninline_relation(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   229
        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
   230
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   231
                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
   232
                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
   233
                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
   234
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   235
                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
   236
                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
   237
                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
   238
                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
   239
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   240
                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
   241
                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
   242
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   243
                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
   244
                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
   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)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   247
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   248
    def test_indexed_change(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   249
        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
   250
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   251
                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
   252
                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
   253
                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
   254
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   255
                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
   256
                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
   257
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   258
                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
   259
                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
   260
                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
   261
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   262
                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
   263
                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
   264
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   265
    def test_unique_change(self):
9851
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   266
        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
   267
            try:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   268
                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
   269
                                  '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
   270
                                  '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
   271
                                  'E name "Workflow"').rows[0][0]
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   272
                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
   273
                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
   274
                cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   275
                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
   276
                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
   277
            finally:
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   278
                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
   279
                cnx.commit()
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))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   282
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   283
    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
   284
        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
   285
            cnx.execute('SET DEF cardinality "?1" '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   286
                         '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
   287
                         'RT name "title", E name "Bookmark"')
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   288
            cnx.commit()
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   289
            # 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
   290
            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
   291
            cnx.commit()
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   292
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   293
    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
   294
        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
   295
            cnx.execute('SET DEF cardinality "11" '
42a874c666b1 [hookstests/syncschema] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   296
                         '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
   297
                         '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
   298
            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
   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()