server/test/unittest_schemaserial.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 13 Jun 2014 12:07:51 +0200
changeset 10352 bab2befaac9b
parent 10213 e53cc2182cf8
child 10553 1d824df4f2bd
permissions -rw-r--r--
[session] provide missing apis to Connection From this point, Connection provides a superset of ClientConnection. Related to #3837233.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
     1
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
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: 4793
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6632
78878f5a8166 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6631
diff changeset
    18
"""unit tests for schema rql (de)serialization"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
9299
c5eed908117d [schema] store default attribute values in a Bytes field, allowing python objects as default values
Aurélien Campeas <aurelien.campeas@logilab.fr>
parents: 9141
diff changeset
    22
from cubicweb import Binary
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from cubicweb.schema import CubicWebSchemaLoader
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
from cubicweb.devtools import TestServerConfiguration
9956
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
    25
from cubicweb.devtools.testlib import CubicWebTC
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
9796
2d1e488f6f71 [tests/schemaserial] kill star import
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9795
diff changeset
    27
from cubicweb.server.schemaserial import (updateeschema2rql, updaterschema2rql, rschema2rql,
2d1e488f6f71 [tests/schemaserial] kill star import
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9795
diff changeset
    28
                                          eschema2rql, rdef2rql, specialize2rql,
2d1e488f6f71 [tests/schemaserial] kill star import
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9795
diff changeset
    29
                                          _erperms2rql as erperms2rql)
2d1e488f6f71 [tests/schemaserial] kill star import
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9795
diff changeset
    30
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    31
from logilab.database import get_db_helper
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    32
from yams import register_base_type, unregister_base_type
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    33
9140
e7ffe39d4b1a [test] make unittest_schemaserial.py runnable with python
David Douard <david.douard@logilab.fr>
parents: 9128
diff changeset
    34
schema = config = None
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6632
diff changeset
    35
def setUpModule(*args):
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    36
    register_base_type('BabarTestType', ('jungle_speed',))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    37
    helper = get_db_helper('sqlite')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    38
    helper.TYPE_MAPPING['BabarTestType'] = 'TEXT'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    39
    helper.TYPE_CONVERTERS['BabarTestType'] = lambda x: '"%s"' % x
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    40
6631
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    41
    global schema, config
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    42
    loader = CubicWebSchemaLoader()
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    43
    apphome = Schema2RQLTC.datadir + '-schemaserial'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    44
    config = TestServerConfiguration('data', apphome=apphome)
6631
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    45
    config.bootstrap_cubes()
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    46
    schema = loader.load(config)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    48
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6632
diff changeset
    49
def tearDownModule(*args):
6631
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    50
    global schema, config
9140
e7ffe39d4b1a [test] make unittest_schemaserial.py runnable with python
David Douard <david.douard@logilab.fr>
parents: 9128
diff changeset
    51
    schema = config = None
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4763
diff changeset
    52
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    53
    unregister_base_type('BabarTestType')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    54
    helper = get_db_helper('sqlite')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    55
    helper.TYPE_MAPPING.pop('BabarTestType', None)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    56
    helper.TYPE_CONVERTERS.pop('BabarTestType', None)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    57
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
    58
cstrtypemap = {'RQLConstraint': 'RQLConstraint_eid',
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
    59
               'SizeConstraint': 'SizeConstraint_eid',
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
    60
               'StaticVocabularyConstraint': 'StaticVocabularyConstraint_eid',
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
    61
               'FormatConstraint': 'FormatConstraint_eid',
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
    62
               }
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
    63
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
class Schema2RQLTC(TestCase):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    65
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
    def test_eschema2rql1(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    67
        self.assertListEqual([
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    68
            ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
    69
             {'description': u'define a final relation: '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
    70
              'link a final relation type from a non final entity '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
    71
              'to a final entity type. used to build the instance schema',
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    72
              'name': u'CWAttribute', 'final': False})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    73
                             list(eschema2rql(schema.eschema('CWAttribute'))))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    74
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    def test_eschema2rql2(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    76
        self.assertListEqual([
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    77
                ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    78
                 {'description': u'', 'final': True, 'name': u'String'})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    79
                             list(eschema2rql(schema.eschema('String'))))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    80
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
    def test_eschema2rql_specialization(self):
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
    82
        # x: None since eschema.eid are None
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    83
        self.assertListEqual([('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    84
                               {'et': None, 'x': None}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    85
                              ('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    86
                               {'et': None, 'x': None})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    87
                             sorted(specialize2rql(schema)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    88
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    89
    def test_esche2rql_custom_type(self):
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
    90
        expected = [('INSERT CWEType X: X description %(description)s,X final %(final)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
    91
                     'X name %(name)s',
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    92
                     {'description': u'',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    93
                     'name': u'BabarTestType', 'final': True},)]
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    94
        got = list(eschema2rql(schema.eschema('BabarTestType')))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    95
        self.assertListEqual(expected, got)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    96
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
    def test_rschema2rql1(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
    98
        self.assertListEqual([
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
    99
            ('INSERT CWRType X: X description %(description)s,X final %(final)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   100
             'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   101
             'X name %(name)s,X symmetric %(symmetric)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   102
             {'description': u'link a relation definition to its relation type',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   103
              'symmetric': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   104
              'name': u'relation_type',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   105
              'final' : False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   106
              'fulltext_container': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   107
              'inlined': True}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   108
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   109
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   110
             'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   111
             'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   112
             {'se': None, 'rt': None, 'oe': None,
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   113
              'description': u'',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   114
              'composite': u'object',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   115
              'cardinality': u'1*',
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   116
              'ordernum': 1}),
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   117
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   118
             'WHERE CT eid %(ct)s, EDEF eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   119
             {'x': None, 'ct': u'RQLConstraint_eid',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   120
              'value': u';O;O final TRUE\n'}),
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
   121
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   122
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   123
             'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   124
             'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   125
             {'se': None, 'rt': None, 'oe': None,
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   126
              'description': u'', 'composite': u'object',
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   127
              'ordernum': 1, 'cardinality': u'1*'}),
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   128
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   129
             'WHERE CT eid %(ct)s, EDEF eid %(x)s',
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   130
             {'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final FALSE\n'}),
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   131
        ],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   132
                             list(rschema2rql(schema.rschema('relation_type'), cstrtypemap)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   133
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
    def test_rschema2rql2(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   135
        self.assertListEqual([
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   136
            ('INSERT CWRType X: X description %(description)s,X final %(final)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   137
             'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   138
             'X name %(name)s,X symmetric %(symmetric)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   139
             {'description': u'',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   140
              'symmetric': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   141
              'name': u'add_permission',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   142
              'final': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   143
              'fulltext_container': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   144
              'inlined': False}),
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
   145
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   146
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   147
             'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   148
             'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   149
             {'se': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   150
              'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   151
              'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   152
              'description': u'groups allowed to add entities/relations of this type',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   153
              'composite': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   154
              'ordernum': 9999,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   155
              'cardinality': u'**'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   156
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   157
             'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   158
             'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   159
             {'se': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   160
              'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   161
              'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   162
              'description': u'rql expression allowing to add entities/relations of this type',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   163
              'composite': 'subject',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   164
              'ordernum': 9999,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   165
              'cardinality': u'*?'}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   166
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   167
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   168
             'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   169
             'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   170
             {'se': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   171
              'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   172
              'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   173
              'description': u'groups allowed to add entities/relations of this type',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   174
              'composite': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   175
              'ordernum': 9999,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   176
              'cardinality': u'**'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   177
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   178
             'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   179
             'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   180
             {'se': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   181
              'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   182
              'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   183
              'description': u'rql expression allowing to add entities/relations of this type',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   184
              'composite': 'subject',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   185
              'ordernum': 9999,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   186
              'cardinality': u'*?'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   187
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   188
             'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   189
             'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   190
            {'cardinality': u'**',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   191
             'composite': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   192
             'description': u'groups allowed to add entities/relations of this type',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   193
             'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   194
             'ordernum': 9999,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   195
             'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   196
             'se': None}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   197
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   198
             'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   199
             'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   200
             {'cardinality': u'*?',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   201
              'composite': u'subject',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   202
              'description': u'rql expression allowing to add entities/relations of this type',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   203
              'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   204
              'ordernum': 9999,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   205
              'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   206
              'se': None})],
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   207
                             list(rschema2rql(schema.rschema('add_permission'), cstrtypemap)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   208
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
    def test_rschema2rql3(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   210
        self.assertListEqual([
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   211
            ('INSERT CWRType X: X description %(description)s,X final %(final)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   212
             'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   213
             'X name %(name)s,X symmetric %(symmetric)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   214
             {'description': u'',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   215
              'symmetric': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   216
              'name': u'cardinality',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   217
              'final': True,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   218
              'fulltext_container': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   219
              'inlined': False}),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   221
            ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,'
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   222
             'X description %(description)s,X formula %(formula)s,X fulltextindexed %(fulltextindexed)s,'
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   223
             'X indexed %(indexed)s,X internationalizable %(internationalizable)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   224
             'X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   225
             'X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   226
             {'se': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   227
              'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   228
              'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   229
              'description': u'subject/object cardinality',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   230
              'internationalizable': True,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   231
              'fulltextindexed': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   232
              'ordernum': 5,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   233
              'defaultval': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   234
              'indexed': False,
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   235
              'formula': None,
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   236
              'cardinality': u'?1'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   237
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   238
             'WHERE CT eid %(ct)s, EDEF eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   239
             {'x': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   240
              'ct': u'SizeConstraint_eid',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   241
              'value': u'max=2'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   242
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   243
             'WHERE CT eid %(ct)s, EDEF eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   244
             {'x': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   245
              'ct': u'StaticVocabularyConstraint_eid',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   246
              'value': u"u'?1', u'11'"}),
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
   247
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   248
            ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,'
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   249
             'X description %(description)s,X formula %(formula)s,X fulltextindexed %(fulltextindexed)s,'
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   250
             'X indexed %(indexed)s,X internationalizable %(internationalizable)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   251
             'X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   252
             'WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   253
             {'se': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   254
              'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   255
              'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   256
              'description': u'subject/object cardinality',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   257
              'internationalizable': True,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   258
              'fulltextindexed': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   259
              'ordernum': 5,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   260
              'defaultval': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   261
              'indexed': False,
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   262
              'formula': None,
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   263
              'cardinality': u'?1'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   264
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   265
             'WHERE CT eid %(ct)s, EDEF eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   266
             {'x': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   267
              'ct': u'SizeConstraint_eid',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   268
              'value': u'max=2'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   269
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   270
             'WHERE CT eid %(ct)s, EDEF eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   271
             {'x': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   272
              'ct': u'StaticVocabularyConstraint_eid',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   273
              'value': (u"u'?*', u'1*', u'+*', u'**', u'?+', u'1+', u'++', u'*+', u'?1', "
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   274
                        "u'11', u'+1', u'*1', u'??', u'1?', u'+?', u'*?'")})],
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   275
              list(rschema2rql(schema.rschema('cardinality'), cstrtypemap)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   277
    def test_rschema2rql_custom_type(self):
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   278
        expected = [('INSERT CWRType X: X description %(description)s,X final %(final)s,'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   279
                     'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   280
                     'X name %(name)s,X symmetric %(symmetric)s',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   281
                     {'description': u'',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   282
                      'final': True,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   283
                      'fulltext_container': None,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   284
                      'inlined': False,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   285
                      'name': u'custom_field_of_jungle',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   286
                      'symmetric': False}),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   287
                     ('INSERT CWAttribute X: X cardinality %(cardinality)s,'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   288
                      'X defaultval %(defaultval)s,X description %(description)s,'
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   289
                      'X extra_props %(extra_props)s,X formula %(formula)s,X indexed %(indexed)s,'
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   290
                      'X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   291
                      'X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   292
                      {'cardinality': u'?1',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   293
                       'defaultval': None,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   294
                       'description': u'',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   295
                       'extra_props': '{"jungle_speed": 42}',
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   296
                       'formula': None,
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   297
                       'indexed': False,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   298
                       'oe': None,
9453
5c4d9dfbf176 [server test] simplify data-schemaserial test instance's schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9395
diff changeset
   299
                       'ordernum': 4,
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   300
                       'rt': None,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   301
                       'se': None})]
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   302
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   303
        got = list(rschema2rql(schema.rschema('custom_field_of_jungle'), cstrtypemap))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   304
        self.assertEqual(2, len(got))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   305
        # this is a custom type attribute with an extra parameter
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   306
        self.assertIn('extra_props', got[1][1])
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   307
        # this extr
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   308
        extra_props = got[1][1]['extra_props']
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   309
        self.assertIsInstance(extra_props, Binary)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   310
        got[1][1]['extra_props'] = got[1][1]['extra_props'].getvalue()
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   311
        self.assertListEqual(expected, got)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   312
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   313
    def test_rdef2rql(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   314
        self.assertListEqual([
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   315
            ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,'
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   316
             'X description %(description)s,X formula %(formula)s,X fulltextindexed %(fulltextindexed)s,'
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   317
             'X indexed %(indexed)s,X internationalizable %(internationalizable)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   318
             'X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   319
             'X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   320
             {'se': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   321
              'rt': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   322
              'oe': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   323
              'description': u'',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   324
              'internationalizable': True,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   325
              'fulltextindexed': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   326
              'ordernum': 3,
9984
793377697c81 merge 3.18.6 into 3.19
Julien Cristau <julien.cristau@logilab.fr>
parents: 9796 9920
diff changeset
   327
              'defaultval': Binary.zpickle(u'text/plain'),
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   328
              'indexed': False,
9965
a8769b752299 [CWEP002] Account for attribute formula in schema bootstrap
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9956
diff changeset
   329
              'formula': None,
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   330
              'cardinality': u'?1'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   331
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   332
             'WHERE CT eid %(ct)s, EDEF eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   333
             {'x': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   334
              'value': u'None',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   335
              'ct': 'FormatConstraint_eid'}),
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   336
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   337
             'WHERE CT eid %(ct)s, EDEF eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   338
             {'x': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   339
              'value': u'max=50',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   340
              'ct': 'SizeConstraint_eid'})],
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   341
                             list(rdef2rql(schema['description_format'].rdefs[('CWRType', 'String')],
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   342
                                           cstrtypemap)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
    def test_updateeschema2rql1(self):
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   345
        self.assertListEqual([('SET X description %(description)s,X final %(final)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   346
                               'X name %(name)s WHERE X eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   347
                               {'description': u'define a final relation: link a final relation type from'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   348
                                ' a non final entity to a final entity type. used to build the instance schema',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   349
                                'x': 1, 'final': False, 'name': u'CWAttribute'})],
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   350
                             list(updateeschema2rql(schema.eschema('CWAttribute'), 1)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   351
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
    def test_updateeschema2rql2(self):
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   353
        self.assertListEqual([('SET X description %(description)s,X final %(final)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   354
                               'X name %(name)s WHERE X eid %(x)s',
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   355
                               {'description': u'', 'x': 1, 'final': True, 'name': u'String'})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   356
                             list(updateeschema2rql(schema.eschema('String'), 1)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   357
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
    def test_updaterschema2rql1(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   359
        self.assertListEqual([
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   360
            ('SET X description %(description)s,X final %(final)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   361
             'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   362
             'X name %(name)s,X symmetric %(symmetric)s WHERE X eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   363
             {'x': 1,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   364
              'symmetric': False,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
              'description': u'link a relation definition to its relation type',
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   366
              'final': False, 'fulltext_container': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   367
              'inlined': True,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   368
              'name': u'relation_type'})],
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   369
                             list(updaterschema2rql(schema.rschema('relation_type'), 1)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   370
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
    def test_updaterschema2rql2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
        expected = [
9795
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   373
            ('SET X description %(description)s,X final %(final)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   374
             'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   375
             'X name %(name)s,X symmetric %(symmetric)s WHERE X eid %(x)s',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   376
             {'x': 1,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   377
              'symmetric': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   378
              'description': u'',
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   379
              'final': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   380
              'fulltext_container': None,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   381
              'inlined': False,
e8039b12d52e [tests/schemaserial] break long lines
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9453
diff changeset
   382
              'name': u'add_permission'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   383
            ]
4763
81b0df087375 schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4680
diff changeset
   384
        for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'), 1)):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   385
            yield self.assertEqual, expected[i], (rql, args)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   386
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   387
class Perms2RQLTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   388
    GROUP_MAPPING = {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
        'managers': 0,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
        'users':  1,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
        'guests': 2,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
        'owners': 3,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   393
        }
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   394
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   395
    def test_eperms2rql1(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   396
        self.assertListEqual([('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   397
                              ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   398
                              ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   399
                              ('SET X add_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   400
                              ('SET X update_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   401
                              ('SET X delete_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   402
                             [(rql, kwargs)
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   403
                              for rql, kwargs in erperms2rql(schema.eschema('CWEType'), self.GROUP_MAPPING)])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   404
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
    def test_rperms2rql2(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   406
        self.assertListEqual([('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   407
                              ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   408
                              ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   409
                              ('SET X add_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   410
                              ('SET X delete_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   411
                             [(rql, kwargs)
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   412
                              for rql, kwargs in erperms2rql(schema.rschema('read_permission').rdef('CWEType', 'CWGroup'),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   413
                                                             self.GROUP_MAPPING)])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   414
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
    def test_rperms2rql3(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   416
        self.assertListEqual([('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   417
                              ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   418
                              ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}),
9395
96dba2efd16d [hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9299
diff changeset
   419
                              ('SET X add_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   420
                              ('SET X update_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   421
                             [(rql, kwargs)
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   422
                              for rql, kwargs in erperms2rql(schema.rschema('name').rdef('CWEType', 'String'),
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   423
                                                             self.GROUP_MAPPING)])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   424
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   425
    #def test_perms2rql(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5575
diff changeset
   426
    #    self.assertListEqual(perms2rql(schema, self.GROUP_MAPPING),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   427
    #                         ['INSERT CWEType X: X name 'Societe', X final FALSE'])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   428
9956
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   429
class ComputedAttributeAndRelationTC(CubicWebTC):
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   430
    appid = 'data-cwep002'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   431
9956
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   432
    def test(self):
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   433
        # force to read schema from the database
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   434
        self.repo.set_schema(self.repo.deserialize_schema(), resetvreg=False)
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   435
        schema = self.repo.schema
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   436
        self.assertEqual([('Company', 'Person')], list(schema['has_employee'].rdefs))
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   437
        self.assertEqual('O works_for S',
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   438
                         schema['has_employee'].rule)
19a683a0047c [CWEP002] properly handle serialization of computed relations
Lea Capgen <lea.capgen@logilab.fr>
parents: 9796
diff changeset
   439
        self.assertEqual([('Company', 'Int')], list(schema['total_salary'].rdefs))
9968
50f046bf0e50 [CWEP002] properly handle serialization of computed attributes
Lea Capgen <lea.capgen@logilab.fr>
parents: 9965
diff changeset
   440
        self.assertEqual('Any SUM(SA) GROUPBY X WHERE P works_for X, P salary SA',
50f046bf0e50 [CWEP002] properly handle serialization of computed attributes
Lea Capgen <lea.capgen@logilab.fr>
parents: 9965
diff changeset
   441
                         schema['total_salary'].rdefs['Company', 'Int'].formula)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   443
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   444
    unittest_main()