cubicweb/server/test/unittest_migractions.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 05 Apr 2019 17:58:19 +0200
changeset 12567 26744ad37953
parent 12545 be36811f0d08
child 12742 ca698656251c
permissions -rw-r--r--
Drop python2 support This mostly consists in removing the dependency on "six" and updating the code to use only Python3 idioms. Notice that we previously used TemporaryDirectory from cubicweb.devtools.testlib for compatibility with Python2. We now directly import it from tempfile.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12237
2dd0dcb2e5f9 [test] Drop no more used "maxeid" based deletion in BaseQuerierTC and derived tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11929
diff changeset
     1
# copyright 2003 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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
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: 4774
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6595
00cd0b273cf5 [test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
    18
"""unit tests for module cubicweb.server.migractions"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
11292
ba81a528722b [test] Add missing os import in unittest_migractions.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11291
diff changeset
    20
import os
11288
ab0a1863248e [server] some pep8 changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11112
diff changeset
    21
import os.path as osp
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    22
import sys
1016
26387b836099 use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents: 972
diff changeset
    23
from datetime import date
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    24
from contextlib import contextmanager
12567
26744ad37953 Drop python2 support
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12545
diff changeset
    25
from tempfile import TemporaryDirectory
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
10917
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
    27
from logilab.common import tempattr
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
6292
054fa36060d5 [migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6208
diff changeset
    29
from yams.constraints import UniqueConstraint
054fa36060d5 [migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6208
diff changeset
    30
11273
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
    31
from cubicweb import (ConfigurationError, ValidationError,
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
    32
                      ExecutionError, Binary)
10441
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    33
from cubicweb.devtools import startpgcluster, stoppgcluster
12567
26744ad37953 Drop python2 support
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12545
diff changeset
    34
from cubicweb.devtools.testlib import CubicWebTC
12512
661dd0436c01 [schema] drop monkeypatch "name_for" on BaseConstraint
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12239
diff changeset
    35
from cubicweb.schema import constraint_name_for
1251
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 972
diff changeset
    36
from cubicweb.server.sqlutils import SQL_PREFIX
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
    37
from cubicweb.server.migractions import ServerMigrationHelper
11273
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
    38
from cubicweb.server.sources import storages
11362
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
    39
from cubicweb.server.schema2sql import build_index_name
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
8935
a8a9ba6f4cdd [server/test] use server config in migration
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8696
diff changeset
    41
import cubicweb.devtools
a8a9ba6f4cdd [server/test] use server config in migration
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8696
diff changeset
    42
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
    43
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
    44
HERE = osp.dirname(osp.abspath(__file__))
11288
ab0a1863248e [server] some pep8 changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11112
diff changeset
    45
migrschema = None
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
    46
10441
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    47
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    48
def setUpModule():
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    49
    startpgcluster(__file__)
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    50
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    51
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6635
diff changeset
    52
def tearDownModule(*args):
4774
89a7555020ba [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4763
diff changeset
    53
    global migrschema
89a7555020ba [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4763
diff changeset
    54
    del migrschema
7073
4ce9e536dd66 [test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6816
diff changeset
    55
    if hasattr(MigrationCommandsTC, 'origschema'):
4ce9e536dd66 [test] add some tags
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6816
diff changeset
    56
        del MigrationCommandsTC.origschema
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
    57
    if hasattr(MigrationCommandsComputedTC, 'origschema'):
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
    58
        del MigrationCommandsComputedTC.origschema
10441
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    59
    stoppgcluster(__file__)
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    60
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    61
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    62
class MigrationConfig(cubicweb.devtools.TestServerConfiguration):
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    63
    default_sources = cubicweb.devtools.DEFAULT_PSQL_SOURCES
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    64
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    65
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
    66
class MigrationTC(CubicWebTC):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2745
diff changeset
    67
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
    68
    appid = 'data-migractions'
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
    69
10441
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
    70
    configcls = MigrationConfig
8935
a8a9ba6f4cdd [server/test] use server config in migration
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8696
diff changeset
    71
9043
97c3bb9a7c99 [testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8947
diff changeset
    72
    def _init_repo(self):
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
    73
        super(MigrationTC, self)._init_repo()
4681
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4635
diff changeset
    74
        # we have to read schema from the database to get eid for schema entities
9043
97c3bb9a7c99 [testlib] move repo and related attribute back on Instance instead of Class
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8947
diff changeset
    75
        self.repo.set_schema(self.repo.deserialize_schema(), resetvreg=False)
8947
3bbd416b09ec [repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8942
diff changeset
    76
        # hack to read the schema from data/migrschema
11899
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    77
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    78
        @contextmanager
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    79
        def temp_app(config, appid, apphome):
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    80
            old = config.apphome, config.appid
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    81
            sys.path.remove(old[0])
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    82
            sys.path.insert(0, apphome)
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    83
            config._apphome, config.appid = apphome, appid
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    84
            try:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    85
                yield config
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    86
            finally:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    87
                sys.path.remove(apphome)
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    88
                sys.path.insert(0, old[0])
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    89
                config._apphome, config.appid = old
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    90
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    91
        appid = osp.join(self.appid, 'migratedapp')
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    92
        apphome = osp.join(HERE, appid)
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    93
        with temp_app(self.config, appid, apphome) as config:
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    94
            global migrschema
bf6106b91633 [schema] load schema from modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 11767
diff changeset
    95
            migrschema = config.load_schema()
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2745
diff changeset
    96
6795
f29d24c3d687 [server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6790
diff changeset
    97
    def tearDown(self):
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
    98
        super(MigrationTC, self).tearDown()
6795
f29d24c3d687 [server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6790
diff changeset
    99
        self.repo.vreg['etypes'].clear_caches()
f29d24c3d687 [server test] fix test inter-dependancy issue
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6790
diff changeset
   100
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   101
    @contextmanager
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   102
    def mh(self):
10353
d9a1e7939ee6 [migractions] remove any session related leftovers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10257
diff changeset
   103
        with self.admin_access.repo_cnx() as cnx:
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   104
            yield cnx, ServerMigrationHelper(self.repo.config, migrschema,
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   105
                                             repo=self.repo, cnx=cnx,
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   106
                                             interactive=False)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   107
9963
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   108
    def table_sql(self, mh, tablename):
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   109
        result = mh.sqlexec(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   110
            "SELECT table_name FROM information_schema.tables WHERE LOWER(table_name)=%(table)s",
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   111
            {'table': tablename.lower()})
9963
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   112
        if result:
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   113
            return result[0][0]
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   114
        return None  # no such table
9963
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   115
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   116
    def table_schema(self, mh, tablename):
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   117
        result = mh.sqlexec(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   118
            "SELECT column_name, data_type, character_maximum_length "
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   119
            "FROM information_schema.columns "
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   120
            "WHERE LOWER(table_name) = %(table)s", {'table': tablename.lower()})
10441
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
   121
        assert result, 'no table %s' % tablename
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
   122
        return dict((x[0], (x[1], x[2])) for x in result)
9963
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   123
11414
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   124
    def table_constraints(self, mh, tablename):
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   125
        result = mh.sqlexec(
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   126
            "SELECT DISTINCT constraint_name FROM information_schema.constraint_column_usage "
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   127
            "WHERE LOWER(table_name) = '%(table)s' AND constraint_name LIKE 'cstr%%'"
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   128
            % {'table': tablename.lower()})
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   129
        assert result, 'no table %s' % tablename
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   130
        return set(x[0] for x in result)
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   131
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   132
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   133
class MigrationCommandsTC(MigrationTC):
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   134
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   135
    def _init_repo(self):
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   136
        super(MigrationCommandsTC, self)._init_repo()
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   137
        assert 'Folder' in migrschema
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   138
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: 9273
diff changeset
   139
    def test_add_attribute_bool(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   140
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   141
            self.assertNotIn('yesno', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   142
            cnx.create_entity('Note')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   143
            cnx.commit()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   144
            mh.cmd_add_attribute('Note', 'yesno')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   145
            self.assertIn('yesno', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   146
            self.assertEqual(self.schema['yesno'].subjects(), ('Note',))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   147
            self.assertEqual(self.schema['yesno'].objects(), ('Boolean',))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   148
            self.assertEqual(self.schema['Note'].default('yesno'), False)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   149
            # test default value set on existing entities
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   150
            note = cnx.execute('Note X').get_entity(0, 0)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   151
            self.assertEqual(note.yesno, False)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   152
            # test default value set for next entities
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   153
            self.assertEqual(cnx.create_entity('Note').yesno, False)
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: 9273
diff changeset
   154
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
    def test_add_attribute_int(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   156
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   157
            self.assertNotIn('whatever', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   158
            cnx.create_entity('Note')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   159
            cnx.commit()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   160
            orderdict = dict(mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, '
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   161
                                        'RDEF relation_type RT, RDEF ordernum O, RT name RTN'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   162
            mh.cmd_add_attribute('Note', 'whatever')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   163
            self.assertIn('whatever', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   164
            self.assertEqual(self.schema['whatever'].subjects(), ('Note',))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   165
            self.assertEqual(self.schema['whatever'].objects(), ('Int',))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   166
            self.assertEqual(self.schema['Note'].default('whatever'), 0)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   167
            # test default value set on existing entities
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   168
            note = cnx.execute('Note X').get_entity(0, 0)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   169
            self.assertIsInstance(note.whatever, int)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   170
            self.assertEqual(note.whatever, 0)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   171
            # test default value set for next entities
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   172
            self.assertEqual(cnx.create_entity('Note').whatever, 0)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   173
            # test attribute order
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   174
            orderdict2 = dict(mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, '
3134
3cda74b5534c update test to avoid failure due to migration schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3126
diff changeset
   175
                                         'RDEF relation_type RT, RDEF ordernum O, RT name RTN'))
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   176
            whateverorder = migrschema['whatever'].rdef('Note', 'Int').order
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10646
diff changeset
   177
            for k, v in orderdict.items():
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   178
                if v >= whateverorder:
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   179
                    orderdict[k] = v + 1
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   180
            orderdict['whatever'] = whateverorder
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   181
            self.assertDictEqual(orderdict, orderdict2)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
    def test_add_attribute_varchar(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   184
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   185
            self.assertNotIn('whatever', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   186
            cnx.create_entity('Note')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   187
            cnx.commit()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   188
            self.assertNotIn('shortpara', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   189
            mh.cmd_add_attribute('Note', 'shortpara')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   190
            self.assertIn('shortpara', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   191
            self.assertEqual(self.schema['shortpara'].subjects(), ('Note', ))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   192
            self.assertEqual(self.schema['shortpara'].objects(), ('String', ))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   193
            # test created column is actually a varchar(64)
9963
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   194
            fields = self.table_schema(mh, '%sNote' % SQL_PREFIX)
11415
f87da59faea1 [migration] Test and fix case of addition of an attribute with some serialized constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11414
diff changeset
   195
            self.assertEqual(fields['%sshortpara' % SQL_PREFIX], ('character varying', 11))
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   196
            # test default value set on existing entities
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   197
            self.assertEqual(cnx.execute('Note X').get_entity(0, 0).shortpara, 'hop')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   198
            # test default value set for next entities
11415
f87da59faea1 [migration] Test and fix case of addition of an attribute with some serialized constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11414
diff changeset
   199
            self.assertEqual(cnx.create_entity('Note', shortpara=u'hop hop').shortpara, u'hop hop')
f87da59faea1 [migration] Test and fix case of addition of an attribute with some serialized constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11414
diff changeset
   200
            # serialized constraint added
f87da59faea1 [migration] Test and fix case of addition of an attribute with some serialized constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11414
diff changeset
   201
            constraints = self.table_constraints(mh, 'cw_Personne')
f87da59faea1 [migration] Test and fix case of addition of an attribute with some serialized constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11414
diff changeset
   202
            self.assertEqual(len(constraints), 1, constraints)
11359
2da2dd60331c [sql gen] Explicitly name unique index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11292
diff changeset
   203
2da2dd60331c [sql gen] Explicitly name unique index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11292
diff changeset
   204
    def test_add_attribute_unique(self):
2da2dd60331c [sql gen] Explicitly name unique index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11292
diff changeset
   205
        with self.mh() as (cnx, mh):
2da2dd60331c [sql gen] Explicitly name unique index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11292
diff changeset
   206
            self.assertNotIn('unique_id', self.schema)
2da2dd60331c [sql gen] Explicitly name unique index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11292
diff changeset
   207
            mh.cmd_add_attribute('Note', 'unique_id')
2da2dd60331c [sql gen] Explicitly name unique index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11292
diff changeset
   208
            # test unique index creation
2da2dd60331c [sql gen] Explicitly name unique index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11292
diff changeset
   209
            dbh = self.repo.system_source.dbhelper
2da2dd60331c [sql gen] Explicitly name unique index
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11292
diff changeset
   210
            self.assertTrue(dbh.index_exists(cnx.cnxset.cu, 'cw_Note', 'cw_unique_id', unique=True))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   211
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
    def test_add_datetime_with_default_value_attribute(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   213
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   214
            self.assertNotIn('mydate', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   215
            self.assertNotIn('oldstyledefaultdate', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   216
            self.assertNotIn('newstyledefaultdate', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   217
            mh.cmd_add_attribute('Note', 'mydate')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   218
            mh.cmd_add_attribute('Note', 'oldstyledefaultdate')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   219
            mh.cmd_add_attribute('Note', 'newstyledefaultdate')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   220
            self.assertIn('mydate', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   221
            self.assertIn('oldstyledefaultdate', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   222
            self.assertIn('newstyledefaultdate', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   223
            self.assertEqual(self.schema['mydate'].subjects(), ('Note', ))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   224
            self.assertEqual(self.schema['mydate'].objects(), ('Date', ))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   225
            testdate = date(2005, 12, 13)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   226
            eid1 = mh.rqlexec('INSERT Note N')[0][0]
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   227
            eid2 = mh.rqlexec('INSERT Note N: N mydate %(mydate)s', {'mydate': testdate})[0][0]
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   228
            d1 = mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid1})[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   229
            d2 = mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid2})[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   230
            d3 = mh.rqlexec('Any D WHERE X eid %(x)s, X oldstyledefaultdate D', {'x': eid1})[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   231
            d4 = mh.rqlexec('Any D WHERE X eid %(x)s, X newstyledefaultdate D', {'x': eid1})[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   232
            self.assertEqual(d1, date.today())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   233
            self.assertEqual(d2, testdate)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   234
            myfavoritedate = date(2013, 1, 1)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   235
            self.assertEqual(d3, myfavoritedate)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   236
            self.assertEqual(d4, myfavoritedate)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   237
6292
054fa36060d5 [migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6208
diff changeset
   238
    def test_drop_chosen_constraints_ctxmanager(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   239
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   240
            with mh.cmd_dropped_constraints('Note', 'unique_id', UniqueConstraint):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   241
                mh.cmd_add_attribute('Note', 'unique_id')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   242
                # make sure the maxsize constraint is not dropped
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   243
                self.assertRaises(ValidationError,
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   244
                                  mh.rqlexec,
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   245
                                  'INSERT Note N: N unique_id "xyz"')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   246
                mh.rollback()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   247
                # make sure the unique constraint is dropped
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   248
                mh.rqlexec('INSERT Note N: N unique_id "x"')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   249
                mh.rqlexec('INSERT Note N: N unique_id "x"')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   250
                mh.rqlexec('DELETE Note N')
6292
054fa36060d5 [migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6208
diff changeset
   251
054fa36060d5 [migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6208
diff changeset
   252
    def test_drop_required_ctxmanager(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   253
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   254
            with mh.cmd_dropped_constraints('Note', 'unique_id', cstrtype=None,
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   255
                                            droprequired=True):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   256
                mh.cmd_add_attribute('Note', 'unique_id')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   257
                mh.rqlexec('INSERT Note N')
10441
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
   258
                mh.rqlexec('SET N unique_id "x"')
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   259
            # make sure the required=True was restored
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   260
            self.assertRaises(ValidationError, mh.rqlexec, 'INSERT Note N')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   261
            mh.rollback()
6292
054fa36060d5 [migractions] add a dropped_constraints() migration command
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6208
diff changeset
   262
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
    def test_rename_attribute(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   264
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   265
            self.assertNotIn('civility', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   266
            eid1 = mh.rqlexec('INSERT Personne X: X nom "lui", X sexe "M"')[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   267
            eid2 = mh.rqlexec('INSERT Personne X: X nom "l\'autre", X sexe NULL')[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   268
            mh.cmd_rename_attribute('Personne', 'sexe', 'civility')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   269
            self.assertNotIn('sexe', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   270
            self.assertIn('civility', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   271
            # test data has been backported
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   272
            c1 = mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid1)[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   273
            self.assertEqual(c1, 'M')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   274
            c2 = mh.rqlexec('Any C WHERE X eid %s, X civility C' % eid2)[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   275
            self.assertEqual(c2, None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   277
    def test_workflow_actions(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   278
        with self.mh() as (cnx, mh):
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   279
            mh.cmd_add_workflow(u'foo', ('Personne', 'Email'),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   280
                                ensure_workflowable=False)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   281
            for etype in ('Personne', 'Email'):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   282
                s1 = mh.rqlexec('Any N WHERE WF workflow_of ET, ET name "%s", WF name N' %
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   283
                                etype)[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   284
                self.assertEqual(s1, "foo")
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   285
                s1 = mh.rqlexec('Any N WHERE ET default_workflow WF, ET name "%s", WF name N' %
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   286
                                etype)[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   287
                self.assertEqual(s1, "foo")
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   288
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   289
    def test_add_entity_type(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   290
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   291
            self.assertNotIn('Folder2', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   292
            self.assertNotIn('filed_under2', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   293
            mh.cmd_add_entity_type('Folder2')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   294
            self.assertIn('Folder2', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   295
            self.assertIn('Old', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   296
            self.assertTrue(cnx.execute('CWEType X WHERE X name "Folder2"'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   297
            self.assertIn('filed_under2', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   298
            self.assertTrue(cnx.execute('CWRType X WHERE X name "filed_under2"'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   299
            self.assertEqual(sorted(str(rs) for rs in self.schema['Folder2'].subject_relations()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   300
                             ['created_by', 'creation_date', 'cw_source', 'cwuri',
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   301
                              'description', 'description_format',
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   302
                              'eid',
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   303
                              'filed_under2', 'has_text',
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   304
                              'identity', 'in_basket', 'inlined_rel', 'is', 'is_instance_of',
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   305
                              'modification_date', 'name', 'owned_by'])
10257
1925e7fe9412 [server/test] don't rely on a sorted output from .object_relations()
Julien Cristau <julien.cristau@logilab.fr>
parents: 10129
diff changeset
   306
            self.assertCountEqual([str(rs) for rs in self.schema['Folder2'].object_relations()],
11112
d0d86803a804 fix test broken by #012e6c7d02ef
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11106
diff changeset
   307
                                  ['filed_under2', 'identity', 'inlined_rel'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   308
            # Old will be missing as it has been renamed into 'New' in the migrated
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   309
            # schema while New hasn't been added here.
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   310
            self.assertEqual(sorted(str(e) for e in self.schema['filed_under2'].subjects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   311
                             sorted(str(e) for e in self.schema.entities()
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   312
                                    if not e.final and e != 'Old'))
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   313
            self.assertEqual(self.schema['filed_under2'].objects(), ('Folder2',))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   314
            eschema = self.schema.eschema('Folder2')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   315
            for cstr in eschema.rdef('name').constraints:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   316
                self.assertTrue(hasattr(cstr, 'eid'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
11904
e760c54490b1 [migration] Fix addition of entity type including boundary constraints on its own attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
   318
    def test_add_entity_type_with_constraint(self):
e760c54490b1 [migration] Fix addition of entity type including boundary constraints on its own attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
   319
        with self.mh() as (cnx, mh):
e760c54490b1 [migration] Fix addition of entity type including boundary constraints on its own attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
   320
            mh.cmd_add_entity_type('Activity')
e760c54490b1 [migration] Fix addition of entity type including boundary constraints on its own attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
   321
            constraints = self.table_constraints(mh, 'cw_Activity')
e760c54490b1 [migration] Fix addition of entity type including boundary constraints on its own attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
   322
            self.assertEqual(len(constraints), 2, constraints)
e760c54490b1 [migration] Fix addition of entity type including boundary constraints on its own attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
   323
10999
adc46197b8c9 [migration] test addition of a cube providing a custom final type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10951
diff changeset
   324
    def test_add_cube_with_custom_final_type(self):
adc46197b8c9 [migration] test addition of a cube providing a custom final type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10951
diff changeset
   325
        with self.mh() as (cnx, mh):
11007
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   326
            try:
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   327
                mh.cmd_add_cube('fakecustomtype')
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   328
                self.assertIn('Numeric', self.schema)
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   329
                self.assertTrue(self.schema['Numeric'].final)
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   330
                rdef = self.schema['num'].rdefs[('Location', 'Numeric')]
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   331
                self.assertEqual(rdef.scale, 10)
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   332
                self.assertEqual(rdef.precision, 18)
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   333
                fields = self.table_schema(mh, '%sLocation' % SQL_PREFIX)
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   334
                self.assertEqual(fields['%snum' % SQL_PREFIX], ('numeric', None))  # XXX
11007
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   335
            finally:
f9386e3bf3e8 [migration/test] avoid test interdependency by removing fakecustomtype cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11006
diff changeset
   336
                mh.cmd_drop_cube('fakecustomtype')
11232
25ec9be5f305 [test/migractions] work around drop_cube not deleting final etypes
Julien Cristau <julien.cristau@logilab.fr>
parents: 11129
diff changeset
   337
                mh.drop_entity_type('Numeric')
10999
adc46197b8c9 [migration] test addition of a cube providing a custom final type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10951
diff changeset
   338
2251
799ff50ddfe8 fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2124
diff changeset
   339
    def test_add_drop_entity_type(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   340
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   341
            mh.cmd_add_entity_type('Folder2')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   342
            wf = mh.cmd_add_workflow(u'folder2 wf', 'Folder2',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   343
                                     ensure_workflowable=False)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   344
            todo = wf.add_state(u'todo', initial=True)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   345
            done = wf.add_state(u'done')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   346
            wf.add_transition(u'redoit', done, todo)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   347
            wf.add_transition(u'markasdone', todo, done)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   348
            cnx.commit()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   349
            mh.cmd_drop_entity_type('Folder2')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   350
            self.assertNotIn('Folder2', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   351
            self.assertFalse(cnx.execute('CWEType X WHERE X name "Folder2"'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   352
            # test automatic workflow deletion
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   353
            self.assertFalse(cnx.execute('Workflow X WHERE NOT X workflow_of ET'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   354
            self.assertFalse(cnx.execute('State X WHERE NOT X state_of WF'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   355
            self.assertFalse(cnx.execute('Transition X WHERE NOT X transition_of WF'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
8105
7980b36fb1aa [schema sync] Update repo._type_source_cache when renaming an entity (closes #2094470)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7791
diff changeset
   357
    def test_rename_entity_type(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   358
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   359
            entity = mh.create_entity('Old', name=u'old')
11763
39df042f4ab4 [repository] Drop type_and_source_from_eid and rename related cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11744
diff changeset
   360
            self.repo.type_from_eid(entity.eid, entity._cw)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   361
            mh.cmd_rename_entity_type('Old', 'New')
11362
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   362
            dbh = self.repo.system_source.dbhelper
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   363
            indices = set(dbh.list_indices(cnx.cnxset.cu, 'cw_New'))
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   364
            self.assertNotIn(build_index_name('cw_Old', ['cw_name']), indices)
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   365
            self.assertIn(build_index_name('cw_New', ['cw_name']), indices)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   366
            mh.cmd_rename_attribute('New', 'name', 'new_name')
11362
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   367
            indices = set(dbh.list_indices(cnx.cnxset.cu, 'cw_New'))
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   368
            # check 'indexed' index
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   369
            self.assertNotIn(build_index_name('cw_New', ['cw_name'], 'idx_'), indices)
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   370
            self.assertIn(build_index_name('cw_New', ['cw_new_name'], 'idx_'), indices)
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   371
            # check 'unique' index
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   372
            self.assertNotIn(build_index_name('cw_New', ['cw_name'], 'key_'), indices)
ebe75d73acdd [schema sync] Rename index when an entity type is renamed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11359
diff changeset
   373
            self.assertIn(build_index_name('cw_New', ['cw_new_name'], 'key_'), indices)
8105
7980b36fb1aa [schema sync] Update repo._type_source_cache when renaming an entity (closes #2094470)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7791
diff changeset
   374
2251
799ff50ddfe8 fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2124
diff changeset
   375
    def test_add_drop_relation_type(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   376
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   377
            mh.cmd_add_entity_type('Folder2', auto=False)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   378
            mh.cmd_add_relation_type('filed_under2')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   379
            self.assertIn('filed_under2', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   380
            # Old will be missing as it has been renamed into 'New' in the migrated
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   381
            # schema while New hasn't been added here.
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   382
            self.assertEqual(sorted(str(e) for e in self.schema['filed_under2'].subjects()),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   383
                             sorted(str(e) for e in self.schema.entities()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   384
                                    if not e.final and e != 'Old'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   385
            self.assertEqual(self.schema['filed_under2'].objects(), ('Folder2',))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   386
            mh.cmd_drop_relation_type('filed_under2')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   387
            self.assertNotIn('filed_under2', self.schema)
10129
52adf66fae7d [migration] don't crash when deleting a non-existing rtype
Julien Cristau <julien.cristau@logilab.fr>
parents: 10107
diff changeset
   388
            # this should not crash
52adf66fae7d [migration] don't crash when deleting a non-existing rtype
Julien Cristau <julien.cristau@logilab.fr>
parents: 10107
diff changeset
   389
            mh.cmd_drop_relation_type('filed_under2')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
    def test_add_relation_definition_nortype(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   392
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   393
            mh.cmd_add_relation_definition('Personne', 'concerne2', 'Affaire')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   394
            self.assertEqual(self.schema['concerne2'].subjects(),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   395
                             ('Personne',))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   396
            self.assertEqual(self.schema['concerne2'].objects(),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   397
                             ('Affaire', ))
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   398
            self.assertEqual(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   399
                self.schema['concerne2'].rdef('Personne', 'Affaire').cardinality,
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   400
                '1*')
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   401
            mh.cmd_add_relation_definition('Personne', 'concerne2', 'Note')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   402
            self.assertEqual(sorted(self.schema['concerne2'].objects()), ['Affaire', 'Note'])
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   403
            mh.create_entity('Personne', nom=u'tot')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   404
            mh.create_entity('Affaire')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   405
            mh.rqlexec('SET X concerne2 Y WHERE X is Personne, Y is Affaire')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   406
            cnx.commit()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   407
            mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Affaire')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   408
            self.assertIn('concerne2', self.schema)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   409
            mh.cmd_drop_relation_definition('Personne', 'concerne2', 'Note')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   410
            self.assertNotIn('concerne2', self.schema)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
2251
799ff50ddfe8 fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2124
diff changeset
   412
    def test_drop_relation_definition_existant_rtype(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   413
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   414
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   415
                             ['Affaire', 'Personne'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   416
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].objects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   417
                             ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   418
            mh.cmd_drop_relation_definition('Personne', 'concerne', 'Affaire')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   419
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   420
                             ['Affaire'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   421
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].objects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   422
                             ['Division', 'Note', 'Societe', 'SubDivision'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   423
            mh.cmd_add_relation_definition('Personne', 'concerne', 'Affaire')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   424
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   425
                             ['Affaire', 'Personne'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   426
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].objects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   427
                             ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   428
            # trick: overwrite self.maxeid to avoid deletion of just reintroduced types
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   429
            self.maxeid = cnx.execute('Any MAX(X)')[0][0]
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   430
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   431
    def test_drop_relation_definition_with_specialization(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   432
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   433
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   434
                             ['Affaire', 'Personne'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   435
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].objects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   436
                             ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   437
            mh.cmd_drop_relation_definition('Affaire', 'concerne', 'Societe')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   438
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   439
                             ['Affaire', 'Personne'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   440
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].objects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   441
                             ['Affaire', 'Note'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   442
            mh.cmd_add_relation_definition('Affaire', 'concerne', 'Societe')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   443
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].subjects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   444
                             ['Affaire', 'Personne'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   445
            self.assertEqual(sorted(str(e) for e in self.schema['concerne'].objects()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   446
                             ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   447
            # trick: overwrite self.maxeid to avoid deletion of just reintroduced types
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   448
            self.maxeid = cnx.execute('Any MAX(X)')[0][0]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   449
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   450
    def test_rename_relation(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   451
        self.skipTest('implement me')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   452
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   453
    def test_change_relation_props_non_final(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   454
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   455
            rschema = self.schema['concerne']
4100
ca9e014012ef api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
   456
            card = rschema.rdef('Affaire', 'Societe').cardinality
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   457
            self.assertEqual(card, '**')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   458
            try:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   459
                mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   460
                                             cardinality='?*')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   461
                card = rschema.rdef('Affaire', 'Societe').cardinality
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   462
                self.assertEqual(card, '?*')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   463
            finally:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   464
                mh.cmd_change_relation_props('Affaire', 'concerne', 'Societe',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   465
                                             cardinality='**')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   466
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   467
    def test_change_relation_props_final(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   468
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   469
            rschema = self.schema['adel']
4100
ca9e014012ef api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
   470
            card = rschema.rdef('Personne', 'String').fulltextindexed
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   471
            self.assertEqual(card, False)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   472
            try:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   473
                mh.cmd_change_relation_props('Personne', 'adel', 'String',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   474
                                             fulltextindexed=True)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   475
                card = rschema.rdef('Personne', 'String').fulltextindexed
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   476
                self.assertEqual(card, True)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   477
            finally:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   478
                mh.cmd_change_relation_props('Personne', 'adel', 'String',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   479
                                             fulltextindexed=False)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
9565
fa00fc251d57 [migractions] Better handle removal of RQLConstraint in sync_schema
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9273
diff changeset
   481
    def test_sync_schema_props_perms_rqlconstraints(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   482
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   483
            # Drop one of the RQLConstraint.
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   484
            rdef = self.schema['evaluee'].rdefs[('Personne', 'Note')]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   485
            oldconstraints = rdef.constraints
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   486
            self.assertIn('S created_by U',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   487
                          [cstr.expression for cstr in oldconstraints])
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   488
            mh.cmd_sync_schema_props_perms('evaluee', commit=True)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   489
            newconstraints = rdef.constraints
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   490
            self.assertNotIn('S created_by U',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   491
                             [cstr.expression for cstr in newconstraints])
9565
fa00fc251d57 [migractions] Better handle removal of RQLConstraint in sync_schema
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9273
diff changeset
   492
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   493
            # Drop all RQLConstraint.
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   494
            rdef = self.schema['travaille'].rdefs[('Personne', 'Societe')]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   495
            oldconstraints = rdef.constraints
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   496
            self.assertEqual(len(oldconstraints), 2)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   497
            mh.cmd_sync_schema_props_perms('travaille', commit=True)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   498
            rdef = self.schema['travaille'].rdefs[('Personne', 'Societe')]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   499
            newconstraints = rdef.constraints
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   500
            self.assertEqual(len(newconstraints), 0)
9565
fa00fc251d57 [migractions] Better handle removal of RQLConstraint in sync_schema
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9273
diff changeset
   501
2637
07103211e511 R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   502
    def test_sync_schema_props_perms(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   503
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   504
            nbrqlexpr_start = cnx.execute('Any COUNT(X) WHERE X is RQLExpression')[0][0]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   505
            migrschema['titre'].rdefs[('Personne', 'String')].order = 7
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   506
            migrschema['adel'].rdefs[('Personne', 'String')].order = 6
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   507
            migrschema['ass'].rdefs[('Personne', 'String')].order = 5
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   508
            migrschema['Personne'].description = 'blabla bla'
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   509
            migrschema['titre'].description = 'usually a title'
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   510
            migrschema['titre'].rdefs[('Personne', 'String')].description = 'title for this person'
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   511
            delete_concerne_rqlexpr = self._rrqlexpr_rset(cnx, 'delete', 'concerne')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   512
            add_concerne_rqlexpr = self._rrqlexpr_rset(cnx, 'add', 'concerne')
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6417
diff changeset
   513
10584
743ed2b13a6f [syncschema] only add to the `synchronized` set if all possible updates have been done
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9787
diff changeset
   514
            # make sure properties (e.g. etype descriptions) are synced by the
743ed2b13a6f [syncschema] only add to the `synchronized` set if all possible updates have been done
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9787
diff changeset
   515
            # second call to sync_schema
743ed2b13a6f [syncschema] only add to the `synchronized` set if all possible updates have been done
Aurelien Campeas <aurelien.campeas@pythonian.fr>
parents: 9787
diff changeset
   516
            mh.cmd_sync_schema_props_perms(syncprops=False, commit=False)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   517
            mh.cmd_sync_schema_props_perms(commit=False)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   518
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   519
            self.assertEqual(cnx.execute('Any D WHERE X name "Personne", X description D')[0][0],
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   520
                             'blabla bla')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   521
            self.assertEqual(cnx.execute('Any D WHERE X name "titre", X description D')[0][0],
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   522
                             'usually a title')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   523
            self.assertEqual(cnx.execute('Any D WHERE X relation_type RT, RT name "titre",'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   524
                                         'X from_entity FE, FE name "Personne",'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   525
                                         'X description D')[0][0],
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   526
                             'title for this person')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   527
            rinorder = [n for n, in cnx.execute(
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   528
                'Any N ORDERBY O,N WHERE X is CWAttribute, X relation_type RT, RT name N,'
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   529
                'X from_entity FE, FE name "Personne",'
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   530
                'X ordernum O')]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   531
            expected = [u'nom', u'prenom', u'sexe', u'promo', u'ass', u'adel', u'titre',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   532
                        u'web', u'tel', u'fax', u'datenaiss', u'test', u'tzdatenaiss',
11273
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   533
                        u'description', u'firstname', u'photo',
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   534
                        u'creation_date', u'cwuri', u'modification_date']
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   535
            self.assertEqual(expected, rinorder)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   536
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   537
            # test permissions synchronization ####################################
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   538
            # new rql expr to add note entity
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   539
            eexpr = self._erqlexpr_entity(cnx, 'add', 'Note')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   540
            self.assertEqual(eexpr.expression,
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   541
                             'X ecrit_part PE, U in_group G, '
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   542
                             'PE require_permission P, P name "add_note", P require_group G')
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   543
            self.assertEqual([et.name for et in eexpr.reverse_add_permission], ['Note'])
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   544
            self.assertEqual(eexpr.reverse_read_permission, ())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   545
            self.assertEqual(eexpr.reverse_delete_permission, ())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   546
            self.assertEqual(eexpr.reverse_update_permission, ())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   547
            self.assertTrue(self._rrqlexpr_rset(cnx, 'add', 'para'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   548
            # no rqlexpr to delete para attribute
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   549
            self.assertFalse(self._rrqlexpr_rset(cnx, 'delete', 'para'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   550
            # new rql expr to add ecrit_par relation
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   551
            rexpr = self._rrqlexpr_entity(cnx, 'add', 'ecrit_par')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   552
            self.assertEqual(rexpr.expression,
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   553
                             'O require_permission P, P name "add_note", '
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   554
                             'U in_group G, P require_group G')
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   555
            self.assertEqual([rdef.rtype.name for rdef in rexpr.reverse_add_permission],
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   556
                             ['ecrit_par'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   557
            self.assertEqual(rexpr.reverse_read_permission, ())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   558
            self.assertEqual(rexpr.reverse_delete_permission, ())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   559
            # no more rqlexpr to delete and add travaille relation
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   560
            self.assertFalse(self._rrqlexpr_rset(cnx, 'add', 'travaille'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   561
            self.assertFalse(self._rrqlexpr_rset(cnx, 'delete', 'travaille'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   562
            # no more rqlexpr to delete and update Societe entity
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   563
            self.assertFalse(self._erqlexpr_rset(cnx, 'update', 'Societe'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   564
            self.assertFalse(self._erqlexpr_rset(cnx, 'delete', 'Societe'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   565
            # no more rqlexpr to read Affaire entity
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   566
            self.assertFalse(self._erqlexpr_rset(cnx, 'read', 'Affaire'))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   567
            # rqlexpr to update Affaire entity has been updated
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   568
            eexpr = self._erqlexpr_entity(cnx, 'update', 'Affaire')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   569
            self.assertEqual(eexpr.expression, 'X concerne S, S owned_by U')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   570
            # no change for rqlexpr to add and delete Affaire entity
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   571
            self.assertEqual(len(self._erqlexpr_rset(cnx, 'delete', 'Affaire')), 1)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   572
            self.assertEqual(len(self._erqlexpr_rset(cnx, 'add', 'Affaire')), 1)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   573
            # no change for rqlexpr to add and delete concerne relation
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   574
            self.assertEqual(len(self._rrqlexpr_rset(cnx, 'delete', 'concerne')),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   575
                             len(delete_concerne_rqlexpr))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   576
            self.assertEqual(len(self._rrqlexpr_rset(cnx, 'add', 'concerne')),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   577
                             len(add_concerne_rqlexpr))
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   578
            # * migrschema involve:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   579
            #   * 7 erqlexprs deletions (2 in (Affaire + Societe + Note.para) + 1 Note.something
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   580
            #   * 2 rrqlexprs deletions (travaille)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   581
            #   * 1 update (Affaire update)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   582
            #   * 2 new (Note add, ecrit_par add)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   583
            #   * 2 implicit new for attributes (Note.para, Person.test)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   584
            # remaining orphan rql expr which should be deleted at commit (composite relation)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   585
            # unattached expressions -> pending deletion on commit
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   586
            self.assertEqual(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   587
                cnx.execute('Any COUNT(X) WHERE X is RQLExpression, X exprtype "ERQLExpression",'
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   588
                            'NOT ET1 read_permission X, NOT ET2 add_permission X, '
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   589
                            'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0],
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   590
                7)
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   591
            self.assertEqual(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   592
                cnx.execute('Any COUNT(X) WHERE X is RQLExpression, X exprtype "RRQLExpression",'
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   593
                            'NOT ET1 read_permission X, NOT ET2 add_permission X, '
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   594
                            'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0],
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   595
                2)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   596
            # finally
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   597
            self.assertEqual(cnx.execute('Any COUNT(X) WHERE X is RQLExpression')[0][0],
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   598
                             nbrqlexpr_start + 1 + 2 + 2 + 2)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   599
            cnx.commit()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   600
            # unique_together test
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   601
            self.assertEqual(len(self.schema.eschema('Personne')._unique_together), 1)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   602
            self.assertCountEqual(self.schema.eschema('Personne')._unique_together[0],
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   603
                                  ('nom', 'prenom', 'datenaiss'))
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   604
            rset = cnx.execute('Any C WHERE C is CWUniqueTogetherConstraint, '
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   605
                               'C constraint_of ET, ET name "Personne"')
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   606
            self.assertEqual(len(rset), 1)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   607
            relations = [r.name for r in rset.get_entity(0, 0).relations]
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   608
            self.assertCountEqual(relations, ('nom', 'prenom', 'datenaiss'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   609
11414
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   610
            # serialized constraint changed
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   611
            constraints = self.table_constraints(mh, 'cw_Personne')
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   612
            self.assertEqual(len(constraints), 1, constraints)
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   613
            rdef = migrschema['promo'].rdefs['Personne', 'String']
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   614
            cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
12512
661dd0436c01 [schema] drop monkeypatch "name_for" on BaseConstraint
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12239
diff changeset
   615
            self.assertIn(constraint_name_for(cstr, rdef), constraints)
11414
69ea7be0373a [test] Add a migration test for update of a static vocabulary constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11362
diff changeset
   616
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   617
    def _erqlexpr_rset(self, cnx, action, ertype):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
   618
        rql = 'RQLExpression X WHERE ET is CWEType, ET %s_permission X, ET name %%(name)s' % action
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   619
        return cnx.execute(rql, {'name': ertype})
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   620
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   621
    def _erqlexpr_entity(self, cnx, action, ertype):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   622
        rset = self._erqlexpr_rset(cnx, action, ertype)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   623
        self.assertEqual(len(rset), 1)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   624
        return rset.get_entity(0, 0)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   625
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   626
    def _rrqlexpr_rset(self, cnx, action, ertype):
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   627
        return cnx.execute('RQLExpression X WHERE RT is CWRType, RDEF %s_permission X, '
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   628
                           'RT name %%(name)s, RDEF relation_type RT' % action,
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   629
                           {'name': ertype})
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   630
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   631
    def _rrqlexpr_entity(self, cnx, action, ertype):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   632
        rset = self._rrqlexpr_rset(cnx, action, ertype)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6208
diff changeset
   633
        self.assertEqual(len(rset), 1)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   634
        return rset.get_entity(0, 0)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   635
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   636
    def test_set_size_constraint(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   637
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   638
            # existing previous value
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   639
            try:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   640
                mh.cmd_set_size_constraint('CWEType', 'name', 128)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   641
            finally:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   642
                mh.cmd_set_size_constraint('CWEType', 'name', 64)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   643
            # non existing previous value
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   644
            try:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   645
                mh.cmd_set_size_constraint('CWEType', 'description', 256)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   646
            finally:
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   647
                mh.cmd_set_size_constraint('CWEType', 'description', None)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   648
10107
1ef92a6193a8 [serverctl] rename remove_cube to drop_cube (closes #4545093)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9971
diff changeset
   649
    def test_add_drop_cube_and_deps(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   650
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   651
            schema = self.repo.schema
10814
a13db4185129 [server/test] dict.iterkeys
Julien Cristau <julien.cristau@logilab.fr>
parents: 10801
diff changeset
   652
            self.assertEqual(sorted((str(s), str(o)) for s, o in schema['see_also'].rdefs),
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   653
                             sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   654
                                     ('Bookmark', 'Bookmark'), ('Bookmark', 'Note'),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   655
                                     ('Note', 'Note'), ('Note', 'Bookmark')]))
439
7cb7cb318983 test fixes
sylvain.thenault@logilab.fr
parents: 47
diff changeset
   656
            try:
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   657
                mh.cmd_drop_cube('fakeemail', removedeps=True)
439
7cb7cb318983 test fixes
sylvain.thenault@logilab.fr
parents: 47
diff changeset
   658
                # file was there because it's an email dependancy, should have been removed
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   659
                self.assertNotIn('fakeemail', self.config.cubes())
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   660
                self.assertNotIn(self.config.cube_dir('fakeemail'), self.config.cubes_path())
9675
8aabfefc8a81 [test] use assertNotIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9674
diff changeset
   661
                self.assertNotIn('file', self.config.cubes())
8aabfefc8a81 [test] use assertNotIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9674
diff changeset
   662
                self.assertNotIn(self.config.cube_dir('file'), self.config.cubes_path())
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   663
                for ertype in ('Email', 'EmailThread', 'EmailPart', 'File',
439
7cb7cb318983 test fixes
sylvain.thenault@logilab.fr
parents: 47
diff changeset
   664
                               'sender', 'in_thread', 'reply_to', 'data_format'):
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   665
                    self.assertNotIn(ertype, schema)
10814
a13db4185129 [server/test] dict.iterkeys
Julien Cristau <julien.cristau@logilab.fr>
parents: 10801
diff changeset
   666
                self.assertEqual(sorted(schema['see_also'].rdefs),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   667
                                 sorted([('Folder', 'Folder'),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   668
                                         ('Bookmark', 'Bookmark'),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   669
                                         ('Bookmark', 'Note'),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   670
                                         ('Note', 'Note'),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   671
                                         ('Note', 'Bookmark')]))
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   672
                self.assertEqual(sorted(schema['see_also'].subjects()),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   673
                                 ['Bookmark', 'Folder', 'Note'])
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   674
                self.assertEqual(sorted(schema['see_also'].objects()),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   675
                                 ['Bookmark', 'Folder', 'Note'])
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   676
                self.assertEqual(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   677
                    cnx.execute('Any X WHERE X pkey "system.version.fakeemail"').rowcount,
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   678
                    0)
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   679
                self.assertEqual(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   680
                    cnx.execute('Any X WHERE X pkey "system.version.file"').rowcount,
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   681
                    0)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   682
            finally:
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   683
                mh.cmd_add_cube('fakeemail')
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   684
                self.assertIn('fakeemail', self.config.cubes())
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   685
                self.assertIn(self.config.cube_dir('fakeemail'), self.config.cubes_path())
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   686
                self.assertIn('file', self.config.cubes())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   687
                self.assertIn(self.config.cube_dir('file'), self.config.cubes_path())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   688
                for ertype in ('Email', 'EmailThread', 'EmailPart', 'File',
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   689
                               'sender', 'in_thread', 'reply_to', 'data_format'):
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   690
                    self.assertIn(ertype, schema)
10814
a13db4185129 [server/test] dict.iterkeys
Julien Cristau <julien.cristau@logilab.fr>
parents: 10801
diff changeset
   691
                self.assertEqual(sorted(schema['see_also'].rdefs),
a13db4185129 [server/test] dict.iterkeys
Julien Cristau <julien.cristau@logilab.fr>
parents: 10801
diff changeset
   692
                                 sorted([('EmailThread', 'EmailThread'), ('Folder', 'Folder'),
a13db4185129 [server/test] dict.iterkeys
Julien Cristau <julien.cristau@logilab.fr>
parents: 10801
diff changeset
   693
                                         ('Bookmark', 'Bookmark'),
a13db4185129 [server/test] dict.iterkeys
Julien Cristau <julien.cristau@logilab.fr>
parents: 10801
diff changeset
   694
                                         ('Bookmark', 'Note'),
a13db4185129 [server/test] dict.iterkeys
Julien Cristau <julien.cristau@logilab.fr>
parents: 10801
diff changeset
   695
                                         ('Note', 'Note'),
a13db4185129 [server/test] dict.iterkeys
Julien Cristau <julien.cristau@logilab.fr>
parents: 10801
diff changeset
   696
                                         ('Note', 'Bookmark')]))
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   697
                self.assertEqual(sorted(schema['see_also'].subjects()),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   698
                                 ['Bookmark', 'EmailThread', 'Folder', 'Note'])
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   699
                self.assertEqual(sorted(schema['see_also'].objects()),
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   700
                                 ['Bookmark', 'EmailThread', 'Folder', 'Note'])
12545
be36811f0d08 [server/test] make unittest_migractions.py use new style cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12512
diff changeset
   701
                from cubicweb_fakeemail.__pkginfo__ import version as email_version
be36811f0d08 [server/test] make unittest_migractions.py use new style cubes
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 12512
diff changeset
   702
                from cubicweb_file.__pkginfo__ import version as file_version
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   703
                self.assertEqual(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   704
                    cnx.execute('Any V WHERE X value V, X pkey "system.version.fakeemail"')[0][0],
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   705
                    email_version)
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   706
                self.assertEqual(
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   707
                    cnx.execute('Any V WHERE X value V, X pkey "system.version.file"')[0][0],
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   708
                    file_version)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   709
                # why this commit is necessary is unclear to me (though without it
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   710
                # next test may fail complaining of missing tables
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   711
                cnx.commit()
972
1efba3fd1364 set_state command in shell
sylvain.thenault@logilab.fr
parents: 934
diff changeset
   712
10107
1ef92a6193a8 [serverctl] rename remove_cube to drop_cube (closes #4545093)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9971
diff changeset
   713
    def test_add_drop_cube_no_deps(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   714
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   715
            cubes = set(self.config.cubes())
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   716
            schema = self.repo.schema
2124
5a0b02f37b23 set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   717
            try:
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   718
                mh.cmd_drop_cube('fakeemail')
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   719
                cubes.remove('fakeemail')
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   720
                self.assertNotIn('fakeemail', self.config.cubes())
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9663
diff changeset
   721
                self.assertIn('file', self.config.cubes())
2124
5a0b02f37b23 set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   722
                for ertype in ('Email', 'EmailThread', 'EmailPart',
5a0b02f37b23 set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   723
                               'sender', 'in_thread', 'reply_to'):
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   724
                    self.assertNotIn(ertype, schema)
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   725
            finally:
10487
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   726
                mh.cmd_add_cube('fakeemail')
49a5c38de1de [server/test] stop using email cube
Julien Cristau <julien.cristau@logilab.fr>
parents: 10441
diff changeset
   727
                self.assertIn('fakeemail', self.config.cubes())
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   728
                # why this commit is necessary is unclear to me (though without it
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   729
                # next test may fail complaining of missing tables
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   730
                cnx.commit()
2124
5a0b02f37b23 set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   731
10107
1ef92a6193a8 [serverctl] rename remove_cube to drop_cube (closes #4545093)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9971
diff changeset
   732
    def test_drop_dep_cube(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   733
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   734
            with self.assertRaises(ConfigurationError) as cm:
10107
1ef92a6193a8 [serverctl] rename remove_cube to drop_cube (closes #4545093)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9971
diff changeset
   735
                mh.cmd_drop_cube('file')
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   736
            self.assertEqual(str(cm.exception), "can't remove cube file, used as a dependency")
2124
5a0b02f37b23 set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   737
2963
12ad88615a12 test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   738
    def test_introduce_base_class(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   739
        with self.mh() as (cnx, mh):
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   740
            mh.cmd_add_entity_type('Para')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   741
            self.assertEqual(sorted(et.type for et in self.schema['Para'].specialized_by()),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   742
                             ['Note'])
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   743
            self.assertEqual(self.schema['Note'].specializes().type, 'Para')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   744
            mh.cmd_add_entity_type('Text')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   745
            self.assertEqual(sorted(et.type for et in self.schema['Para'].specialized_by()),
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   746
                             ['Note', 'Text'])
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   747
            self.assertEqual(self.schema['Text'].specializes().type, 'Para')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   748
            # test columns have been actually added
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   749
            text = cnx.create_entity('Text', para=u"hip", summary=u"hop", newattr=u"momo")
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   750
            note = cnx.create_entity('Note', para=u"hip", shortpara=u"hop",
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   751
                                     newattr=u"momo", unique_id=u"x")
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   752
            aff = cnx.create_entity('Affaire')
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   753
            self.assertTrue(cnx.execute('SET X newnotinlined Y WHERE X eid %(x)s, Y eid %(y)s',
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   754
                                        {'x': text.eid, 'y': aff.eid}))
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   755
            self.assertTrue(cnx.execute('SET X newnotinlined Y WHERE X eid %(x)s, Y eid %(y)s',
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   756
                                        {'x': note.eid, 'y': aff.eid}))
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   757
            self.assertTrue(cnx.execute('SET X newinlined Y WHERE X eid %(x)s, Y eid %(y)s',
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   758
                                        {'x': text.eid, 'y': aff.eid}))
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   759
            self.assertTrue(cnx.execute('SET X newinlined Y WHERE X eid %(x)s, Y eid %(y)s',
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   760
                                        {'x': note.eid, 'y': aff.eid}))
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   761
            # XXX remove specializes by ourselves, else tearDown fails when removing
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   762
            # Para because of Note inheritance. This could be fixed by putting the
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   763
            # MemSchemaCWETypeDel(session, name) operation in the
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   764
            # after_delete_entity(CWEType) hook, since in that case the MemSchemaSpecializesDel
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   765
            # operation would be removed before, but I'm not sure this is a desired behaviour.
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   766
            #
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   767
            # also we need more tests about introducing/removing base classes or
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   768
            # specialization relationship...
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   769
            cnx.execute('DELETE X specializes Y WHERE Y name "Para"')
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   770
            cnx.commit()
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   771
            self.assertEqual(sorted(et.type for et in self.schema['Para'].specialized_by()),
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   772
                             [])
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   773
            self.assertEqual(self.schema['Note'].specializes(), None)
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   774
            self.assertEqual(self.schema['Text'].specializes(), None)
2963
12ad88615a12 test and fix migration introducing base classes (w/ regard to yams inheritance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2930
diff changeset
   775
6163
407f54345687 [migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5575
diff changeset
   776
    def test_add_symmetric_relation_type(self):
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   777
        with self.mh() as (cnx, mh):
9963
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   778
            self.assertFalse(self.table_sql(mh, 'same_as_relation'))
9787
ae624d86c652 [tests/migration] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9675
diff changeset
   779
            mh.cmd_add_relation_type('same_as')
9963
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   780
            self.assertTrue(self.table_sql(mh, 'same_as_relation'))
6163
407f54345687 [migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5575
diff changeset
   781
10645
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   782
    def test_change_attribute_type(self):
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   783
        with self.mh() as (cnx, mh):
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   784
            mh.cmd_create_entity('Societe', tel=1)
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   785
            mh.commit()
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   786
            mh.change_attribute_type('Societe', 'tel', 'Float')
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   787
            self.assertNotIn(('Societe', 'Int'), self.schema['tel'].rdefs)
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   788
            self.assertIn(('Societe', 'Float'), self.schema['tel'].rdefs)
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   789
            self.assertEqual(self.schema['tel'].rdefs[('Societe', 'Float')].object, 'Float')
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   790
            tel = mh.rqlexec('Any T WHERE X tel T')[0][0]
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   791
            self.assertEqual(tel, 1.0)
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   792
            self.assertIsInstance(tel, float)
57c60a96de70 [migration] fix change_attribute_type to update the live schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10487
diff changeset
   793
10917
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   794
    def test_drop_required_inlined_relation(self):
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   795
        with self.mh() as (cnx, mh):
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   796
            bob = mh.cmd_create_entity('Personne', nom=u'bob')
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   797
            mh.cmd_create_entity('Note', ecrit_par=bob)
10917
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   798
            mh.commit()
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   799
            rdef = mh.fs_schema.rschema('ecrit_par').rdefs[('Note', 'Personne')]
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   800
            with tempattr(rdef, 'cardinality', '1*'):
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   801
                mh.sync_schema_props_perms('ecrit_par', syncperms=False)
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   802
            mh.cmd_drop_relation_type('ecrit_par')
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   803
            self.assertNotIn('%secrit_par' % SQL_PREFIX,
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   804
                             self.table_schema(mh, '%sPersonne' % SQL_PREFIX))
edea9c324396 [hooks/syncschema] don't set NOT NULL on inlined relation columns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10814
diff changeset
   805
10921
977def81780a [migration] don't handle data deletion anymore on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10917
diff changeset
   806
    def test_drop_inlined_rdef_delete_data(self):
977def81780a [migration] don't handle data deletion anymore on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10917
diff changeset
   807
        with self.mh() as (cnx, mh):
12239
19aae64c4010 [cleanup] Fix some flake8 errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12238
diff changeset
   808
            mh.cmd_create_entity('Note', ecrit_par=cnx.user.eid)
10921
977def81780a [migration] don't handle data deletion anymore on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10917
diff changeset
   809
            mh.commit()
977def81780a [migration] don't handle data deletion anymore on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10917
diff changeset
   810
            mh.drop_relation_definition('Note', 'ecrit_par', 'CWUser')
977def81780a [migration] don't handle data deletion anymore on schema changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10917
diff changeset
   811
            self.assertFalse(mh.sqlexec('SELECT * FROM cw_Note WHERE cw_ecrit_par IS NOT NULL'))
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   812
11273
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   813
    def test_storage_changed(self):
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   814
        with self.mh() as (cnx, mh):
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   815
            john = mh.cmd_create_entity('Personne', nom=u'john',
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   816
                                        photo=Binary(b'something'))
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   817
            bill = mh.cmd_create_entity('Personne', nom=u'bill')
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   818
            mh.commit()
11744
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   819
            with TemporaryDirectory() as tempdir:
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   820
                bfs_storage = storages.BytesFileSystemStorage(tempdir)
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   821
                storages.set_attribute_storage(self.repo, 'Personne', 'photo', bfs_storage)
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   822
                mh.cmd_storage_changed('Personne', 'photo')
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   823
                bob = mh.cmd_create_entity('Personne', nom=u'bob')
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   824
                bffss_dir_content = os.listdir(tempdir)
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   825
                self.assertEqual(len(bffss_dir_content), 1)
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   826
                john.cw_clear_all_caches()
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   827
                self.assertEqual(john.photo.getvalue(),
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   828
                                 osp.join(tempdir,
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   829
                                          bffss_dir_content[0]).encode('utf8'))
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   830
                bob.cw_clear_all_caches()
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   831
                self.assertIsNone(bob.photo)
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   832
                bill.cw_clear_all_caches()
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   833
                self.assertIsNone(bill.photo)
a6dc650bc230 [test] Replace logilab-common's with_tempdir by tempfile.TemporaryDirectory
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11416
diff changeset
   834
                storages.unset_attribute_storage(self.repo, 'Personne', 'photo')
11273
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   835
c655e19cbc35 [server,bfss] fix storage migration when Bytes attributes is None (closes #13519541)
Alexandre Richardson <alexandre.richardson@logilab.fr>
parents: 11232
diff changeset
   836
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   837
class MigrationCommandsComputedTC(MigrationTC):
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   838
    """ Unit tests for computed relations and attributes
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   839
    """
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   840
    appid = 'datacomputed'
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   841
9969
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   842
    def setUp(self):
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   843
        MigrationTC.setUp(self)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   844
        # ensure vregistry is reloaded, needed by generated hooks for computed
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   845
        # attributes
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   846
        self.repo.vreg.set_schema(self.repo.schema)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   847
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   848
    def test_computed_relation_add_relation_definition(self):
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   849
        self.assertNotIn('works_for', self.schema)
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   850
        with self.mh() as (cnx, mh):
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   851
            with self.assertRaises(ExecutionError) as exc:
10633
d800ecd381f6 [server/test] bit of PEP8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10632
diff changeset
   852
                mh.cmd_add_relation_definition('Employee', 'works_for', 'Company')
9961
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   853
        self.assertEqual(str(exc.exception),
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   854
                         'Cannot add a relation definition for a computed '
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   855
                         'relation (works_for)')
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   856
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   857
    def test_computed_relation_drop_relation_definition(self):
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   858
        self.assertIn('notes', self.schema)
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   859
        with self.mh() as (cnx, mh):
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   860
            with self.assertRaises(ExecutionError) as exc:
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   861
                mh.cmd_drop_relation_definition('Company', 'notes', 'Note')
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   862
        self.assertEqual(str(exc.exception),
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   863
                         'Cannot drop a relation definition for a computed '
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   864
                         'relation (notes)')
cef58bd36f7b [CWEP002 migration] properly raise exception on (add|drop)_relation_definition for computed relation
Laura Médioni <laura.medioni@logilab.fr>
parents: 9787
diff changeset
   865
9963
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   866
    def test_computed_relation_add_relation_type(self):
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   867
        self.assertNotIn('works_for', self.schema)
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   868
        with self.mh() as (cnx, mh):
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   869
            mh.cmd_add_relation_type('works_for')
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   870
            self.assertIn('works_for', self.schema)
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   871
            self.assertEqual(self.schema['works_for'].rule,
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   872
                             'O employees S, NOT EXISTS (O associates S)')
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   873
            self.assertEqual(self.schema['works_for'].objects(), ('Company',))
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   874
            self.assertEqual(self.schema['works_for'].subjects(), ('Employee',))
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   875
            self.assertFalse(self.table_sql(mh, 'works_for_relation'))
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   876
            e = cnx.create_entity('Employee')
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   877
            a = cnx.create_entity('Employee')
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   878
            cnx.create_entity('Company', employees=e, associates=a)
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   879
            cnx.commit()
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   880
            company = cnx.execute('Company X').get_entity(0, 0)
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   881
            self.assertEqual([e.eid],
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   882
                             [x.eid for x in company.reverse_works_for])
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   883
            mh.rollback()
5531f5577b50 [CWEP002 migration] support add_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9962
diff changeset
   884
9962
64b573d54133 [CWEP002 migration] support drop_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9961
diff changeset
   885
    def test_computed_relation_drop_relation_type(self):
64b573d54133 [CWEP002 migration] support drop_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9961
diff changeset
   886
        self.assertIn('notes', self.schema)
64b573d54133 [CWEP002 migration] support drop_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9961
diff changeset
   887
        with self.mh() as (cnx, mh):
64b573d54133 [CWEP002 migration] support drop_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9961
diff changeset
   888
            mh.cmd_drop_relation_type('notes')
64b573d54133 [CWEP002 migration] support drop_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9961
diff changeset
   889
        self.assertNotIn('notes', self.schema)
64b573d54133 [CWEP002 migration] support drop_relation_type for computed relations
Laura Médioni <laura.medioni@logilab.fr>
parents: 9961
diff changeset
   890
9964
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   891
    def test_computed_relation_sync_schema_props_perms(self):
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   892
        self.assertIn('whatever', self.schema)
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   893
        with self.mh() as (cnx, mh):
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   894
            mh.cmd_sync_schema_props_perms('whatever')
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   895
            self.assertEqual(self.schema['whatever'].rule,
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   896
                             'S employees E, O associates E')
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   897
            self.assertEqual(self.schema['whatever'].objects(), ('Company',))
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   898
            self.assertEqual(self.schema['whatever'].subjects(), ('Company',))
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   899
            self.assertFalse(self.table_sql(mh, 'whatever_relation'))
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   900
10799
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   901
    def test_computed_relation_sync_schema_props_perms_security(self):
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   902
        with self.mh() as (cnx, mh):
10800
1e4ddf5ee9ad [server/test] dict.itervalues() → iter(dict.values())
Julien Cristau <julien.cristau@logilab.fr>
parents: 10799
diff changeset
   903
            rdef = next(iter(self.schema['perm_changes'].rdefs.values()))
10799
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   904
            self.assertEqual(rdef.permissions,
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   905
                             {'add': (), 'delete': (),
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   906
                              'read': ('managers', 'users')})
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   907
            mh.cmd_sync_schema_props_perms('perm_changes')
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   908
            self.assertEqual(self.schema['perm_changes'].permissions,
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   909
                             {'read': ('managers',)})
10800
1e4ddf5ee9ad [server/test] dict.itervalues() → iter(dict.values())
Julien Cristau <julien.cristau@logilab.fr>
parents: 10799
diff changeset
   910
            rdef = next(iter(self.schema['perm_changes'].rdefs.values()))
10799
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   911
            self.assertEqual(rdef.permissions,
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   912
                             {'add': (), 'delete': (),
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   913
                              'read': ('managers',)})
ec97974b9010 make sync_schema_props_perms(<computed rtype>) work as expected
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10662
diff changeset
   914
9964
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   915
    def test_computed_relation_sync_schema_props_perms_on_rdef(self):
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   916
        self.assertIn('whatever', self.schema)
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   917
        with self.mh() as (cnx, mh):
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   918
            with self.assertRaises(ExecutionError) as exc:
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   919
                mh.cmd_sync_schema_props_perms(
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   920
                    ('Company', 'whatever', 'Person'))
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   921
        self.assertEqual(str(exc.exception),
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   922
                         'Cannot synchronize a relation definition for a computed '
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   923
                         'relation (whatever)')
f4a3ee05cf9d [CWEP002 migration] support sync_schema_props_perms for computed relations
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9963
diff changeset
   924
10632
d89e9176d263 [migration] don't attempt to carry over values when renaming a computed relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10129
diff changeset
   925
    def test_computed_relation_rename_relation_type(self):
d89e9176d263 [migration] don't attempt to carry over values when renaming a computed relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10129
diff changeset
   926
        with self.mh() as (cnx, mh):
d89e9176d263 [migration] don't attempt to carry over values when renaming a computed relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10129
diff changeset
   927
            mh.cmd_rename_relation_type('to_be_renamed', 'renamed')
d89e9176d263 [migration] don't attempt to carry over values when renaming a computed relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10129
diff changeset
   928
        self.assertIn('renamed', self.schema)
d89e9176d263 [migration] don't attempt to carry over values when renaming a computed relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10129
diff changeset
   929
        self.assertNotIn('to_be_renamed', self.schema)
d89e9176d263 [migration] don't attempt to carry over values when renaming a computed relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10129
diff changeset
   930
9969
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   931
    # computed attributes migration ############################################
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   932
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   933
    def setup_add_score(self):
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   934
        with self.admin_access.client_cnx() as cnx:
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   935
            assert not cnx.execute('Company X')
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   936
            c = cnx.create_entity('Company')
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   937
            e1 = cnx.create_entity('Employee', reverse_employees=c)
10633
d800ecd381f6 [server/test] bit of PEP8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10632
diff changeset
   938
            cnx.create_entity('Note', note=2, concerns=e1)
9969
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   939
            e2 = cnx.create_entity('Employee', reverse_employees=c)
10633
d800ecd381f6 [server/test] bit of PEP8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 10632
diff changeset
   940
            cnx.create_entity('Note', note=4, concerns=e2)
9969
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   941
            cnx.commit()
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   942
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   943
    def assert_score_initialized(self, mh):
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   944
        self.assertEqual(self.schema['score'].rdefs['Company', 'Float'].formula,
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   945
                         'Any AVG(NN) WHERE X employees E, N concerns E, N note NN')
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   946
        fields = self.table_schema(mh, '%sCompany' % SQL_PREFIX)
10441
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
   947
        self.assertEqual(fields['%sscore' % SQL_PREFIX], ('double precision', None))
9969
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   948
        self.assertEqual([[3.0]],
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   949
                         mh.rqlexec('Any CS WHERE C score CS, C is Company').rows)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   950
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   951
    def test_computed_attribute_add_relation_type(self):
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   952
        self.assertNotIn('score', self.schema)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   953
        self.setup_add_score()
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   954
        with self.mh() as (cnx, mh):
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   955
            mh.cmd_add_relation_type('score')
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   956
            self.assertIn('score', self.schema)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   957
            self.assertEqual(self.schema['score'].objects(), ('Float',))
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   958
            self.assertEqual(self.schema['score'].subjects(), ('Company',))
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   959
            self.assert_score_initialized(mh)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   960
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   961
    def test_computed_attribute_add_attribute(self):
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   962
        self.assertNotIn('score', self.schema)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   963
        self.setup_add_score()
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   964
        with self.mh() as (cnx, mh):
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   965
            mh.cmd_add_attribute('Company', 'score')
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   966
            self.assertIn('score', self.schema)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   967
            self.assert_score_initialized(mh)
0f64ef873f7a [CWEP002 migration] support add_relation_type/add_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9964
diff changeset
   968
9970
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   969
    def assert_computed_attribute_dropped(self):
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   970
        self.assertNotIn('note20', self.schema)
10441
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
   971
        with self.mh() as (cnx, mh):
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
   972
            fields = self.table_schema(mh, '%sNote' % SQL_PREFIX)
1d0f4064a87e [test] run unittest_migractions on postgresql
Julien Cristau <julien.cristau@logilab.fr>
parents: 10353
diff changeset
   973
        self.assertNotIn('%snote20' % SQL_PREFIX, fields)
9970
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   974
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   975
    def test_computed_attribute_drop_type(self):
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   976
        self.assertIn('note20', self.schema)
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   977
        with self.mh() as (cnx, mh):
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   978
            mh.cmd_drop_relation_type('note20')
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   979
        self.assert_computed_attribute_dropped()
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   980
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   981
    def test_computed_attribute_drop_relation_definition(self):
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   982
        self.assertIn('note20', self.schema)
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   983
        with self.mh() as (cnx, mh):
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   984
            mh.cmd_drop_relation_definition('Note', 'note20', 'Int')
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   985
        self.assert_computed_attribute_dropped()
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   986
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   987
    def test_computed_attribute_drop_attribute(self):
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   988
        self.assertIn('note20', self.schema)
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   989
        with self.mh() as (cnx, mh):
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   990
            mh.cmd_drop_attribute('Note', 'note20')
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   991
        self.assert_computed_attribute_dropped()
671bbfed459b [CWEP002 migration] support drop_relation_type/drop_relation_definition/drop_attribute for computed attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9969
diff changeset
   992
9971
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
   993
    def test_computed_attribute_sync_schema_props_perms_rtype(self):
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
   994
        self.assertIn('note100', self.schema)
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
   995
        with self.mh() as (cnx, mh):
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
   996
            mh.cmd_sync_schema_props_perms('note100')
11039
6424a2e112f5 [schema] rebuild computed attributes on schema reload
Julien Cristau <julien.cristau@logilab.fr>
parents: 11007
diff changeset
   997
        rdef = self.schema['note100'].rdefs['Note', 'Int']
6424a2e112f5 [schema] rebuild computed attributes on schema reload
Julien Cristau <julien.cristau@logilab.fr>
parents: 11007
diff changeset
   998
        self.assertEqual(rdef.formula_select.as_string(),
6424a2e112f5 [schema] rebuild computed attributes on schema reload
Julien Cristau <julien.cristau@logilab.fr>
parents: 11007
diff changeset
   999
                         'Any (N * 100) WHERE X note N, X is Note')
6424a2e112f5 [schema] rebuild computed attributes on schema reload
Julien Cristau <julien.cristau@logilab.fr>
parents: 11007
diff changeset
  1000
        self.assertEqual(rdef.formula, 'Any N*100 WHERE X note N')
9971
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1001
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1002
    def test_computed_attribute_sync_schema_props_perms_rdef(self):
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1003
        self.setup_add_score()
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1004
        with self.mh() as (cnx, mh):
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1005
            mh.cmd_sync_schema_props_perms(('Note', 'note100', 'Int'))
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1006
            self.assertEqual([[200], [400]],
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1007
                             cnx.execute('Any N ORDERBY N WHERE X note100 N').rows)
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1008
            self.assertEqual([[300]],
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1009
                             cnx.execute('Any CS WHERE C score100 CS, C is Company').rows)
5e44dd9dde6b [CWEP002 migration] support sync_schema_props_perms for computed attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9970
diff changeset
  1010
6163
407f54345687 [migration] fix add_relation_type() for symmetric relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5575
diff changeset
  1011
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1012
if __name__ == '__main__':
12238
6ed86e0b0222 [test] Stop using lgc.testlib in unittest_migractions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12237
diff changeset
  1013
    import unittest
6ed86e0b0222 [test] Stop using lgc.testlib in unittest_migractions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12237
diff changeset
  1014
    unittest.main()