Ejemplo n.º 1
0
 def setUp(self):
     self.list_field = mock.MagicMock(fields.ListField)
     self.list_field.flags = {
         'item_type': fields.IntField(),
         'notnull': True,
         'options': None,
     }
     self.validator = validators.ListValidator(self.list_field)
Ejemplo n.º 2
0
 def test_field_list_item_type_list(self):
     self.assertRaises(errors.ValidationError,
                       fields.ListField,
                       item_type=params.ListParam())
     field = fields.ListField(item_type=fields.ListField(
         item_type=fields.IntField()))
     self.assertEqual(field.validate([]), [])
     self.assertEqual(field.validate([[1, 2, 3], [True, False], [1.2]]),
                      [[1, 2, 3], [1, 0], [1]])
     self.assertRaises(errors.ValidationError, field.validate,
                       [[1, 2, 3], 4, [1.2]])
Ejemplo n.º 3
0
 def test_param_list_item_type_int(self):
     self.assertRaises(errors.ValidationError,
                       params.ListParam,
                       item_type=fields.IntField())
     param = params.ListParam(item_type=params.IntParam())
     self.assertEqual(param.validate(()), [])
     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, 'abc')
     self.assertRaises(errors.ValidationError, param.validate,
                       ['abc', 'efd'])
     self.assertRaises(errors.ValidationError, param.validate, False)
     self.assertRaises(errors.ValidationError, param.validate,
                       ['abc', 'ef'])
Ejemplo n.º 4
0
 def test_field_list_item_type_int(self):
     self.assertRaises(errors.ValidationError,
                       fields.ListField,
                       item_type=params.IntParam())
     field = fields.ListField(item_type=fields.IntField())
     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, 'abc')
     self.assertRaises(errors.ValidationError, field.validate,
                       ['abc', 'efd'])
     self.assertRaises(errors.ValidationError, field.validate, ())
     self.assertRaises(errors.ValidationError, field.validate, (1, 2, 3))
Ejemplo n.º 5
0
class CollectionParams(Resource):
    times = fields.IntField(required=True, default=1)
Ejemplo n.º 6
0
class PersonResource(Resource):
    id = fields.IntField(default=None)
    name = fields.CharField()
    birth_date = fields.DateTimeField()
    admin = fields.BoolField(default=False)
Ejemplo n.º 7
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.º 8
0
class SimpleResource(Resource):
    id = fields.IntField()
    name = fields.CharField()
Ejemplo n.º 9
0
 def setUp(self):
     self.field = fields.IntField()
Ejemplo n.º 10
0
 def setUp(self):
     self.extra = {'extra_bool': True, 'extra_str': 'Yes', 'extra_int': 100}
     self.field = fields.IntField(default=99, **self.extra)
Ejemplo n.º 11
0
class SimpleResource(resources.Resource):
    name = fields.CharField(default=None)
    age = fields.IntField(default=None)
    readonly = fields.IntField(readonly=True)
Ejemplo n.º 12
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.º 13
0
 class DefaultFuncResource(resources.Resource):
     name = fields.CharField(default=None)
     age = fields.IntField(default=default_func)