Example #1
0
    def test_unicode_serialization(self):
        field = UnicodeField()

        assert field.serialize(u'wow ☃')

        assert field.serialize('still ok')

        assert field.serialize(1.0)

        assert field.serialize(None) is None

        field = UnicodeField(strict=True)

        assert field.serialize(u'nice snowman ☃')

        assert field.serialize('not strict enough')
Example #2
0
 def test_optional_validation(self):
     """Fields are required by default but can be made optional"""
     fields = [
         IntegerField(required=False),
         UnicodeField(required=False),
         ObjectField(required=False),
         ArrayField(required=False),
         IsoDateString(required=False),
         # subschema tested elsewhere...
     ]
     for field in fields:
         assert field.validate(None)
Example #3
0
    def test_unicode_serialization(self):
        field = UnicodeField()

        assert field.serialize(u"wow ☃")

        assert field.serialize("still ok")

        assert field.serialize(1.0)

        assert field.serialize(None) is None

        field = UnicodeField(strict=True)

        assert field.serialize(u"nice snowman ☃")

        assert field.serialize("not strict enough")
Example #4
0
 class FirstSchema(Schema):
     foo = UnicodeField(required=False, default=default)
Example #5
0
    def test_unicode_validation(self):
        field = UnicodeField()

        assert field.validate(u"wow ☃")

        assert field.validate("still ok")

        with self.assertRaises(Invalid):
            field.validate(1.0)

        with self.assertRaises(Invalid):
            field.validate(None)

        field = UnicodeField(required=False)

        assert field.validate(u"wow ☃")

        assert field.validate(None)

        with self.assertRaises(Invalid):
            field.validate(1)

        field = UnicodeField(strict=True)

        assert field.validate(u"nice snowman ☃")

        with self.assertRaises(Invalid):
            field.validate("not strict enough")
Example #6
0
class RoundHole(Schema):
    id = UnicodeField()
    name = UnicodeField()
    diameter = NumberField()
Example #7
0
class DefaultsSchema(Schema):
    not_defaulted = UnicodeField()
    defaulted = UnicodeField(default="testing")
Example #8
0
 class Sub(Schema):
     foo = UnicodeField()
Example #9
0
class Ship(Schema):
    name = UnicodeField()
    captain = Subschema(Person)
Example #10
0
class Person(Schema):
    first_name = UnicodeField()
    last_name = UnicodeField()
Example #11
0
class Schema2(Schema):
    peas = UnicodeField()
    carrots = IntegerField()
    beans = IntegerField()
Example #12
0
 class Whoa(Schema):
     __lambda = UnicodeField()
Example #13
0
 class Out(Schema):
     wow = UnicodeField()
Example #14
0
 class In(Schema):
     __finally = UnicodeField()
Example #15
0
 class MySchema(Schema):
     content = UnicodeField()
Example #16
0
 class Inner(Schema):
     foo = UnicodeField()
Example #17
0
class SquarePeg(Schema):
    id = IntegerField()
    name = UnicodeField()
    width = NumberField()
Example #18
0
    def test_unicode_validation(self):
        field = UnicodeField()

        assert field.validate(u'wow ☃')

        assert field.validate('still ok')

        with self.assertRaises(Invalid):
            field.validate(1.0)

        with self.assertRaises(Invalid):
            field.validate(None)

        field = UnicodeField(required=False)

        assert field.validate(u'wow ☃')

        assert field.validate(None)

        with self.assertRaises(Invalid):
            field.validate(1)

        field = UnicodeField(strict=True)

        assert field.validate(u'nice snowman ☃')

        if six.PY2:
            with self.assertRaises(Invalid):
                field.validate('not strict enough')
Example #19
0
class Schema1(Schema):
    my_str = UnicodeField()
    my_int = IntegerField()
    another_str = UnicodeField()