예제 #1
0
    def test_given_no_validators_when_field_validated_then_calls_field_type_validator(self):
        field_type = Mock(FieldType)
        field = Field('name', field_type)
        value = Mock()

        field.validate(value)

        field_type.validate.assert_called_once_with(value)
예제 #2
0
    def test_given_no_validators_when_field_validated_then_calls_field_type_validator(
            self):
        field_type = Mock(FieldType)
        field = Field('name', field_type)
        value = Mock()

        field.validate(value)

        field_type.validate.assert_called_once_with(value)
예제 #3
0
    def test_given_validator_on_action_when_field_validated_then_calls_action_validator(self):
        field_type = Mock(FieldType)
        action_validator = Mock()
        value = Mock()

        field = Field('name', field_type, create=action_validator)

        field.validate(value, 'create')

        action_validator.assert_called_once_with(value)
예제 #4
0
    def test_given_validator_on_action_when_field_validated_then_calls_action_validator(
            self):
        field_type = Mock(FieldType)
        action_validator = Mock()
        value = Mock()

        field = Field('name', field_type, create=action_validator)

        field.validate(value, 'create')

        action_validator.assert_called_once_with(value)
예제 #5
0
    def test_given_multiple_validators_then_field_validated_then_calls_all_validators(self):
        field_type = Mock(FieldType)
        validator1 = Mock()
        validator2 = Mock()
        action_validator1 = Mock()
        action_validator2 = Mock()
        value = Mock()

        field = Field('name', field_type, validator1, validator2, create=[action_validator1, action_validator2])

        field.validate(value, 'create')

        field_type.validate.assert_called_once_with(value)
        validator1.assert_called_once_with(value)
        validator2.assert_called_once_with(value)
        action_validator1.assert_called_once_with(value)
        action_validator2.assert_called_once_with(value)
예제 #6
0
    def test_given_validation_error_raised_then_reformats_error(self):
        field_type = Mock(FieldType)
        field_type.validate.side_effect = ValidationError('message')
        value = Mock()

        field = Field('name', field_type)

        self.assertRaisesRegexp(ValidationError,
                                "Input Error - field 'name': message",
                                field.validate, value)
예제 #7
0
    def test_given_multiple_validators_then_field_validated_then_calls_all_validators(
            self):
        field_type = Mock(FieldType)
        validator1 = Mock()
        validator2 = Mock()
        action_validator1 = Mock()
        action_validator2 = Mock()
        value = Mock()

        field = Field('name',
                      field_type,
                      validator1,
                      validator2,
                      create=[action_validator1, action_validator2])

        field.validate(value, 'create')

        field_type.validate.assert_called_once_with(value)
        validator1.assert_called_once_with(value)
        validator2.assert_called_once_with(value)
        action_validator1.assert_called_once_with(value)
        action_validator2.assert_called_once_with(value)