server/test/unittest_schemaserial.py
changeset 9795 e8039b12d52e
parent 9453 5c4d9dfbf176
child 9796 2d1e488f6f71
equal deleted inserted replaced
9794:61da050d11e4 9795:e8039b12d52e
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    65 class Schema2RQLTC(TestCase):
    65 class Schema2RQLTC(TestCase):
    66 
    66 
    67     def test_eschema2rql1(self):
    67     def test_eschema2rql1(self):
    68         self.assertListEqual([
    68         self.assertListEqual([
    69             ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
    69             ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
    70              {'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',
    70              {'description': u'define a final relation: '
       
    71               'link a final relation type from a non final entity '
       
    72               'to a final entity type. used to build the instance schema',
    71               'name': u'CWAttribute', 'final': False})],
    73               'name': u'CWAttribute', 'final': False})],
    72                              list(eschema2rql(schema.eschema('CWAttribute'))))
    74                              list(eschema2rql(schema.eschema('CWAttribute'))))
    73 
    75 
    74     def test_eschema2rql2(self):
    76     def test_eschema2rql2(self):
    75         self.assertListEqual([
    77         self.assertListEqual([
    84                               ('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
    86                               ('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s',
    85                                {'et': None, 'x': None})],
    87                                {'et': None, 'x': None})],
    86                              sorted(specialize2rql(schema)))
    88                              sorted(specialize2rql(schema)))
    87 
    89 
    88     def test_esche2rql_custom_type(self):
    90     def test_esche2rql_custom_type(self):
    89         expected = [('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
    91         expected = [('INSERT CWEType X: X description %(description)s,X final %(final)s,'
       
    92                      'X name %(name)s',
    90                      {'description': u'',
    93                      {'description': u'',
    91                      'name': u'BabarTestType', 'final': True},)]
    94                      'name': u'BabarTestType', 'final': True},)]
    92         got = list(eschema2rql(schema.eschema('BabarTestType')))
    95         got = list(eschema2rql(schema.eschema('BabarTestType')))
    93         self.assertListEqual(expected, got)
    96         self.assertListEqual(expected, got)
    94 
    97 
    95     def test_rschema2rql1(self):
    98     def test_rschema2rql1(self):
    96         self.assertListEqual([
    99         self.assertListEqual([
    97             ('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,'
    98              {'description': u'link a relation definition to its relation type', 'symmetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
   101              'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
    99 
   102              'X name %(name)s,X symmetric %(symmetric)s',
   100             ('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',
   103              {'description': u'link a relation definition to its relation type',
       
   104               'symmetric': False,
       
   105               'name': u'relation_type',
       
   106               'final' : False,
       
   107               'fulltext_container': None,
       
   108               'inlined': True}),
       
   109 
       
   110             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
       
   111              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
       
   112              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
   101              {'se': None, 'rt': None, 'oe': None,
   113              {'se': None, 'rt': None, 'oe': None,
   102               'description': u'', 'composite': u'object', 'cardinality': u'1*',
   114               'description': u'',
       
   115               'composite': u'object',
       
   116               'cardinality': u'1*',
   103               'ordernum': 1}),
   117               'ordernum': 1}),
   104             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   118             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
   105              {'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final TRUE\n'}),
   119              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
   106 
   120              {'x': None, 'ct': u'RQLConstraint_eid',
   107             ('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',
   121               'value': u';O;O final TRUE\n'}),
       
   122 
       
   123             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
       
   124              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
       
   125              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
   108              {'se': None, 'rt': None, 'oe': None,
   126              {'se': None, 'rt': None, 'oe': None,
   109               'description': u'', 'composite': u'object', 
   127               'description': u'', 'composite': u'object',
   110               'ordernum': 1, 'cardinality': u'1*'}),
   128               'ordernum': 1, 'cardinality': u'1*'}),
   111             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   129             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
       
   130              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
   112              {'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final FALSE\n'}),
   131              {'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final FALSE\n'}),
   113         ],
   132         ],
   114                              list(rschema2rql(schema.rschema('relation_type'), cstrtypemap)))
   133                              list(rschema2rql(schema.rschema('relation_type'), cstrtypemap)))
   115 
   134 
   116     def test_rschema2rql2(self):
   135     def test_rschema2rql2(self):
   117         self.assertListEqual([
   136         self.assertListEqual([
   118             ('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}),
   137             ('INSERT CWRType X: X description %(description)s,X final %(final)s,'
   119 
   138              'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
   120             ('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',
   139              'X name %(name)s,X symmetric %(symmetric)s',
   121              {'se': None, 'rt': None, 'oe': None,
   140              {'description': u'',
   122               'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'ordernum': 9999, 'cardinality': u'**'}),
   141               'symmetric': False,
   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',
   142               'name': u'add_permission',
   124              {'se': None, 'rt': None, 'oe': None,
   143               'final': False,
   125               'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}),
   144               'fulltext_container': None,
   126 
   145               'inlined': False}),
   127             ('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',
   146 
   128              {'se': None, 'rt': None, 'oe': None,
   147             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
   129               'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'ordernum': 9999, 'cardinality': u'**'}),
   148              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
   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',
   149              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
   131              {'se': None, 'rt': None, 'oe': None,
   150              {'se': None,
   132               'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}),
   151               'rt': None,
   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',
   152               'oe': None,
   134             {'cardinality': u'**', 'composite': None, 'description': u'groups allowed to add entities/relations of this type',
   153               'description': u'groups allowed to add entities/relations of this type',
   135              'oe': None, 'ordernum': 9999, 'rt': None, 'se': None}),
   154               'composite': None,
   136             ('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',
   155               'ordernum': 9999,
   137              {'cardinality': u'*?', 'composite': u'subject', 'description': u'rql expression allowing to add entities/relations of this type', 'oe': None, 'ordernum': 9999, 'rt': None, 'se': None})],
   156               'cardinality': u'**'}),
       
   157             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
       
   158              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
       
   159              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
       
   160              {'se': None,
       
   161               'rt': None,
       
   162               'oe': None,
       
   163               'description': u'rql expression allowing to add entities/relations of this type',
       
   164               'composite': 'subject',
       
   165               'ordernum': 9999,
       
   166               'cardinality': u'*?'}),
       
   167 
       
   168             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
       
   169              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
       
   170              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
       
   171              {'se': None,
       
   172               'rt': None,
       
   173               'oe': None,
       
   174               'description': u'groups allowed to add entities/relations of this type',
       
   175               'composite': None,
       
   176               'ordernum': 9999,
       
   177               'cardinality': u'**'}),
       
   178             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
       
   179              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
       
   180              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
       
   181              {'se': None,
       
   182               'rt': None,
       
   183               'oe': None,
       
   184               'description': u'rql expression allowing to add entities/relations of this type',
       
   185               'composite': 'subject',
       
   186               'ordernum': 9999,
       
   187               'cardinality': u'*?'}),
       
   188             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
       
   189              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
       
   190              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
       
   191             {'cardinality': u'**',
       
   192              'composite': None,
       
   193              'description': u'groups allowed to add entities/relations of this type',
       
   194              'oe': None,
       
   195              'ordernum': 9999,
       
   196              'rt': None,
       
   197              'se': None}),
       
   198             ('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,'
       
   199              'X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,'
       
   200              'X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
       
   201              {'cardinality': u'*?',
       
   202               'composite': u'subject',
       
   203               'description': u'rql expression allowing to add entities/relations of this type',
       
   204               'oe': None,
       
   205               'ordernum': 9999,
       
   206               'rt': None,
       
   207               'se': None})],
   138                              list(rschema2rql(schema.rschema('add_permission'), cstrtypemap)))
   208                              list(rschema2rql(schema.rschema('add_permission'), cstrtypemap)))
   139 
   209 
   140     def test_rschema2rql3(self):
   210     def test_rschema2rql3(self):
   141         self.assertListEqual([
   211         self.assertListEqual([
   142             ('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',
   212             ('INSERT CWRType X: X description %(description)s,X final %(final)s,'
   143              {'description': u'', 'symmetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
   213              'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
   144 
   214              'X name %(name)s,X symmetric %(symmetric)s',
   145             ('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',
   215              {'description': u'',
   146              {'se': None, 'rt': None, 'oe': None,
   216               'symmetric': False,
   147               'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1'}),
   217               'name': u'cardinality',
   148             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   218               'final': True,
   149              {'x': None, 'ct': u'SizeConstraint_eid', 'value': u'max=2'}),
   219               'fulltext_container': None,
   150             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   220               'inlined': False}),
   151              {'x': None, 'ct': u'StaticVocabularyConstraint_eid', 'value': u"u'?1', u'11'"}),
   221 
   152 
   222             ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,'
   153             ('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',
   223              'X description %(description)s,X fulltextindexed %(fulltextindexed)s,'
   154              {'se': None, 'rt': None, 'oe': None,
   224              'X indexed %(indexed)s,X internationalizable %(internationalizable)s,'
   155               'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1'}),
   225              'X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,'
   156             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   226              'X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
   157              {'x': None, 'ct': u'SizeConstraint_eid', 'value': u'max=2'}),
   227              {'se': None,
   158             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   228               'rt': None,
   159              {'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'*?'"})],
   229               'oe': None,
       
   230               'description': u'subject/object cardinality',
       
   231               'internationalizable': True,
       
   232               'fulltextindexed': False,
       
   233               'ordernum': 5,
       
   234               'defaultval': None,
       
   235               'indexed': False,
       
   236               'cardinality': u'?1'}),
       
   237             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
       
   238              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   239              {'x': None,
       
   240               'ct': u'SizeConstraint_eid',
       
   241               'value': u'max=2'}),
       
   242             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
       
   243              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   244              {'x': None,
       
   245               'ct': u'StaticVocabularyConstraint_eid',
       
   246               'value': u"u'?1', u'11'"}),
       
   247 
       
   248             ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,'
       
   249              'X description %(description)s,X fulltextindexed %(fulltextindexed)s,'
       
   250              'X indexed %(indexed)s,X internationalizable %(internationalizable)s,'
       
   251              'X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE '
       
   252              'WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
       
   253              {'se': None,
       
   254               'rt': None,
       
   255               'oe': None,
       
   256               'description': u'subject/object cardinality',
       
   257               'internationalizable': True,
       
   258               'fulltextindexed': False,
       
   259               'ordernum': 5,
       
   260               'defaultval': None,
       
   261               'indexed': False,
       
   262               'cardinality': u'?1'}),
       
   263             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
       
   264              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   265              {'x': None,
       
   266               'ct': u'SizeConstraint_eid',
       
   267               'value': u'max=2'}),
       
   268             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
       
   269              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   270              {'x': None,
       
   271               'ct': u'StaticVocabularyConstraint_eid',
       
   272               'value': (u"u'?*', u'1*', u'+*', u'**', u'?+', u'1+', u'++', u'*+', u'?1', "
       
   273                         "u'11', u'+1', u'*1', u'??', u'1?', u'+?', u'*?'")})],
   160                              list(rschema2rql(schema.rschema('cardinality'), cstrtypemap)))
   274                              list(rschema2rql(schema.rschema('cardinality'), cstrtypemap)))
   161 
   275 
   162     def test_rschema2rql_custom_type(self):
   276     def test_rschema2rql_custom_type(self):
   163         expected = [('INSERT CWRType X: X description %(description)s,X final %(final)s,'
   277         expected = [('INSERT CWRType X: X description %(description)s,X final %(final)s,'
   164                      'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
   278                      'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
   194         got[1][1]['extra_props'] = got[1][1]['extra_props'].getvalue()
   308         got[1][1]['extra_props'] = got[1][1]['extra_props'].getvalue()
   195         self.assertListEqual(expected, got)
   309         self.assertListEqual(expected, got)
   196 
   310 
   197     def test_rdef2rql(self):
   311     def test_rdef2rql(self):
   198         self.assertListEqual([
   312         self.assertListEqual([
   199             ('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',
   313             ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,'
   200              {'se': None, 'rt': None, 'oe': None,
   314              'X description %(description)s,X fulltextindexed %(fulltextindexed)s,'
   201               'description': u'', 'internationalizable': True, 'fulltextindexed': False,
   315              'X indexed %(indexed)s,X internationalizable %(internationalizable)s,'
   202               'ordernum': 3, 'defaultval': Binary('text/plain'), 'indexed': False, 'cardinality': u'?1'}),
   316              'X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,'
   203             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   317              'X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
   204              {'x': None, 'value': u'None', 'ct': 'FormatConstraint_eid'}),
   318              {'se': None,
   205             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   319               'rt': None,
   206              {'x': None, 'value': u'max=50', 'ct': 'SizeConstraint_eid'})],
   320               'oe': None,
   207                              list(rdef2rql(schema['description_format'].rdefs[('CWRType', 'String')], cstrtypemap)))
   321               'description': u'',
       
   322               'internationalizable': True,
       
   323               'fulltextindexed': False,
       
   324               'ordernum': 3,
       
   325               'defaultval': Binary('text/plain'),
       
   326               'indexed': False,
       
   327               'cardinality': u'?1'}),
       
   328             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
       
   329              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   330              {'x': None,
       
   331               'value': u'None',
       
   332               'ct': 'FormatConstraint_eid'}),
       
   333             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X '
       
   334              'WHERE CT eid %(ct)s, EDEF eid %(x)s',
       
   335              {'x': None,
       
   336               'value': u'max=50',
       
   337               'ct': 'SizeConstraint_eid'})],
       
   338                              list(rdef2rql(schema['description_format'].rdefs[('CWRType', 'String')],
       
   339                                            cstrtypemap)))
   208 
   340 
   209 
   341 
   210     def test_updateeschema2rql1(self):
   342     def test_updateeschema2rql1(self):
   211         self.assertListEqual([('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X eid %(x)s',
   343         self.assertListEqual([('SET X description %(description)s,X final %(final)s,'
   212                                {'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'})],
   344                                'X name %(name)s WHERE X eid %(x)s',
       
   345                                {'description': u'define a final relation: link a final relation type from'
       
   346                                 ' a non final entity to a final entity type. used to build the instance schema',
       
   347                                 'x': 1, 'final': False, 'name': u'CWAttribute'})],
   213                              list(updateeschema2rql(schema.eschema('CWAttribute'), 1)))
   348                              list(updateeschema2rql(schema.eschema('CWAttribute'), 1)))
   214 
   349 
   215     def test_updateeschema2rql2(self):
   350     def test_updateeschema2rql2(self):
   216         self.assertListEqual([('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X eid %(x)s',
   351         self.assertListEqual([('SET X description %(description)s,X final %(final)s,'
       
   352                                'X name %(name)s WHERE X eid %(x)s',
   217                                {'description': u'', 'x': 1, 'final': True, 'name': u'String'})],
   353                                {'description': u'', 'x': 1, 'final': True, 'name': u'String'})],
   218                              list(updateeschema2rql(schema.eschema('String'), 1)))
   354                              list(updateeschema2rql(schema.eschema('String'), 1)))
   219 
   355 
   220     def test_updaterschema2rql1(self):
   356     def test_updaterschema2rql1(self):
   221         self.assertListEqual([
   357         self.assertListEqual([
   222             ('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',
   358             ('SET X description %(description)s,X final %(final)s,'
   223              {'x': 1, 'symmetric': False,
   359              'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
       
   360              'X name %(name)s,X symmetric %(symmetric)s WHERE X eid %(x)s',
       
   361              {'x': 1,
       
   362               'symmetric': False,
   224               'description': u'link a relation definition to its relation type',
   363               'description': u'link a relation definition to its relation type',
   225               'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})],
   364               'final': False, 'fulltext_container': None,
       
   365               'inlined': True,
       
   366               'name': u'relation_type'})],
   226                              list(updaterschema2rql(schema.rschema('relation_type'), 1)))
   367                              list(updaterschema2rql(schema.rschema('relation_type'), 1)))
   227 
   368 
   228     def test_updaterschema2rql2(self):
   369     def test_updaterschema2rql2(self):
   229         expected = [
   370         expected = [
   230             ('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',
   371             ('SET X description %(description)s,X final %(final)s,'
   231              {'x': 1, 'symmetric': False,
   372              'X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,'
   232               'description': u'', 'final': False, 'fulltext_container': None,
   373              'X name %(name)s,X symmetric %(symmetric)s WHERE X eid %(x)s',
   233               'inlined': False, 'name': u'add_permission'})
   374              {'x': 1,
       
   375               'symmetric': False,
       
   376               'description': u'',
       
   377               'final': False,
       
   378               'fulltext_container': None,
       
   379               'inlined': False,
       
   380               'name': u'add_permission'})
   234             ]
   381             ]
   235         for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'), 1)):
   382         for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'), 1)):
   236             yield self.assertEqual, expected[i], (rql, args)
   383             yield self.assertEqual, expected[i], (rql, args)
   237 
   384 
   238 class Perms2RQLTC(TestCase):
   385 class Perms2RQLTC(TestCase):