Ejemplo n.º 1
0
 def test_param_list_item_type_char(self):
     self.assertRaises(errors.ValidationError,
                       params.ListParam,
                       item_type=fields.CharField())
     param = params.ListParam(item_type=params.CharParam())
     self.assertEqual(param.validate([]), [])
     self.assertEqual(param.validate(()), [])
     self.assertEqual(param.validate('abd'), ['abd'])
     self.assertEqual(param.validate('1,2,3'), ['1', '2', '3'])
     self.assertEqual(param.validate(('1', '2', '3')), ['1', '2', '3'])
     self.assertEqual(param.validate((1, 2, 3)), ['1', '2', '3'])
     self.assertRaises(errors.ValidationError, param.validate, 1)
     self.assertRaises(errors.ValidationError, param.validate, False)
Ejemplo n.º 2
0
 def test_field_list_item_type_char(self):
     self.assertRaises(errors.ValidationError,
                       fields.ListField,
                       item_type=params.CharParam())
     field = fields.ListField(item_type=fields.CharField())
     self.assertEqual(field.validate([]), [])
     self.assertEqual(field.validate(['1', '2', '3']), ['1', '2', '3'])
     self.assertEqual(field.validate([1, 2, 3]), ['1', '2', '3'])
     self.assertEqual(field.validate((), cast=True), [])
     self.assertEqual(field.validate(('1', '2', '3'), cast=True),
                      ['1', '2', '3'])
     self.assertEqual(field.validate((1, 2, 3), cast=True), ['1', '2', '3'])
     self.assertEqual(field.validate('1,2,3', cast=True), ['1', '2', '3'])
     self.assertRaises(errors.ValidationError, field.validate, ())
     self.assertRaises(errors.ValidationError, field.validate, (1, 2, 3))
Ejemplo n.º 3
0
class PersonResource(Resource):
    id = fields.IntField(default=None)
    name = fields.CharField()
    birth_date = fields.DateTimeField()
    admin = fields.BoolField(default=False)
Ejemplo n.º 4
0
class ComplexResource(Resource):
    id = fields.IntField(notnull=True)
    name = fields.CharField(default='noname')
    items = fields.ListField(item_type=fields.IntField())
    hash_map = fields.DictField(notnull=True)
    unique = fields.SetField()
Ejemplo n.º 5
0
class SimpleResource(Resource):
    id = fields.IntField()
    name = fields.CharField()
Ejemplo n.º 6
0
 def setUp(self):
     self.field = fields.CharField()
Ejemplo n.º 7
0
class SimpleResource(resources.Resource):
    name = fields.CharField(default=None)
    age = fields.IntField(default=None)
    readonly = fields.IntField(readonly=True)
Ejemplo n.º 8
0
class ComplexResource(resources.Resource):
    name = fields.CharField(max_length=20)
    age = fields.IntField()
    admin = fields.BoolField(default=True)
    birth_date = fields.DateTimeField()
Ejemplo n.º 9
0
 class DefaultFuncResource(resources.Resource):
     name = fields.CharField(default=None)
     age = fields.IntField(default=default_func)