Esempio n. 1
0
 def test_default(self):
     int_field = IntegerField(required=True,
                              max_value=24,
                              min_value=22,
                              default=23)
     self.assertEqual(int_field.to_python(), 23)
     self.assertEqual(int_field.to_native(), 23)
Esempio n. 2
0
 def test_required(self):
     field = IntegerField(required=True)
     try:
         field.validate()
     except SerializerFieldValueError as e:
         self.assertEqual(repr(e), 'This field is required.')
         self.assertEqual(str(e), '[field]: This field is required.')
     else:
         self.fail('SerializerFieldValueError not raised.')
Esempio n. 3
0
 def test_required(self):
     field = IntegerField(required=True)
     try:
         field.validate()
     except SerializerFieldValueError as e:
         self.assertEqual(repr(e), 'This field is required.')
         self.assertEqual(str(e), '[field]: This field is required.')
     else:
         self.fail('SerializerFieldValueError not raised.')
Esempio n. 4
0
    def test_max_min(self):
        int_field = IntegerField(required=True, max_value=24, min_value=22)
        int_field.set_value(23)
        int_field.validate()
        self.assertEqual(int_field.to_python(), 23)
        self.assertEqual(int_field.to_native(), 23)

        int_field = IntegerField(required=True, max_value=24, min_value=22)
        int_field.set_value(100)
        self.assertRaises(SerializerFieldValueError, int_field.validate)
Esempio n. 5
0
class TestFlatSerializer(Serializer):
    _type = TypeField('test_object')
    id = IntegerField(required=True, identity=True)
    name = StringField(required=True)
    street = StringField(required=False, on_null=HIDE_FIELD)
    uuid_var = UUIDField(required=True)
    maxmin = IntegerField(max_value=10, min_value=6, required=True)
    datetime_var = DatetimeField(required=True)
    date_var = DateField(required=True)
    time_var = TimeField(required=True)
    haus = StringField(required=True, map_field='house')
    url = UrlField(required=True, base='http://www.base.com', default='api')
    action = StringField(required=False, action_field=True)
Esempio n. 6
0
    class TestNestSerializer(Serializer):
        class NestSerializer(Serializer):
            name = StringField(required=True)
            id = IntegerField(required=True, identity=True)
            planet = StringField(required=True)
            os = StringField(required=True)

        _type = TypeField('test_object')
        id = IntegerField(required=True, identity=True)
        name = StringField(required=True)
        nest = SerializerField(NestSerializer, fields=['name'], required=True)
Esempio n. 7
0
class MySerializer(Serializer):
    class MyNestSerializer(Serializer):
        name = StringField(required=True)
        id = IntegerField(required=True, identity=True)

    _type = TypeField('test_object')
    id = IntegerField(required=True, identity=True)
    name = StringField(required=True)
    date_var = DateField(required=True, map_field='dt')
    time_var = TimeField(required=True, map_field='t')
    url = UrlField(required=True, base='http://www.base.com', default='api')
    nest = SerializerField(MyNestSerializer, required=True)
Esempio n. 8
0
 class LazyFieldNestSerializer(Serializer):
     name = StringField(required=True)
     id = IntegerField(required=True, identity=True)
Esempio n. 9
0
 class LazyFieldSerializer(Serializer):
     _type = TypeField('test_object')
     id = IntegerField(required=True, identity=True)
     nest = SerializerField('LazyFieldNestSerializer', required=True)
Esempio n. 10
0
 class NotRequired(Serializer):
     number = IntegerField(required=False)
     name = DecimalField(required=False)
Esempio n. 11
0
 def test_default(self):
     int_field = IntegerField(required=True, max_value=24, min_value=22, default=23)
     self.assertEqual(int_field.to_python(), 23)
     self.assertEqual(int_field.to_native(), 23)
Esempio n. 12
0
 class KnownTestSerialzer(Serializer):
     code = StringField(required=True, max_length=3)
     number = IntegerField(required=True)
     address = SerializerField(UnknownTestSerialzer, required=True)
Esempio n. 13
0
 def test_hide_on_null(self):
     int_field = IntegerField(required=False, on_null=HIDE_FIELD)
     self.assertRaises(IgnoreField, int_field.to_native)
     self.assertIsNone(int_field.to_python())
Esempio n. 14
0
 def test_validate_raises(self):
     int_field = IntegerField(required=True)
     int_field.set_value('int')
     self.assertRaises(SerializerFieldValueError, int_field.validate)
Esempio n. 15
0
 class TestSerializer(Serializer):
     uuid = UUIDField(required=True)
     name = StringField(required=True)
     foo_number = IntegerField(required=False)
Esempio n. 16
0
 def test_set_value_string(self):
     int_field = IntegerField(required=True)
     int_field.set_value('24')
     int_field.validate()
     self.assertEqual(int_field.to_python(), 24)
     self.assertEqual(int_field.to_native(), 24)
Esempio n. 17
0
 def test_hide_on_null(self):
     int_field = IntegerField(required=False, on_null=HIDE_FIELD)
     self.assertRaises(IgnoreField, int_field.to_native)
     self.assertIsNone(int_field.to_python())
Esempio n. 18
0
class TestSerializer(Serializer):
    name = StringField(required=True)
    number = IntegerField(required=True, max_value=10, min_value=5)
Esempio n. 19
0
    def test_max_min(self):
        int_field = IntegerField(required=True, max_value=24, min_value=22)
        int_field.set_value(23)
        int_field.validate()
        self.assertEqual(int_field.to_python(), 23)
        self.assertEqual(int_field.to_native(), 23)

        int_field = IntegerField(required=True, max_value=24, min_value=22)
        int_field.set_value(100)
        self.assertRaises(SerializerFieldValueError, int_field.validate)
Esempio n. 20
0
 class NestSerializer(Serializer):
     name = StringField(required=True)
     id = IntegerField(required=True, identity=True)
     planet = StringField(required=True)
     os = StringField(required=True)
Esempio n. 21
0
 def test_set_value_string(self):
     int_field = IntegerField(required=True)
     int_field.set_value('24')
     int_field.validate()
     self.assertEqual(int_field.to_python(), 24)
     self.assertEqual(int_field.to_native(), 24)
Esempio n. 22
0
 class KnownTestSerialzer(Serializer):
     code = StringField(required=True, max_length=3)
     number = IntegerField(required=True)
     address = SerializerField(NestKnownTestSerialzer,
                               required=True,
                               fields=['street'])
Esempio n. 23
0
 def test_validate_raises(self):
     int_field = IntegerField(required=True)
     int_field.set_value('int')
     self.assertRaises(SerializerFieldValueError, int_field.validate)