def setUp(self): import colander import limone class Person(colander.Schema): name = colander.SchemaNode(colander.String('UTF-8')) age = colander.SchemaNode(colander.Integer()) self.content_type = limone.make_content_type(Person, 'Person') self.registry = limone.Registry() self.registry.register_content_type(self.content_type)
def setUp(self): import colander import limone class NSAData(colander.Schema): serialnum = colander.SchemaNode(colander.Str('UTF-8')) date_of_contact = colander.SchemaNode(colander.Date()) class PersonalData(colander.Schema): nsa_data = NSAData() n_arrests = colander.SchemaNode(colander.Int()) class PersonSchema(colander.Schema): name = colander.SchemaNode(colander.Str('UTF-8')) age = colander.SchemaNode(colander.Integer(), default=500) personal = PersonalData() self.content_type = limone.make_content_type(PersonSchema, 'Person')
def test_base_lacks_noarg_constructor(self): import colander import limone class Base(object): def __init__(self, x): #pragma NO COVERAGE self.x = x class Schema(colander.Schema): foo = colander.SchemaNode(colander.Int()) # XXX would be a little nicer if we could catch this when generating # the type, rather than waiting for an instantiation. Foo = limone.make_content_type(Schema, 'Foo', bases=(Base,)) with self.assertRaises(TypeError) as ecm: foo = Foo(foo=1) self.assertEqual( str(ecm.exception), "Limone content types may only extend types with no-arg " "constructors.")
def test_schema_is_wrong_type(self): import limone with self.assertRaises(TypeError): limone.make_content_type(object, 'Foo')
def make_content_type(schema, name, module=None, bases=(object,), meta=_MetaType): return limone.make_content_type( schema, name, module, bases, meta)