예제 #1
0
    def test_default(self):
        field = UrlField(required=True, default='https://www.onyg.de')
        field.validate()
        self.assertEqual(field.to_python(), 'https://www.onyg.de')
        self.assertEqual(field.to_native(), 'https://www.onyg.de')

        field = UrlField(required=True, default='no url')
        self.assertRaises(SerializerFieldValueError, field.validate)
예제 #2
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)
예제 #3
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)
예제 #4
0
    def test_default(self):
        field = UrlField(required=True, default='https://www.onyg.de')
        field.validate()
        self.assertEqual(field.to_python(), 'https://www.onyg.de')
        self.assertEqual(field.to_native(), 'https://www.onyg.de')

        field = UrlField(required=True, default='no url')
        self.assertRaises(SerializerFieldValueError, field.validate)
예제 #5
0
 def test_hide_on_null(self):
     field = UrlField(required=False, on_null=HIDE_FIELD)
     self.assertRaises(IgnoreField, field.to_native)
     self.assertIsNone(field.to_python())
예제 #6
0
 def test_validate_raises(self):
     field = UrlField(required=True)
     field.set_value('api')
     self.assertRaises(SerializerFieldValueError, field.validate)
예제 #7
0
 def test_base(self):
     field = UrlField(required=True, base='http://www.onyg.de')
     field.set_value('api')
     field.validate()
     self.assertEqual(field.to_python(), 'http://www.onyg.de/api')
     self.assertEqual(field.to_native(), 'http://www.onyg.de/api')
예제 #8
0
 def test_hide_on_null(self):
     field = UrlField(required=False, on_null=HIDE_FIELD)
     self.assertRaises(IgnoreField, field.to_native)
     self.assertIsNone(field.to_python())
예제 #9
0
 def test_validate_raises(self):
     field = UrlField(required=True)
     field.set_value('api')
     self.assertRaises(SerializerFieldValueError, field.validate)
예제 #10
0
 def test_base(self):
     field = UrlField(required=True, base='http://www.onyg.de')
     field.set_value('api')
     field.validate()
     self.assertEqual(field.to_python(), 'http://www.onyg.de/api')
     self.assertEqual(field.to_native(), 'http://www.onyg.de/api')