server/test/unittest_schemaserial.py
author David Douard <david.douard@logilab.fr>
Wed, 31 Jul 2013 16:58:44 +0200
branchstable
changeset 9209 15dd5b37998b
parent 9141 492216093bc3
child 9299 c5eed908117d
permissions -rw-r--r--
[pkg] prepare 3.17.5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
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
import sys
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
from cStringIO import StringIO
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
from cubicweb.schema import CubicWebSchemaLoader
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
from cubicweb.devtools import TestServerConfiguration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    28
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
    29
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
    30
9140
e7ffe39d4b1a [test] make unittest_schemaserial.py runnable with python
David Douard <david.douard@logilab.fr>
parents: 9128
diff changeset
    31
schema = config = None
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6632
diff changeset
    32
def setUpModule(*args):
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    33
    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
    34
    helper = get_db_helper('sqlite')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    35
    helper.TYPE_MAPPING['BabarTestType'] = 'TEXT'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    36
    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
    37
6631
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    38
    global schema, config
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    39
    loader = CubicWebSchemaLoader()
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    40
    apphome = Schema2RQLTC.datadir + '-schemaserial'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    41
    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
    42
    config.bootstrap_cubes()
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    43
    schema = loader.load(config)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    45
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6632
diff changeset
    46
def tearDownModule(*args):
6631
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    47
    global schema, config
9140
e7ffe39d4b1a [test] make unittest_schemaserial.py runnable with python
David Douard <david.douard@logilab.fr>
parents: 9128
diff changeset
    48
    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
    49
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    50
    unregister_base_type('BabarTestType')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    51
    helper = get_db_helper('sqlite')
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    52
    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
    53
    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
    54
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
from cubicweb.server.schemaserial import *
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
    56
from cubicweb.server.schemaserial import _erperms2rql as erperms2rql
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
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',
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2447
diff changeset
    69
             {'description': u'define a final relation: link a final relation type from a non final entity 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
    70
              '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
    71
                             list(eschema2rql(schema.eschema('CWAttribute'))))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    72
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
    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
    74
        self.assertListEqual([
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    75
                ('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
    76
                 {'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
    77
                             list(eschema2rql(schema.eschema('String'))))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    78
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    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
    80
        # 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
    81
        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
    82
                               {'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
    83
                              ('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
                              ('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
    88
                               {'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
    89
                             sorted(specialize2rql(schema)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    90
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    91
    def test_esche2rql_custom_type(self):
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    92
        expected = [('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    93
                     {'description': u'',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    94
                     'name': u'BabarTestType', 'final': True},)]
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    95
        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
    96
        self.assertListEqual(expected, got)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
    97
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
    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
    99
        self.assertListEqual([
4467
0e73d299730a fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4191
diff changeset
   100
            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s',
0e73d299730a fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4191
diff changeset
   101
             {'description': u'link a relation definition to its relation type', 'symmetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   102
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
   103
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
   104
             {'se': None, 'rt': None, 'oe': None,
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
   105
              'description': u'', 'composite': u'object', 'cardinality': u'1*',
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
   106
              'ordernum': 1}),
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
   107
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
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
   108
             {'x': None, 'ct': u'RQLConstraint_eid', '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
   109
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
   110
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
   111
             {'se': None, 'rt': None, 'oe': None,
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
              'description': u'', 'composite': u'object', 
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
   113
              'ordernum': 1, 'cardinality': u'1*'}),
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
   114
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
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
   115
             {'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
   116
        ],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   117
                             list(rschema2rql(schema.rschema('relation_type'), cstrtypemap)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   118
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
    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
   120
        self.assertListEqual([
4680
8a6bee838464 [test] update tests broken by changes on attributes permissions handling in yams (add/delete replaced by update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   121
            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s', {'description': u'', 'symmetric': False, 'name': u'add_permission', 'final': False, 'fulltext_container': None, 'inlined': False}),
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
   122
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
   123
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
   124
             {'se': None, 'rt': None, 'oe': None,
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
              'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'ordernum': 9999, 'cardinality': u'**'}),
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
   126
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
             {'se': None, 'rt': None, 'oe': None,
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
   128
              'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   129
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
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
   131
             {'se': None, 'rt': None, 'oe': None,
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
   132
              'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'ordernum': 9999, 'cardinality': u'**'}),
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
   133
            ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
   134
             {'se': None, 'rt': None, 'oe': None,
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   135
              'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   136
                             list(rschema2rql(schema.rschema('add_permission'), cstrtypemap)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   137
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
    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
   139
        self.assertListEqual([
4467
0e73d299730a fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4191
diff changeset
   140
            ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s',
0e73d299730a fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4191
diff changeset
   141
             {'description': u'', 'symmetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
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
   143
            ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
   144
             {'se': None, 'rt': None, 'oe': None,
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
   145
              'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1'}),
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
   146
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
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
   147
             {'x': None, 'ct': u'SizeConstraint_eid', 'value': u'max=2'}),
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
   148
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
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
   149
             {'x': None, 'ct': u'StaticVocabularyConstraint_eid', '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
   150
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
   151
            ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
   152
             {'se': None, 'rt': None, 'oe': None,
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
   153
              'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1'}),
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
   154
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
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
   155
             {'x': None, 'ct': u'SizeConstraint_eid', 'value': u'max=2'}),
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
   156
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF 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
   157
             {'x': None, 'ct': u'StaticVocabularyConstraint_eid', 'value': u"u'?*', u'1*', u'+*', u'**', u'?+', u'1+', u'++', u'*+', u'?1', u'11', u'+1', u'*1', u'??', u'1?', u'+?', u'*?'"})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   158
                             list(rschema2rql(schema.rschema('cardinality'), cstrtypemap)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
8945
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   160
    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
   161
        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
   162
                     '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
   163
                     '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
   164
                     {'description': u'',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   165
                      'final': True,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   166
                      'fulltext_container': None,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   167
                      'inlined': False,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   168
                      '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
   169
                      'symmetric': False}),
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   170
                     ('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
   171
                      'X defaultval %(defaultval)s,X description %(description)s,'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   172
                      'X extra_props %(extra_props)s,X indexed %(indexed)s,'
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   173
                      '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
   174
                      '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
   175
                      {'cardinality': u'?1',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   176
                       'defaultval': None,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   177
                       'description': u'',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   178
                       'extra_props': '{"jungle_speed": 42}',
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   179
                       'indexed': False,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   180
                       'oe': None,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   181
                       'ordernum': 19,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   182
                       'rt': None,
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   183
                       'se': None})]
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   184
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   185
        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
   186
        self.assertEqual(2, len(got))
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   187
        # 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
   188
        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
   189
        # this extr
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   190
        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
   191
        from cubicweb import Binary
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   192
        self.assertIsInstance(extra_props, Binary)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   193
        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
   194
        self.assertListEqual(expected, got)
ba9e3fbfa5a5 [schemaserial] serialize additional yams parameter for customs type
Vincent Michel <vincent.michel@logilab.fr>
parents: 8223
diff changeset
   195
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
   196
    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
   197
        self.assertListEqual([
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
   198
            ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
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
   199
             {'se': None, 'rt': None, 'oe': None,
8223
b1a685038c3b [test] fix test broken by RichString handling changes in yams #default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
   200
              'description': u'', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 3, 'defaultval': u'text/plain', 'indexed': False, '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
   201
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
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
   202
             {'x': None, 'value': u'None', 'ct': '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
   203
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF 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
   204
             {'x': None, 'value': u'max=50', 'ct': 'SizeConstraint_eid'})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   205
                             list(rdef2rql(schema['description_format'].rdefs[('CWRType', 'String')], cstrtypemap)))
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
   206
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
    def test_updateeschema2rql1(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   209
        self.assertListEqual([('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X eid %(x)s',
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   210
                               {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the instance schema', 'x': 1, 'final': False, 'name': u'CWAttribute'})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   211
                             list(updateeschema2rql(schema.eschema('CWAttribute'), 1)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   212
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
    def test_updateeschema2rql2(self):
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   214
        self.assertListEqual([('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X eid %(x)s',
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   215
                               {'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
   216
                             list(updateeschema2rql(schema.eschema('String'), 1)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   217
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
    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
   219
        self.assertListEqual([
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
   220
            ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s WHERE X eid %(x)s',
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
   221
             {'x': 1, 'symmetric': False,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
              'description': u'link a relation definition to its relation type',
9128
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   223
              'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})],
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   224
                             list(updaterschema2rql(schema.rschema('relation_type'), 1)))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   225
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
    def test_updaterschema2rql2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
        expected = [
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
   228
            ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s WHERE X eid %(x)s',
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
   229
             {'x': 1, 'symmetric': False,
4680
8a6bee838464 [test] update tests broken by changes on attributes permissions handling in yams (add/delete replaced by update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   230
              'description': u'', 'final': False, 'fulltext_container': None,
8a6bee838464 [test] update tests broken by changes on attributes permissions handling in yams (add/delete replaced by update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   231
              'inlined': False, 'name': u'add_permission'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
            ]
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
   233
        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
   234
            yield self.assertEqual, expected[i], (rql, args)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
class Perms2RQLTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
    GROUP_MAPPING = {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
        'managers': 0,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
        'users':  1,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
        'guests': 2,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
        'owners': 3,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
        }
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   243
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
    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
   245
        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
   246
                              ('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
   247
                              ('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
   248
                              ('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
   249
                              ('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
   250
                              ('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
   251
                             [(rql, kwargs)
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   252
                              for rql, kwargs in erperms2rql(schema.eschema('CWEType'), self.GROUP_MAPPING)])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   253
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
    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
   255
        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
   256
                              ('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
   257
                              ('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
   258
                              ('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
   259
                              ('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
   260
                             [(rql, kwargs)
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   261
                              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
   262
                                                             self.GROUP_MAPPING)])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   263
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   264
    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
   265
        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
   266
                              ('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
   267
                              ('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
   268
                              ('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
   269
                             [(rql, kwargs)
d988eec2d5d3 [test/schemaserial] swap got/expected to get nicer unittest2 diagnostics
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8945
diff changeset
   270
                              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
   271
                                                             self.GROUP_MAPPING)])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   272
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
    #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
   274
    #    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
   275
    #                         ['INSERT CWEType X: X name 'Societe', X final FALSE'])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   276
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   277
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   278
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   279
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   280
    unittest_main()