server/test/unittest_schemaserial.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 03 Dec 2009 09:55:18 +0100
branchstable
changeset 3978 2c95e3033f64
parent 3897 6421a0050234
child 4191 01638461d4b0
permissions -rw-r--r--
finish yesterday work on rql constraints: * Fix inheritance pb: there are some places where we filter constraints according to the class hierarchy, so rql unique constraint should'nt be neither a RQLContraint nor a RQLVocabularyConstraint subclass. Added test in unittest_schema reflecting this. * So now we have to get explicitly RQLUniqueConstraint where desired (eg in server/hooks.py) * Update i18ncubicweb command to include constraint types in generated pot file (this should have been there for a while...) * Update unittest_schemaserial which has been broken when serializing format for rql constraints has changed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""unit tests for schema rql (de)serialization
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
     2
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
import sys
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
from cStringIO import StringIO
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
from cubicweb.schema import CubicWebSchemaLoader
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
from cubicweb.devtools import TestServerConfiguration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
loader = CubicWebSchemaLoader()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
config = TestServerConfiguration('data')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
config.bootstrap_cubes()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
schema = loader.load(config)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
from cubicweb.server.schemaserial import *
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    19
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
class Schema2RQLTC(TestCase):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    21
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
    def test_eschema2rql1(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    23
        self.assertListEquals(list(eschema2rql(schema.eschema('CWAttribute'))),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
                              [
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    25
            ('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
    26
             {'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',
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    27
              'name': u'CWAttribute', 'final': False})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
            ])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    29
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    def test_eschema2rql2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
        self.assertListEquals(list(eschema2rql(schema.eschema('String'))), [
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    32
                ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    33
                 {'description': u'', 'final': True, 'name': u'String'})])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    34
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    def test_eschema2rql_specialization(self):
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    36
        self.assertListEquals(sorted(specialize2rql(schema)),
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    37
                              [('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    38
                                {'et': 'BaseTransition', 'x': 'Transition'}),
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    39
                               ('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    40
                                {'et': 'BaseTransition', 'x': 'WorkflowTransition'}),
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    41
                               ('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    42
                                {'et': 'Division', 'x': 'SubDivision'}),
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    43
                               # ('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    44
                               #  {'et': 'File', 'x': 'Image'}),
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    45
                               ('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
    46
                                {'et': 'Societe', 'x': 'Division'})])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    47
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
    def test_rschema2rql1(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
        self.assertListEquals(list(rschema2rql(schema.rschema('relation_type'))),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
                             [
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    51
            ('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 symetric %(symetric)s',
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    52
             {'description': u'link a relation definition to its relation type', 'symetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    53
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    54
            ('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 name %(se)s,ER name %(rt)s,OE name %(oe)s',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    55
             {'rt': 'relation_type', 'description': u'', 'composite': u'object', 'oe': 'CWRType',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    56
              'ordernum': 1, 'cardinality': u'1*', 'se': 'CWRelation'}),
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    57
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT name %(ctname)s, EDEF relation_type ER, EDEF from_entity SE, EDEF to_entity OE, ER name %(rt)s, SE name %(se)s, OE name %(oe)s, EDEF is CWRelation',
3978
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3897
diff changeset
    58
             {'rt': 'relation_type', 'oe': 'CWRType', 'ctname': u'RQLConstraint', 'se': 'CWRelation', 'value': u';O;O final FALSE\n'}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    59
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    60
            ('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 name %(se)s,ER name %(rt)s,OE name %(oe)s',
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    61
             {'rt': 'relation_type', 'description': u'', 'composite': u'object', 'oe': 'CWRType',
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    62
              'ordernum': 1, 'cardinality': u'1*', 'se': 'CWAttribute'}),
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    63
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT name %(ctname)s, EDEF relation_type ER, EDEF from_entity SE, EDEF to_entity OE, ER name %(rt)s, SE name %(se)s, OE name %(oe)s, EDEF is CWRelation',
3978
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3897
diff changeset
    64
             {'rt': 'relation_type', 'oe': 'CWRType', 'ctname': u'RQLConstraint', 'se': 'CWAttribute', 'value': u';O;O final TRUE\n'}),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
            ])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    66
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
    def test_rschema2rql2(self):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    68
        self.assertListEquals(list(rschema2rql(schema.rschema('add_permission'))),
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    69
                              [
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    70
            ('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 symetric %(symetric)s', {'description': u'core relation giving to a group the permission to add an entity or relation type', 'symetric': False, 'name': u'add_permission', 'final': False, 'fulltext_container': None, 'inlined': False}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    71
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    72
            ('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 name %(se)s,ER name %(rt)s,OE name %(oe)s',
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    73
             {'rt': 'add_permission', 'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'oe': 'CWGroup', 'ordernum': 3, 'cardinality': u'**', 'se': 'CWEType'}),
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    74
            ('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 name %(se)s,ER name %(rt)s,OE name %(oe)s',
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    75
             {'rt': 'add_permission', 'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'oe': 'CWGroup', 'ordernum': 3, 'cardinality': u'**', 'se': 'CWRType'}),
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    76
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    77
            ('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 name %(se)s,ER name %(rt)s,OE name %(oe)s',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    78
             {'rt': 'add_permission', 'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'oe': 'RQLExpression', 'ordernum': 5, 'cardinality': u'*?', 'se': 'CWEType'}),
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    79
            ('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 name %(se)s,ER name %(rt)s,OE name %(oe)s',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    80
             {'rt': 'add_permission', 'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'oe': 'RQLExpression', 'ordernum': 5, 'cardinality': u'*?', 'se': 'CWRType'}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    81
            ])
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    82
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    def test_rschema2rql3(self):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    84
        self.assertListEquals(list(rschema2rql(schema.rschema('cardinality'))),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
                             [
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    86
            ('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 symetric %(symetric)s',
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
    87
             {'description': u'', 'symetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    89
            ('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 name %(se)s,ER name %(rt)s,OE name %(oe)s',
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    90
             {'rt': 'cardinality', 'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1', 'oe': 'String', 'se': 'CWRelation'}),
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    91
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT name %(ctname)s, EDEF relation_type ER, EDEF from_entity SE, EDEF to_entity OE, ER name %(rt)s, SE name %(se)s, OE name %(oe)s, EDEF is CWAttribute',
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    92
             {'rt': 'cardinality', 'oe': 'String', 'ctname': u'SizeConstraint', 'se': 'CWRelation', 'value': u'max=2'}),
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    93
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT name %(ctname)s, EDEF relation_type ER, EDEF from_entity SE, EDEF to_entity OE, ER name %(rt)s, SE name %(se)s, OE name %(oe)s, EDEF is CWAttribute',
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    94
             {'rt': 'cardinality', 'oe': 'String', 'ctname': u'StaticVocabularyConstraint', 'se': 'CWRelation', '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'*?'"}),
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    95
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    96
            ('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 name %(se)s,ER name %(rt)s,OE name %(oe)s',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    97
             {'rt': 'cardinality', 'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1', 'oe': 'String', 'se': 'CWAttribute'}),
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    98
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT name %(ctname)s, EDEF relation_type ER, EDEF from_entity SE, EDEF to_entity OE, ER name %(rt)s, SE name %(se)s, OE name %(oe)s, EDEF is CWAttribute',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    99
             {'rt': 'cardinality', 'oe': 'String', 'ctname': u'SizeConstraint', 'se': 'CWAttribute', 'value': u'max=2'}),
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   100
            ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT name %(ctname)s, EDEF relation_type ER, EDEF from_entity SE, EDEF to_entity OE, ER name %(rt)s, SE name %(se)s, OE name %(oe)s, EDEF is CWAttribute',
2200
25bb65dc4559 test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   101
             {'rt': 'cardinality', 'oe': 'String', 'ctname': u'StaticVocabularyConstraint', 'se': 'CWAttribute', 'value': u"u'?1', u'11'"}),
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   102
            ])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    def test_updateeschema2rql1(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   106
        self.assertListEquals(list(updateeschema2rql(schema.eschema('CWAttribute'))),
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
   107
                              [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2447
diff changeset
   108
                                {'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', 'et': 'CWAttribute', 'final': False, 'name': u'CWAttribute'}),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
                               ])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   110
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
    def test_updateeschema2rql2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
        self.assertListEquals(list(updateeschema2rql(schema.eschema('String'))),
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
   113
                              [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
   114
                                {'description': u'', 'et': 'String', 'final': True, 'name': u'String'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
                               ])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   116
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
    def test_updaterschema2rql1(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
        self.assertListEquals(list(updaterschema2rql(schema.rschema('relation_type'))),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
                             [
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
   120
            ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
             {'rt': 'relation_type', 'symetric': False,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
              'description': u'link a relation definition to its relation type',
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
   123
              'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
            ])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   125
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
    def test_updaterschema2rql2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        expected = [
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
   128
            ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
             {'rt': 'add_permission', 'symetric': False,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
              'description': u'core relation giving to a group the permission to add an entity or relation type',
2447
b83fcc2311af fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2200
diff changeset
   131
              'final': False, 'fulltext_container': None, 'inlined': False, 'name': u'add_permission'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
            ]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
        for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'))):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
            yield self.assertEquals, (rql, args), expected[i]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
class Perms2RQLTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
    GROUP_MAPPING = {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
        'managers': 0,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        'users':  1,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        'guests': 2,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
        'owners': 3,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
        }
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   143
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
    def test_eperms2rql1(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   145
        self.assertListEquals([rql for rql, kwargs in erperms2rql(schema.eschema('CWEType'), self.GROUP_MAPPING)],
3897
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   146
                              ['SET X read_permission Y WHERE X is CWEType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   147
                               'SET X read_permission Y WHERE X is CWEType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   148
                               'SET X read_permission Y WHERE X is CWEType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   149
                               'SET X add_permission Y WHERE X is CWEType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   150
                               'SET X update_permission Y WHERE X is CWEType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   151
                               'SET X update_permission Y WHERE X is CWEType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   152
                               'SET X delete_permission Y WHERE X is CWEType, X name %(name)s, Y eid %(g)s',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
                               ])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   154
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
    def test_rperms2rql2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        self.assertListEquals([rql for rql, kwargs in erperms2rql(schema.rschema('read_permission'), self.GROUP_MAPPING)],
3897
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   157
                              ['SET X read_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   158
                               'SET X read_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   159
                               'SET X read_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   160
                               'SET X add_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   161
                               'SET X delete_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
                               ])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   163
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
    def test_rperms2rql3(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
        self.assertListEquals([rql for rql, kwargs in erperms2rql(schema.rschema('name'), self.GROUP_MAPPING)],
3897
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   166
                              ['SET X read_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   167
                               'SET X read_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   168
                               'SET X read_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   169
                               'SET X add_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   170
                               'SET X add_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   171
                               'SET X add_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   172
                               'SET X delete_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   173
                               'SET X delete_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
6421a0050234 cacheable queries to serialize permissions, update relevant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   174
                               'SET X delete_permission Y WHERE X is CWRType, X name %(name)s, Y eid %(g)s',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
                               ])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   176
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
    #def test_perms2rql(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
    #    self.assertListEquals(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
   179
    #                         ['INSERT CWEType X: X name 'Societe', X final FALSE'])
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   180
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
    unittest_main()