Пример #1
0
 class ISchemaTest(Interface):
     title = Bytes(title=u("Title"),
                   description=u("Title"),
                   default=b(""),
                   required=True)
     description = Bytes(title=u("Description"),
                         description=u("Description"),
                         default=b(""),
                         required=True)
     spam = Bytes(title=u("Spam"),
                  description=u("Spam"),
                  default=b(""),
                  required=True)
Пример #2
0
 def test_validate_wrong_types(self):
     from zope.schema.interfaces import WrongType
     from zope.schema._compat import b
     field = self._makeOne()
     self.assertRaises(WrongType, field.validate, b(''))
     self.assertRaises(WrongType, field.validate, 1)
     self.assertRaises(WrongType, field.validate, 1.0)
     self.assertRaises(WrongType, field.validate, ())
     self.assertRaises(WrongType, field.validate, [])
     self.assertRaises(WrongType, field.validate, {})
     self.assertRaises(WrongType, field.validate, set())
     self.assertRaises(WrongType, field.validate, frozenset())
     self.assertRaises(WrongType, field.validate, object())
Пример #3
0
 def test_validate_wrong_types(self):
     from zope.schema.interfaces import WrongType
     from zope.schema._compat import b
     field = self._makeOne()
     self.assertRaises(WrongType, field.validate, b(''))
     self.assertRaises(WrongType, field.validate, 1)
     self.assertRaises(WrongType, field.validate, 1.0)
     self.assertRaises(WrongType, field.validate, ())
     self.assertRaises(WrongType, field.validate, [])
     self.assertRaises(WrongType, field.validate, {})
     self.assertRaises(WrongType, field.validate, set())
     self.assertRaises(WrongType, field.validate, frozenset())
     self.assertRaises(WrongType, field.validate, object())
Пример #4
0
 def test_non_fields(self):
     from zope.schema._compat import b
     from zope.schema._compat import u
     self.assertEqual(self._callFUT(None), False)
     self.assertEqual(self._callFUT(0), False)
     self.assertEqual(self._callFUT(0.0), False)
     self.assertEqual(self._callFUT(True), False)
     self.assertEqual(self._callFUT(b('')), False)
     self.assertEqual(self._callFUT(u('')), False)
     self.assertEqual(self._callFUT(()), False)
     self.assertEqual(self._callFUT([]), False)
     self.assertEqual(self._callFUT({}), False)
     self.assertEqual(self._callFUT(set()), False)
     self.assertEqual(self._callFUT(frozenset()), False)
     self.assertEqual(self._callFUT(object()), False)
Пример #5
0
 def test_non_fields(self):
     from zope.schema._compat import b
     from zope.schema._compat import u
     self.assertEqual(self._callFUT(None), False)
     self.assertEqual(self._callFUT(0), False)
     self.assertEqual(self._callFUT(0.0), False)
     self.assertEqual(self._callFUT(True), False)
     self.assertEqual(self._callFUT(b('')), False)
     self.assertEqual(self._callFUT(u('')), False)
     self.assertEqual(self._callFUT(()), False)
     self.assertEqual(self._callFUT([]), False)
     self.assertEqual(self._callFUT({}), False)
     self.assertEqual(self._callFUT(set()), False)
     self.assertEqual(self._callFUT(frozenset()), False)
     self.assertEqual(self._callFUT(object()), False)
    def test_basic(self):
        from zope.schema._compat import b
        from zope.schema._compat import u
        from zope.schema.interfaces import ValidationError
        c = self._makeImplementer()
        self.assertEqual(c.title, u('say something'))
        self.assertEqual(c.weight, None)
        self.assertEqual(c.code, b('xxxxxx'))
        self.assertRaises(ValidationError, setattr, c, 'title', b('foo'))
        self.assertRaises(ValidationError, setattr, c, 'weight', b('foo'))
        self.assertRaises(ValidationError, setattr, c, 'weight', -1.0)
        self.assertRaises(ValidationError, setattr, c, 'weight', 2)
        self.assertRaises(ValidationError, setattr, c, 'code', -1)
        self.assertRaises(ValidationError, setattr, c, 'code', b('xxxx'))
        self.assertRaises(ValidationError, setattr, c, 'code', u('xxxxxx'))

        c.title = u('c is good')
        c.weight = 10.0
        c.code = b('abcdef')

        self.assertEqual(c.title, u('c is good'))
        self.assertEqual(c.weight, 10)
        self.assertEqual(c.code, b('abcdef'))
Пример #7
0
    def test_basic(self):
        from zope.schema._compat import b
        from zope.schema._compat import u
        from zope.schema.interfaces import ValidationError
        c = self._makeImplementer()
        self.assertEqual(c.title, u('say something'))
        self.assertEqual(c.weight, None)
        self.assertEqual(c.code, b('xxxxxx'))
        self.assertRaises(ValidationError, setattr, c, 'title', b('foo'))
        self.assertRaises(ValidationError, setattr, c, 'weight', b('foo'))
        self.assertRaises(ValidationError, setattr, c, 'weight', -1.0)
        self.assertRaises(ValidationError, setattr, c, 'weight', 2)
        self.assertRaises(ValidationError, setattr, c, 'code', -1)
        self.assertRaises(ValidationError, setattr, c, 'code', b('xxxx'))
        self.assertRaises(ValidationError, setattr, c, 'code', u('xxxxxx'))

        c.title = u('c is good')
        c.weight = 10.0
        c.code = b('abcdef')

        self.assertEqual(c.title, u('c is good'))
        self.assertEqual(c.weight, 10)
        self.assertEqual(c.code, b('abcdef'))
Пример #8
0
 def test_fromUnicode_miss(self):
     from zope.schema._bootstrapinterfaces import WrongType
     from zope.schema._compat import b
     deadbeef = b('DEADBEEF')
     txt = self._makeOne()
     self.assertRaises(WrongType, txt.fromUnicode, deadbeef)
Пример #9
0
 def test_validate_w_invalid_default(self):
     from zope.schema._compat import b
     from zope.schema.interfaces import ValidationError
     self.assertRaises(ValidationError, self._makeOne, default=b(''))
Пример #10
0
 class ISchemaTestSubclass(base):
     foo = Bytes(
         title=u('Foo'),
         description=u('Fooness'),
         default=b(""),
         required=False)
Пример #11
0
 def constraint(self, value):
     # TODO: we should probably use a more general definition of newlines
     return b('\n') not in value
Пример #12
0
 def test_fromUnicode_miss(self):
     from zope.schema._bootstrapinterfaces import WrongType
     from zope.schema._compat import b
     deadbeef = b('DEADBEEF')
     txt = self._makeOne()
     self.assertRaises(WrongType, txt.fromUnicode, deadbeef)
Пример #13
0
 def test_validate_w_invalid_default(self):
     from zope.schema._compat import b
     from zope.schema.interfaces import ValidationError
     self.assertRaises(ValidationError, self._makeOne, default=b(''))
Пример #14
0
 class Schema(Interface):
     title = Text(description=u("Short summary"),
                  default=u('say something'))
     weight = Float(min=0.0)
     code = Bytes(min_length=6, max_length=6, default=b('xxxxxx'))
     date = Float(title=u('Date'), readonly=True)