def test_validate_with_subtype(self): """ If an explicit subtype is provided, its validation is used. """ listof_unicode = ListOf(Unicode()) listof_unicode.validate([u"a", u"b"]) self.assertRaises(ValidationError, listof_unicode.validate, [1, 2]) listof_int = ListOf(Integer()) listof_int.validate([1, 2]) self.assertRaises(ValidationError, listof_int.validate, [u"a", u"b"]) listof_smallint = ListOf(Integer(max=10)) listof_smallint.validate([1, 2]) self.assertRaises(ValidationError, listof_smallint.validate, [1, 100])
class UserTagPermissionVNone(Model): """A description of a tag a user account is allowed access to.""" bucket = "usertagpermission" # key is uuid tagpool = Unicode(max_length=255) max_keys = Integer(null=True)
class ComputedValueModel(Model): """ Toy model for ComputedValue tests. """ a = Integer() b = Unicode() c = ListOf(Unicode()) a_with_b = ComputedValue(lambda m: u"%s::%s" % (m.a, m.b), Unicode(index=True)) b_with_a = ComputedValue(lambda m: u"%s::%s" % (m.b, m.a), Unicode()) a_with_c = ComputedValue(lambda m: [u"%s::%s" % (m.a, c) for c in m.c], ListOf(Unicode(), index=True))
class IndexedVersionedModel(Model): VERSION = 3 MIGRATOR = VersionedModelMigrator bucket = 'versionedmodel' c = Integer() text = Unicode(null=True, index=True)
class VersionedModel(Model): VERSION = 2 MIGRATOR = VersionedModelMigrator c = Integer() text = Unicode(null=True)
class OldVersionedModel(Model): VERSION = 1 bucket = 'versionedmodel' b = Integer()
class UnversionedModel(Model): bucket = 'versionedmodel' a = Integer()
class InheritedModel(SimpleModel): c = Integer()
class IndexedModel(Model): a = Integer(index=True) b = Unicode(index=True, null=True)
class ReferencedModel(Model): """ Toy model for testing fields that reference other models. """ a = Integer() b = Unicode()
class IndexedSetOfModel(Model): """ Toy model for SetOf index tests. """ items = SetOf(Integer(), index=True)
class SetOfModel(Model): """ Toy model for SetOf tests. """ items = SetOf(Integer()) texts = SetOf(Unicode())
class ListOfModel(Model): """ Toy model for ListOf tests. """ items = ListOf(Integer()) texts = ListOf(Unicode())
class IntegerModel(Model): """ Toy model for Integer field tests. """ i = Integer()
class UnknownVersionedModel(Model): VERSION = 4 bucket = 'versionedmodel' d = Integer()
class SimpleModel(Model): a = Integer() b = Unicode()
def test_validate_unbounded(self): i = Integer() i.validate(5) i.validate(-3) self.assertRaises(ValidationError, i.validate, 5.0) self.assertRaises(ValidationError, i.validate, "5")
class ListOfModel(Model): items = ListOf(Integer())
def test_validate_minimum(self): i = Integer(min=3) i.validate(3) i.validate(4) self.assertRaises(ValidationError, i.validate, 2)
class OverriddenModel(InheritedModel): c = Integer(min=0, max=5)
def test_validate_maximum(self): i = Integer(max=5) i.validate(5) i.validate(4) self.assertRaises(ValidationError, i.validate, 6)