def test_can_return_result_for_valid_schema_with_foreach_and_formvalidator(self): schema = SchemaValidator() schema.add('foo', ForEach(IntegerValidator())) schema.add_formvalidator(Validator()) with assert_not_raises(): schema.process({'foo': [10]})
def test_can_retrieve_form_validators(self): formvalidator = Validator() schema = self._schema() schema.add_formvalidator(formvalidator) assert_length(1, schema.formvalidators()) assert_equals(formvalidator, schema.formvalidators()[0])
def test_can_add_form_validators(self): self._schema().add_formvalidator(Validator())
class BasicSchema(SchemaValidator): id = Validator() formvalidators = (Validator(), )
class DeclarativeSchema(SchemaValidator): allow_additional_parameters = False id = IntegerValidator() amount = IntegerValidator formvalidators = (Validator(), )
class VarArgsSchema(VarArgsParsingSchema): parameter_order = ('id', 'items') id = IntegerValidator() items = Validator()
def test_vanilla_validators_default_to_use_exceptions(self): validator = Validator() assert_true(validator._exception_if_invalid) validator = Validator(exception_if_invalid=False) assert_false(validator._exception_if_invalid)
def test_can_use_field_data_to_revert_conversion(self): validator = Validator() data = FieldData('foo', initial_value='bar') assert_equals('bar', validator.revert_conversion(data))