server/test/unittest_schemaserial.py
changeset 9299 c5eed908117d
parent 9141 492216093bc3
child 9395 96dba2efd16d
equal deleted inserted replaced
9296:8a4175557426 9299:c5eed908117d
    20 import sys
    20 import sys
    21 from cStringIO import StringIO
    21 from cStringIO import StringIO
    22 
    22 
    23 from logilab.common.testlib import TestCase, unittest_main
    23 from logilab.common.testlib import TestCase, unittest_main
    24 
    24 
       
    25 from cubicweb import Binary
    25 from cubicweb.schema import CubicWebSchemaLoader
    26 from cubicweb.schema import CubicWebSchemaLoader
    26 from cubicweb.devtools import TestServerConfiguration
    27 from cubicweb.devtools import TestServerConfiguration
    27 
    28 
    28 from logilab.database import get_db_helper
    29 from logilab.database import get_db_helper
    29 from yams import register_base_type, unregister_base_type
    30 from yams import register_base_type, unregister_base_type
   186         self.assertEqual(2, len(got))
   187         self.assertEqual(2, len(got))
   187         # this is a custom type attribute with an extra parameter
   188         # this is a custom type attribute with an extra parameter
   188         self.assertIn('extra_props', got[1][1])
   189         self.assertIn('extra_props', got[1][1])
   189         # this extr
   190         # this extr
   190         extra_props = got[1][1]['extra_props']
   191         extra_props = got[1][1]['extra_props']
   191         from cubicweb import Binary
       
   192         self.assertIsInstance(extra_props, Binary)
   192         self.assertIsInstance(extra_props, Binary)
   193         got[1][1]['extra_props'] = got[1][1]['extra_props'].getvalue()
   193         got[1][1]['extra_props'] = got[1][1]['extra_props'].getvalue()
   194         self.assertListEqual(expected, got)
   194         self.assertListEqual(expected, got)
   195 
   195 
   196     def test_rdef2rql(self):
   196     def test_rdef2rql(self):
   197         self.assertListEqual([
   197         self.assertListEqual([
   198             ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
   198             ('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s',
   199              {'se': None, 'rt': None, 'oe': None,
   199              {'se': None, 'rt': None, 'oe': None,
   200               'description': u'', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 3, 'defaultval': u'text/plain', 'indexed': False, 'cardinality': u'?1'}),
   200               'description': u'', 'internationalizable': True, 'fulltextindexed': False,
       
   201               'ordernum': 3, 'defaultval': Binary('text/plain'), 'indexed': False, 'cardinality': u'?1'}),
   201             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   202             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   202              {'x': None, 'value': u'None', 'ct': 'FormatConstraint_eid'}),
   203              {'x': None, 'value': u'None', 'ct': 'FormatConstraint_eid'}),
   203             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   204             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s',
   204              {'x': None, 'value': u'max=50', 'ct': 'SizeConstraint_eid'})],
   205              {'x': None, 'value': u'max=50', 'ct': 'SizeConstraint_eid'})],
   205                              list(rdef2rql(schema['description_format'].rdefs[('CWRType', 'String')], cstrtypemap)))
   206                              list(rdef2rql(schema['description_format'].rdefs[('CWRType', 'String')], cstrtypemap)))