Пример #1
0
 def test_validate_fields(self):
     """ """
     obj = api.content.create(container=self.portal.folder,
                              id='tt',
                              type='testingtype',
                              enabled='Should be a boolean',
                              textline=None,
                              mandatory_textline=u'Some text',
                              tal_condition=u'',
                              roles_bypassing_talcondition=set())
     self.assertEqual(validate_fields(obj),
                      [WrongType('Should be a boolean', bool, 'enabled')])
     obj.enabled = False
     self.assertFalse(validate_fields(obj))
     obj.enabled = True
     self.assertFalse(validate_fields(obj))
     # not required fields other than Bool must contain something
     # else than None if field is required=True
     obj.mandatory_textline = None
     self.assertEqual(validate_fields(obj),
                      [WrongType(None, unicode, 'mandatory_textline')])
     # validate_fields may raise a ValueError if raise_on_errors=True
     self.assertRaises(ValueError,
                       validate_fields,
                       obj,
                       raise_on_errors=True)
     # back to correct value
     obj.mandatory_textline = u'Some text'
     self.assertFalse(validate_fields(obj))
Пример #2
0
    def _validate(self, value):
        if self._type is not None and not isinstance(value, self._type):
            raise WrongType(value, self._type,
                            self.__name__).with_field_and_value(self, value)

        try:
            constraint = self.constraint(value)
        except ValidationError as e:
            if e.field is None:
                e.field = self
            if e.value is None:
                e.value = value
            raise
        if not constraint:
            raise ConstraintNotSatisfied(value,
                                         self.__name__).with_field_and_value(
                                             self, value)
Пример #3
0
    def _validate(self, value):
        if self._type is not None and not isinstance(value, self._type):
            raise WrongType(value, self._type, self.__name__)

        if not self.constraint(value):
            raise ConstraintNotSatisfied(value, self.__name__)
Пример #4
0
 def _validate(self, value):
     """ Overwrites validator for FileWidget  """
     try:
         ZipFile(StringIO(value))
     except BadZipfile, e:
         raise WrongType(e)