hooks/test/unittest_syncschema.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 21 Jan 2014 18:30:16 +0100
changeset 9548 be001628edad
parent 9463 d62e13eba033
child 9674 96549de9dd70
permissions -rw-r--r--
[schema] fix composite deletion handling Do not delete component entities if the composite is not deleted in the same transaction. Deletion semantics are thus: if the composite is deleted, the components are deleted. Closes #3463112.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8947
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8718
diff changeset
     1
# copyright 2003-2013 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
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    20
from logilab.common.testlib import TestCase, unittest_main
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    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
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
    26
from cubicweb.devtools.repotest import schema_eids_idx, restore_schema_eids_idx
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    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
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    39
    def index_exists(self, etype, attr, unique=False):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
    40
        self.session.set_cnxset()
9463
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
    41
        dbhelper = self.repo.system_source.dbhelper
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
    42
        sqlcursor = self.session.cnxset.cu
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    43
        return dbhelper.index_exists(sqlcursor, SQL_PREFIX + etype, SQL_PREFIX + attr, unique=unique)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    44
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    45
    def _set_perms(self, eid):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    46
        self.execute('SET X read_permission G WHERE X eid %(x)s, G is CWGroup',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
    47
                     {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    48
        self.execute('SET X add_permission G WHERE X eid %(x)s, G is CWGroup, G name "managers"',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
    49
                     {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    50
        self.execute('SET X delete_permission G WHERE X eid %(x)s, G is CWGroup, G name "owners"',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
    51
                     {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    52
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    53
    def _set_attr_perms(self, eid):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    54
        self.execute('SET X read_permission G WHERE X eid %(x)s, G is CWGroup',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
    55
                     {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    56
        self.execute('SET X update_permission G WHERE X eid %(x)s, G is CWGroup, G name "managers"',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
    57
                     {'x': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    58
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    59
    def test_base(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    60
        schema = self.repo.schema
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
    61
        self.session.set_cnxset()
9463
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
    62
        dbhelper = self.repo.system_source.dbhelper
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
    63
        sqlcursor = self.session.cnxset.cu
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    64
        self.assertFalse(schema.has_entity('Societe2'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    65
        self.assertFalse(schema.has_entity('concerne2'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    66
        # schema should be update on insertion (after commit)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    67
        eeid = self.execute('INSERT CWEType X: X name "Societe2", X description "", X final FALSE')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    68
        self._set_perms(eeid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    69
        self.execute('INSERT CWRType X: X name "concerne2", X description "", X final FALSE, X symmetric FALSE')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    70
        self.assertFalse(schema.has_entity('Societe2'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    71
        self.assertFalse(schema.has_entity('concerne2'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    72
        # have to commit before adding definition relations
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    73
        self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    74
        self.assertTrue(schema.has_entity('Societe2'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    75
        self.assertTrue(schema.has_relation('concerne2'))
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
    76
        attreid = self.execute('INSERT CWAttribute X: X cardinality "11", X defaultval %(default)s, '
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    77
                               '   X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
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
    78
                               'WHERE RT name "name", E name "Societe2", F name "String"',
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
    79
                               {'default': Binary.zpickle('noname')})[0][0]
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    80
        self._set_attr_perms(attreid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    81
        concerne2_rdef_eid = self.execute(
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    82
            'INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    83
            'WHERE RT name "concerne2", E name "Societe2"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    84
        self._set_perms(concerne2_rdef_eid)
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    85
        self.assertFalse('name' in schema['Societe2'].subject_relations())
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    86
        self.assertFalse('concerne2' in schema['Societe2'].subject_relations())
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    87
        self.assertFalse(self.index_exists('Societe2', 'name'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    88
        self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    89
        self.assertTrue('name' in schema['Societe2'].subject_relations())
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    90
        self.assertTrue('concerne2' in schema['Societe2'].subject_relations())
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
    91
        self.assertTrue(self.index_exists('Societe2', 'name'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    92
        # now we should be able to insert and query Societe2
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    93
        s2eid = self.execute('INSERT Societe2 X: X name "logilab"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    94
        self.execute('Societe2 X WHERE X name "logilab"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    95
        self.execute('SET X concerne2 X WHERE X name "logilab"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    96
        rset = self.execute('Any X WHERE X concerne2 Y')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
    97
        self.assertEqual(rset.rows, [[s2eid]])
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    98
        # check that when a relation definition is deleted, existing relations are deleted
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    99
        rdefeid = self.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   100
                               '   X from_entity E, X to_entity E '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   101
                               'WHERE RT name "concerne2", E name "CWUser"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   102
        self._set_perms(rdefeid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   103
        self.commit()
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
   104
        self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   105
        self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   106
        self.assertTrue('concerne2' in schema['CWUser'].subject_relations())
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   107
        self.assertFalse('concerne2' in schema['Societe2'].subject_relations())
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   108
        self.assertFalse(self.execute('Any X WHERE X concerne2 Y'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   109
        # schema should be cleaned on delete (after commit)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   110
        self.execute('DELETE CWEType X WHERE X name "Societe2"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   111
        self.execute('DELETE CWRType X WHERE X name "concerne2"')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   112
        self.assertTrue(self.index_exists('Societe2', 'name'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   113
        self.assertTrue(schema.has_entity('Societe2'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   114
        self.assertTrue(schema.has_relation('concerne2'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   115
        self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   116
        self.assertFalse(self.index_exists('Societe2', 'name'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   117
        self.assertFalse(schema.has_entity('Societe2'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   118
        self.assertFalse(schema.has_entity('concerne2'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   119
        self.assertFalse('concerne2' in 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
   120
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
   121
    def test_metartype_with_nordefs(self):
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   122
        META_RTYPES.add('custom_meta')
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   123
        self.execute('INSERT CWRType X: X name "custom_meta", X description "", '
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   124
                     'X final FALSE, X symmetric FALSE')
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   125
        self.commit()
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
        eeid = self.execute('INSERT CWEType X: X name "NEWEtype", '
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   127
                            'X description "", X final FALSE')[0][0]
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   128
        self._set_perms(eeid)
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   129
        self.commit()
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   130
        META_RTYPES.remove('custom_meta')
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   131
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   132
    def test_metartype_with_somerdefs(self):
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   133
        META_RTYPES.add('custom_meta')
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
        self.execute('INSERT CWRType X: X name "custom_meta", X description "", '
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   135
                     'X final FALSE, X symmetric FALSE')
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   136
        self.commit()
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
        rdefeid = self.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, '
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
                               '   X from_entity E, X to_entity E '
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   139
                               'WHERE RT name "custom_meta", E name "CWUser"')[0][0]
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   140
        self._set_perms(rdefeid)
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   141
        self.commit()
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   142
        eeid = self.execute('INSERT CWEType X: X name "NEWEtype", '
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   143
                            'X description "", X final FALSE')[0][0]
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   144
        self._set_perms(eeid)
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
        self.commit()
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
        META_RTYPES.remove('custom_meta')
ab0cd0765076 [hooks/syncschema] do not crash when adding a new entity type (closes #2741643)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7845
diff changeset
   147
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   148
    def test_is_instance_of_insertions(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   149
        seid = self.execute('INSERT Transition T: T name "subdiv"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   150
        is_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is ET, ET name ETN' % seid)]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   151
        self.assertEqual(is_etypes, ['Transition'])
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   152
        instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   153
        self.assertEqual(sorted(instanceof_etypes), ['BaseTransition', 'Transition'])
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   154
        snames = [name for name, in self.execute('Any N WHERE S is BaseTransition, S name N')]
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   155
        self.assertFalse('subdiv' in snames)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   156
        snames = [name for name, in self.execute('Any N WHERE S is_instance_of BaseTransition, S name N')]
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   157
        self.assertTrue('subdiv' in snames)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   158
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   159
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   160
    def test_perms_synchronization_1(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   161
        schema = self.repo.schema
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   162
        self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers', 'users')))
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   163
        self.assertTrue(self.execute('Any X, Y WHERE X is CWEType, X name "CWUser", Y is CWGroup, Y name "users"')[0])
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   164
        self.execute('DELETE X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   165
        self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers', 'users', )))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   166
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   167
        self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers',)))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   168
        self.execute('SET X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   169
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   170
        self.assertEqual(schema['CWUser'].get_groups('read'), set(('managers', 'users',)))
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
    def test_perms_synchronization_2(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   173
        schema = self.repo.schema['in_group'].rdefs[('CWUser', 'CWGroup')]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   174
        self.assertEqual(schema.get_groups('read'), 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
   175
        self.execute('DELETE X read_permission Y WHERE X relation_type RT, RT name "in_group", Y name "guests"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   176
        self.assertEqual(schema.get_groups('read'), 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
   177
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   178
        self.assertEqual(schema.get_groups('read'), set(('managers', 'users')))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   179
        self.execute('SET X read_permission Y WHERE X relation_type RT, RT name "in_group", Y name "guests"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   180
        self.assertEqual(schema.get_groups('read'), set(('managers', 'users')))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   181
        self.commit()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   182
        self.assertEqual(schema.get_groups('read'), 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
   183
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   184
    def test_nonregr_user_edit_itself(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   185
        ueid = self.session.user.eid
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   186
        groupeids = [eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   187
        self.execute('DELETE X in_group Y WHERE X eid %s' % ueid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   188
        self.execute('SET X surname "toto" WHERE X eid %s' % ueid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   189
        self.execute('SET X in_group Y WHERE X eid %s, Y name "managers"' % ueid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   190
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   191
        eeid = self.execute('Any X WHERE X is CWEType, X name "CWEType"')[0][0]
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   192
        self.execute('DELETE X read_permission Y WHERE X eid %s' % eeid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   193
        self.execute('SET X final FALSE WHERE X eid %s' % eeid)
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   194
        self.execute('SET X read_permission Y WHERE X eid %s, Y eid in (%s, %s)'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   195
                     % (eeid, groupeids[0], groupeids[1]))
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   196
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   197
        self.execute('Any X WHERE X is CWEType, X name "CWEType"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   198
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   199
    # schema modification hooks tests #########################################
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   200
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   201
    def test_uninline_relation(self):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
   202
        self.session.set_cnxset()
9463
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
   203
        dbhelper = self.repo.system_source.dbhelper
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
   204
        sqlcursor = self.session.cnxset.cu
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   205
        self.assertTrue(self.schema['state_of'].inlined)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   206
        try:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   207
            self.execute('SET X inlined FALSE WHERE X name "state_of"')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   208
            self.assertTrue(self.schema['state_of'].inlined)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   209
            self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   210
            self.assertFalse(self.schema['state_of'].inlined)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   211
            self.assertFalse(self.index_exists('State', 'state_of'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   212
            rset = self.execute('Any X, Y WHERE X state_of Y')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   213
            self.assertEqual(len(rset), 2) # user states
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   214
        except Exception:
5891
99024ad59223 [schema migration] import refactoring to fix #1109558 and enhances things on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   215
            import traceback
99024ad59223 [schema migration] import refactoring to fix #1109558 and enhances things on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   216
            traceback.print_exc()
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   217
        finally:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   218
            self.execute('SET X inlined TRUE WHERE X name "state_of"')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   219
            self.assertFalse(self.schema['state_of'].inlined)
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   220
            self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   221
            self.assertTrue(self.schema['state_of'].inlined)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   222
            self.assertTrue(self.index_exists('State', 'state_of'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   223
            rset = self.execute('Any X, Y WHERE X state_of Y')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   224
            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
   225
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   226
    def test_indexed_change(self):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
   227
        self.session.set_cnxset()
9463
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
   228
        dbhelper = self.repo.system_source.dbhelper
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
   229
        sqlcursor = self.session.cnxset.cu
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   230
        try:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   231
            self.execute('SET X indexed FALSE WHERE X relation_type R, R name "name"')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   232
            self.assertTrue(self.schema['name'].rdef('Workflow', 'String').indexed)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   233
            self.assertTrue(self.index_exists('Workflow', 'name'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   234
            self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   235
            self.assertFalse(self.schema['name'].rdef('Workflow', 'String').indexed)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   236
            self.assertFalse(self.index_exists('Workflow', 'name'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   237
        finally:
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   238
            self.execute('SET X indexed TRUE WHERE X relation_type R, R name "name"')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   239
            self.assertFalse(self.schema['name'].rdef('Workflow', 'String').indexed)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   240
            self.assertFalse(self.index_exists('Workflow', 'name'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   241
            self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   242
            self.assertTrue(self.schema['name'].rdef('Workflow', 'String').indexed)
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   243
            self.assertTrue(self.index_exists('Workflow', 'name'))
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   244
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   245
    def test_unique_change(self):
7398
26695dd703d8 [repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7244
diff changeset
   246
        self.session.set_cnxset()
9463
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
   247
        dbhelper = self.repo.system_source.dbhelper
d62e13eba033 [multi-sources-removal] Simplify ConnectionsSet internal structures and public methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9402
diff changeset
   248
        sqlcursor = self.session.cnxset.cu
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   249
        try:
9548
be001628edad [schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9463
diff changeset
   250
            eid = self.execute('INSERT CWConstraint X: X cstrtype CT, DEF constrained_by X '
be001628edad [schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9463
diff changeset
   251
                               'WHERE CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,'
be001628edad [schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9463
diff changeset
   252
                               'RT name "name", E name "Workflow"').rows[0][0]
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   253
            self.assertFalse(self.schema['Workflow'].has_unique_values('name'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   254
            self.assertFalse(self.index_exists('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
   255
            self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   256
            self.assertTrue(self.schema['Workflow'].has_unique_values('name'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   257
            self.assertTrue(self.index_exists('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
   258
        finally:
9548
be001628edad [schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9463
diff changeset
   259
            self.execute('DELETE CWConstraint C WHERE C eid %(eid)s', {'eid': eid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   260
            self.commit()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   261
            self.assertFalse(self.schema['Workflow'].has_unique_values('name'))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   262
            self.assertFalse(self.index_exists('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
   263
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   264
    def test_required_change_1(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   265
        self.execute('SET DEF cardinality "?1" '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   266
                     'WHERE DEF relation_type RT, DEF from_entity E,'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   267
                     'RT name "title", E name "Bookmark"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   268
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   269
        # should now be able to add bookmark without title
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   270
        self.execute('INSERT Bookmark X: X path "/view"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   271
        self.commit()
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_required_change_2(self):
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   274
        self.execute('SET DEF cardinality "11" '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   275
                     'WHERE DEF relation_type RT, DEF from_entity E,'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   276
                     'RT name "surname", E name "CWUser"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   277
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   278
        # should not be able anymore to add cwuser without surname
7244
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7078
diff changeset
   279
        req = self.request()
a918f76441ce fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7078
diff changeset
   280
        self.assertRaises(ValidationError, self.create_user, req, "toto")
6410
2e7a7b0829ed [test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   281
        self.rollback()
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   282
        self.execute('SET DEF cardinality "?1" '
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   283
                     'WHERE DEF relation_type RT, DEF from_entity E,'
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   284
                     'RT name "surname", E name "CWUser"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   285
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   286
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   287
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   288
    def test_add_attribute_to_base_class(self):
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
   289
        attreid = self.execute('INSERT CWAttribute X: X cardinality "11", X defaultval %(default)s, '
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
   290
                               'X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
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
   291
                               'WHERE RT name "messageid", E name "BaseTransition", F name "String"',
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
   292
                               {'default': Binary.zpickle('noname')})[0][0]
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   293
        assert self.execute('SET X read_permission Y WHERE X eid %(x)s, Y name "managers"',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
   294
                     {'x': attreid})
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   295
        self.commit()
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   296
        self.schema.rebuild_infered_relations()
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   297
        self.assertTrue('Transition' in self.schema['messageid'].subjects())
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   298
        self.assertTrue('WorkflowTransition' in self.schema['messageid'].subjects())
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   299
        self.execute('Any X WHERE X is_instance_of BaseTransition, X messageid "hop"')
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   300
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   301
    def test_change_fulltextindexed(self):
4826
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   302
        req = self.request()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   303
        target = req.create_entity(u'Email', messageid=u'1234',
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   304
                                   subject=u'rick.roll@dance.com')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   305
        self.commit()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   306
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   307
        self.assertIn(target.eid, [item[0] for item in rset])
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   308
        assert req.execute('SET A fulltextindexed FALSE '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   309
                            'WHERE E is CWEType, E name "Email", A is CWAttribute,'
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   310
                            'A from_entity E, A relation_type R, R name "subject"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   311
        self.commit()
4840
c02a340cd1da cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4826
diff changeset
   312
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7398
diff changeset
   313
        self.assertFalse(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
   314
        assert req.execute('SET A fulltextindexed TRUE '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   315
                           'WHERE A from_entity E, A relation_type R, '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   316
                           'E name "Email", R name "subject"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   317
        self.commit()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   318
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   319
        self.assertIn(target.eid, [item[0] for item in rset])
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   320
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
   321
    def test_change_fulltext_container(self):
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   322
        req = self.request()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   323
        target = req.create_entity(u'EmailAddress', address=u'rick.roll@dance.com')
8483
4ba11607d84a [entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845
diff changeset
   324
        target.cw_set(reverse_use_email=req.user)
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
   325
        self.commit()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   326
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   327
        self.assertIn(req.user.eid, [item[0] for item in rset])
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   328
        assert self.execute('SET R fulltext_container NULL '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   329
                            'WHERE R name "use_email"')
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   330
        self.commit()
4840
c02a340cd1da cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4826
diff changeset
   331
        rset = self.execute('Any X WHERE X has_text "rick.roll"')
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   332
        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
   333
        assert self.execute('SET R fulltext_container "subject" '
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   334
                            'WHERE R name "use_email"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   335
        self.commit()
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   336
        rset = req.execute('Any X WHERE X has_text "rick.roll"')
7eba168407c3 [schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   337
        self.assertIn(req.user.eid, [item[0] for item in rset])
4667
6c8eccb1b695 [fix] Apply fulltextindexed change in the actual index
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   338
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
   339
    def test_update_constraint(self):
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   340
        rdef = self.schema['Transition'].rdef('type')
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   341
        cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   342
        if not getattr(cstr, 'eid', None):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   343
            self.skipTest('start me alone') # bug in schema reloading, constraint's eid not restored
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
   344
        self.execute('SET X value %(v)s WHERE X eid %(x)s',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
   345
                     {'x': cstr.eid, 'v': u"u'normal', u'auto', u'new'"})
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
   346
        self.execute('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   347
                     'WHERE CT name %(ct)s, EDEF eid %(x)s',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4984
diff changeset
   348
                     {'ct': 'SizeConstraint', 'value': u'max=10', 'x': rdef.eid})
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
   349
        self.commit()
19fd1952ad63 [schema sync] test and fix bug when updating multiple constraint for the same rdef in the same transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4840
diff changeset
   350
        cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5891
diff changeset
   351
        self.assertEqual(cstr.values, (u'normal', u'auto', u'new'))
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
   352
        self.execute('INSERT Transition T: T name "hop", T type "new"')
4968
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   353
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   354
if __name__ == '__main__':
79d80cfaab6f missing unittest_main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4927
diff changeset
   355
    unittest_main()