server/test/unittest_schemaserial.py
changeset 4763 81b0df087375
parent 4680 8a6bee838464
child 4766 162b2b127b15
equal deleted inserted replaced
4762:8dce25da9d95 4763:81b0df087375
    15 config.bootstrap_cubes()
    15 config.bootstrap_cubes()
    16 schema = loader.load(config)
    16 schema = loader.load(config)
    17 
    17 
    18 from cubicweb.server.schemaserial import *
    18 from cubicweb.server.schemaserial import *
    19 from cubicweb.server.schemaserial import _erperms2rql as erperms2rql
    19 from cubicweb.server.schemaserial import _erperms2rql as erperms2rql
       
    20 
       
    21 cstrtypemap = {'RQLConstraint': 'RQLConstraint_eid',
       
    22                'SizeConstraint': 'SizeConstraint_eid',
       
    23                'StaticVocabularyConstraint': 'StaticVocabularyConstraint_eid',
       
    24                'FormatConstraint': 'FormatConstraint_eid',
       
    25                }
    20 
    26 
    21 class Schema2RQLTC(TestCase):
    27 class Schema2RQLTC(TestCase):
    22 
    28 
    23     def test_eschema2rql1(self):
    29     def test_eschema2rql1(self):
    24         self.assertListEquals(list(eschema2rql(schema.eschema('CWAttribute'))),
    30         self.assertListEquals(list(eschema2rql(schema.eschema('CWAttribute'))),
    32         self.assertListEquals(list(eschema2rql(schema.eschema('String'))), [
    38         self.assertListEquals(list(eschema2rql(schema.eschema('String'))), [
    33                 ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
    39                 ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
    34                  {'description': u'', 'final': True, 'name': u'String'})])
    40                  {'description': u'', 'final': True, 'name': u'String'})])
    35 
    41 
    36     def test_eschema2rql_specialization(self):
    42     def test_eschema2rql_specialization(self):
       
    43         # x: None since eschema.eid are None
    37         self.assertListEquals(sorted(specialize2rql(schema)),
    44         self.assertListEquals(sorted(specialize2rql(schema)),
    38                               [('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
    45                               [('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
    39                                 {'et': 'BaseTransition', 'x': 'Transition'}),
    46                                 {'et': None, 'x': None}),
    40                                ('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
    47                                ('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
    41                                 {'et': 'BaseTransition', 'x': 'WorkflowTransition'}),
    48                                 {'et': None, 'x': None}),
    42                                ('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
    49                                ('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
    43                                 {'et': 'Division', 'x': 'SubDivision'}),
    50                                 {'et': None, 'x': None}),
    44                                # ('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
    51                                # ('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
    45                                #  {'et': 'File', 'x': 'Image'}),
    52                                #  {'et': 'File', 'x': 'Image'}),
    46                                ('SET X specializes ET WHERE X name %(x)s, ET name %(et)s',
    53                                ('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
    47                                 {'et': 'Societe', 'x': 'Division'})])
    54                                 {'et': None, 'x': None})])
    48 
    55 
    49     def test_rschema2rql1(self):
    56     def test_rschema2rql1(self):
    50         self.assertListEquals(list(rschema2rql(schema.rschema('relation_type'))),
    57         self.assertListEquals(list(rschema2rql(schema.rschema('relation_type'), cstrtypemap)),
    51                              [
    58                              [
    52             ('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',
    59             ('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',
    53              {'description': u'link a relation definition to its relation type', 'symmetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
    60              {'description': u'link a relation definition to its relation type', 'symmetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
    54 
    61 
    55             ('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',
    62             ('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',
    56              {'rt': 'relation_type', 'description': u'', 'composite': u'object', 'oe': 'CWRType',
    63              {'se': None, 'rt': None, 'oe': None,
    57               'ordernum': 1, 'cardinality': u'1*', 'se': 'CWAttribute'}),
    64               'description': u'', 'composite': u'object', 'cardinality': u'1*',
    58             ('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',
    65               'ordernum': 1}),
    59              {'rt': 'relation_type', 'oe': 'CWRType', 'ctname': u'RQLConstraint', 'se': 'CWAttribute', 'value': u';O;O final TRUE\n'}),
    66             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
    60 
    67              {'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final TRUE\n'}),
    61             ('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',
    68 
    62              {'rt': 'relation_type', 'description': u'', 'composite': u'object', 'oe': 'CWRType',
    69             ('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',
    63               'ordernum': 1, 'cardinality': u'1*', 'se': 'CWRelation'}),
    70              {'se': None, 'rt': None, 'oe': None,
    64             ('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',
    71               'description': u'', 'composite': u'object', 
    65              {'rt': 'relation_type', 'oe': 'CWRType', 'ctname': u'RQLConstraint', 'se': 'CWRelation', 'value': u';O;O final FALSE\n'}),
    72               'ordernum': 1, 'cardinality': u'1*'}),
       
    73             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
    74              {'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final FALSE\n'}),
    66             ])
    75             ])
    67 
    76 
    68     def test_rschema2rql2(self):
    77     def test_rschema2rql2(self):
    69         self.assertListEquals(list(rschema2rql(schema.rschema('add_permission'))),
    78         self.assertListEquals(list(rschema2rql(schema.rschema('add_permission'), cstrtypemap)),
    70                               [
    79                               [
    71             ('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}),
    80             ('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}),
    72 
    81 
    73             ('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',
    82             ('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',
    74              {'rt': 'add_permission', 'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'oe': 'CWGroup', 'ordernum': 9999, 'cardinality': u'**', 'se': 'CWEType'}),
    83              {'se': None, 'rt': None, 'oe': None,
    75             ('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',
    84               'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'ordernum': 9999, 'cardinality': u'**'}),
    76              {'rt': 'add_permission', 'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'oe': 'RQLExpression', 'ordernum': 9999, 'cardinality': u'*?', 'se': 'CWEType'}),
    85             ('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',
    77 
    86              {'se': None, 'rt': None, 'oe': None,
    78             ('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',
    87               'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}),
    79              {'rt': 'add_permission', 'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'oe': 'CWGroup', 'ordernum': 9999, 'cardinality': u'**', 'se': 'CWRelation'}),
    88 
    80             ('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',
    89             ('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',
    81              {'rt': 'add_permission', 'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'oe': 'RQLExpression', 'ordernum': 9999, 'cardinality': u'*?', 'se': 'CWRelation'}),
    90              {'se': None, 'rt': None, 'oe': None,
       
    91               'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'ordernum': 9999, 'cardinality': u'**'}),
       
    92             ('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',
       
    93              {'se': None, 'rt': None, 'oe': None,
       
    94               'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}),
    82             ])
    95             ])
    83 
    96 
    84     def test_rschema2rql3(self):
    97     def test_rschema2rql3(self):
    85         self.assertListEquals(list(rschema2rql(schema.rschema('cardinality'))),
    98         self.assertListEquals(list(rschema2rql(schema.rschema('cardinality'), cstrtypemap)),
    86                              [
    99                              [
    87             ('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',
   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',
    88              {'description': u'', 'symmetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
   101              {'description': u'', 'symmetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
    89 
   102 
    90             ('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',
   103             ('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',
    91              {'rt': 'cardinality', 'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1', 'oe': 'String', 'se': 'CWAttribute'}),
   104              {'se': None, 'rt': None, 'oe': None,
    92             ('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',
   105               'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1'}),
    93              {'rt': 'cardinality', 'oe': 'String', 'ctname': u'SizeConstraint', 'se': 'CWAttribute', 'value': u'max=2'}),
   106             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
    94             ('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',
   107              {'x': None, 'ct': u'SizeConstraint_eid', 'value': u'max=2'}),
    95              {'rt': 'cardinality', 'oe': 'String', 'ctname': u'StaticVocabularyConstraint', 'se': 'CWAttribute', 'value': u"u'?1', u'11'"}),
   108             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
    96 
   109              {'x': None, 'ct': u'StaticVocabularyConstraint_eid', 'value': u"u'?1', u'11'"}),
    97             ('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',
   110 
    98              {'rt': 'cardinality', 'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1', 'oe': 'String', 'se': 'CWRelation'}),
   111             ('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',
    99             ('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',
   112              {'se': None, 'rt': None, 'oe': None,
   100              {'rt': 'cardinality', 'oe': 'String', 'ctname': u'SizeConstraint', 'se': 'CWRelation', 'value': u'max=2'}),
   113               'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1'}),
   101             ('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',
   114             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   102              {'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'*?'"}),
   115              {'x': None, 'ct': u'SizeConstraint_eid', 'value': u'max=2'}),
   103             ])
   116             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   117              {'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'*?'"}),
       
   118             ])
       
   119 
       
   120     def test_rdef2rql(self):
       
   121         self.assertListEquals(list(rdef2rql(schema['description_format'].rdefs[('CWRType', 'String')], cstrtypemap)),
       
   122                               [
       
   123             ('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',
       
   124              {'se': None, 'rt': None, 'oe': None,
       
   125               'description': u'', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 7, 'defaultval': u'text/plain', 'indexed': False, 'cardinality': u'?1'}),
       
   126             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   127              {'x': None, 'value': u'None', 'ct': 'FormatConstraint_eid'}),
       
   128             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   129              {'x': None, 'value': u'max=50', 'ct': 'SizeConstraint_eid'})])
   104 
   130 
   105 
   131 
   106     def test_updateeschema2rql1(self):
   132     def test_updateeschema2rql1(self):
   107         self.assertListEquals(list(updateeschema2rql(schema.eschema('CWAttribute'))),
   133         self.assertListEquals(list(updateeschema2rql(schema.eschema('CWAttribute'), 1)),
   108                               [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
   134                               [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X eid %(x)s',
   109                                 {'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'}),
   135                                 {'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'}),
   110                                ])
   136                                ])
   111 
   137 
   112     def test_updateeschema2rql2(self):
   138     def test_updateeschema2rql2(self):
   113         self.assertListEquals(list(updateeschema2rql(schema.eschema('String'))),
   139         self.assertListEquals(list(updateeschema2rql(schema.eschema('String'), 1)),
   114                               [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
   140                               [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X eid %(x)s',
   115                                 {'description': u'', 'et': 'String', 'final': True, 'name': u'String'})
   141                                 {'description': u'', 'x': 1, 'final': True, 'name': u'String'})
   116                                ])
   142                                ])
   117 
   143 
   118     def test_updaterschema2rql1(self):
   144     def test_updaterschema2rql1(self):
   119         self.assertListEquals(list(updaterschema2rql(schema.rschema('relation_type'))),
   145         self.assertListEquals(list(updaterschema2rql(schema.rschema('relation_type'), 1)),
   120                              [
   146                              [
   121             ('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 is CWRType, X name %(rt)s',
   147             ('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',
   122              {'rt': 'relation_type', 'symmetric': False,
   148              {'x': 1, 'symmetric': False,
   123               'description': u'link a relation definition to its relation type',
   149               'description': u'link a relation definition to its relation type',
   124               'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})
   150               'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})
   125             ])
   151             ])
   126 
   152 
   127     def test_updaterschema2rql2(self):
   153     def test_updaterschema2rql2(self):
   128         expected = [
   154         expected = [
   129             ('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 is CWRType, X name %(rt)s',
   155             ('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',
   130              {'rt': 'add_permission', 'symmetric': False,
   156              {'x': 1, 'symmetric': False,
   131               'description': u'', 'final': False, 'fulltext_container': None,
   157               'description': u'', 'final': False, 'fulltext_container': None,
   132               'inlined': False, 'name': u'add_permission'})
   158               'inlined': False, 'name': u'add_permission'})
   133             ]
   159             ]
   134         for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'))):
   160         for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'), 1)):
   135             yield self.assertEquals, (rql, args), expected[i]
   161             yield self.assertEquals, (rql, args), expected[i]
   136 
   162 
   137 class Perms2RQLTC(TestCase):
   163 class Perms2RQLTC(TestCase):
   138     GROUP_MAPPING = {
   164     GROUP_MAPPING = {
   139         'managers': 0,
   165         'managers': 0,
   142         'owners': 3,
   168         'owners': 3,
   143         }
   169         }
   144 
   170 
   145     def test_eperms2rql1(self):
   171     def test_eperms2rql1(self):
   146         self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.eschema('CWEType'), self.GROUP_MAPPING)],
   172         self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.eschema('CWEType'), self.GROUP_MAPPING)],
   147                               [('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
   173                               [('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   148                                ('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 1}),
   174                                ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}),
   149                                ('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 2}),
   175                                ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}),
   150                                ('SET X add_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
   176                                ('SET X add_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   151                                ('SET X update_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
   177                                ('SET X update_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   152                                ('SET X update_permission Y WHERE Y eid %(g)s, ', {'g': 3}),
   178                                ('SET X delete_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   153                                ('SET X delete_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
       
   154                                ])
   179                                ])
   155 
   180 
   156     def test_rperms2rql2(self):
   181     def test_rperms2rql2(self):
   157         self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.rschema('read_permission').rdef('CWEType', 'CWGroup'), self.GROUP_MAPPING)],
   182         self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.rschema('read_permission').rdef('CWEType', 'CWGroup'), self.GROUP_MAPPING)],
   158                               [('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
   183                               [('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   159                                ('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 1}),
   184                                ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}),
   160                                ('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 2}),
   185                                ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}),
   161                                ('SET X add_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
   186                                ('SET X add_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   162                                ('SET X delete_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
   187                                ('SET X delete_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   163                                ])
   188                                ])
   164 
   189 
   165     def test_rperms2rql3(self):
   190     def test_rperms2rql3(self):
   166         self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.rschema('name').rdef('CWEType', 'String'), self.GROUP_MAPPING)],
   191         self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.rschema('name').rdef('CWEType', 'String'), self.GROUP_MAPPING)],
   167                               [('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
   192                               [('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   168                                ('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 1}),
   193                                ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}),
   169                                ('SET X read_permission Y WHERE Y eid %(g)s, ', {'g': 2}),
   194                                ('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}),
   170                                ('SET X update_permission Y WHERE Y eid %(g)s, ', {'g': 0}),
   195                                ('SET X update_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}),
   171                                ('INSERT RQLExpression E: '
       
   172                                 'E expression %(e)s, E exprtype %(t)s, E mainvars %(v)s, '
       
   173                                 'X update_permission E '
       
   174                                 'WHERE ', # completed by the outer function
       
   175                                 {'e': u'U has_update_permission X', 't': u'ERQLExpression', 'v': u'X'}),
       
   176                                ])
   196                                ])
   177 
   197 
   178     #def test_perms2rql(self):
   198     #def test_perms2rql(self):
   179     #    self.assertListEquals(perms2rql(schema, self.GROUP_MAPPING),
   199     #    self.assertListEquals(perms2rql(schema, self.GROUP_MAPPING),
   180     #                         ['INSERT CWEType X: X name 'Societe', X final FALSE'])
   200     #                         ['INSERT CWEType X: X name 'Societe', X final FALSE'])