Пример #1
0
    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])
Пример #2
0
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)
Пример #3
0
 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))
Пример #4
0
class UnknownVersionedModel(Model):
    VERSION = 4
    bucket = 'versionedmodel'
    d = Integer()
Пример #5
0
class IndexedVersionedModel(Model):
    VERSION = 3
    MIGRATOR = VersionedModelMigrator
    bucket = 'versionedmodel'
    c = Integer()
    text = Unicode(null=True, index=True)
Пример #6
0
class VersionedModel(Model):
    VERSION = 2
    MIGRATOR = VersionedModelMigrator
    c = Integer()
    text = Unicode(null=True)
Пример #7
0
 def test_validate_minimum(self):
     i = Integer(min=3)
     i.validate(3)
     i.validate(4)
     self.assertRaises(ValidationError, i.validate, 2)
Пример #8
0
class OverriddenModel(InheritedModel):
    c = Integer(min=0, max=5)
Пример #9
0
class ListOfModel(Model):
    items = ListOf(Integer())
Пример #10
0
 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")
Пример #11
0
class ReferencedModel(Model):
    """
    Toy model for testing fields that reference other models.
    """
    a = Integer()
    b = Unicode()
Пример #12
0
 class IndexedSetOfModel(Model):
     """
     Toy model for SetOf index tests.
     """
     items = SetOf(Integer(), index=True)
Пример #13
0
 class SetOfModel(Model):
     """
     Toy model for SetOf tests.
     """
     items = SetOf(Integer())
     texts = SetOf(Unicode())
Пример #14
0
 class ListOfModel(Model):
     """
     Toy model for ListOf tests.
     """
     items = ListOf(Integer())
     texts = ListOf(Unicode())
Пример #15
0
 class IntegerModel(Model):
     """
     Toy model for Integer field tests.
     """
     i = Integer()
Пример #16
0
class SimpleModel(Model):
    a = Integer()
    b = Unicode()
Пример #17
0
class IndexedModel(Model):
    a = Integer(index=True)
    b = Unicode(index=True, null=True)
Пример #18
0
 def test_validate_minimum(self):
     i = Integer(min=3)
     i.validate(3)
     i.validate(4)
     self.assertRaises(ValidationError, i.validate, 2)
Пример #19
0
class InheritedModel(SimpleModel):
    c = Integer()
Пример #20
0
 def test_validate_maximum(self):
     i = Integer(max=5)
     i.validate(5)
     i.validate(4)
     self.assertRaises(ValidationError, i.validate, 6)
Пример #21
0
 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")
Пример #22
0
class UnversionedModel(Model):
    bucket = 'versionedmodel'
    a = Integer()
Пример #23
0
 def test_validate_maximum(self):
     i = Integer(max=5)
     i.validate(5)
     i.validate(4)
     self.assertRaises(ValidationError, i.validate, 6)
Пример #24
0
class OldVersionedModel(Model):
    VERSION = 1
    bucket = 'versionedmodel'
    b = Integer()