Merge pull request #1308 from lukaszb/missing-custom-validation-method-test

Added missing custom validation method test
This commit is contained in:
Tom Christie 2013-12-20 08:37:30 -08:00
commit 46906b2bdc

View File

@ -47,6 +47,12 @@ class ShouldValidateModel(models.Model):
class ShouldValidateModelSerializer(serializers.ModelSerializer):
renamed = serializers.CharField(source='should_validate_field', required=False)
def validate_renamed(self, attrs, source):
value = attrs[source]
if len(value) < 3:
raise serializers.ValidationError('Minimum 3 characters.')
return attrs
class Meta:
model = ShouldValidateModel
fields = ('renamed',)
@ -63,6 +69,13 @@ class TestPreSaveValidationExclusionsSerializer(TestCase):
self.assertEqual(serializer.is_valid(), False)
class TestCustomValidationMethods(TestCase):
def test_custom_validation_method_is_executed(self):
serializer = ShouldValidateModelSerializer(data={'renamed': 'fo'})
self.assertFalse(serializer.is_valid())
self.assertIn('renamed', serializer.errors)
class ValidationSerializer(serializers.Serializer):
foo = serializers.CharField()