From bc6bf7236b95e9fc150b4a36bd80d6f82ba7356b Mon Sep 17 00:00:00 2001 From: Ryan Kaneshiro Date: Fri, 7 Aug 2015 16:53:43 -0700 Subject: [PATCH] Add test to repro duplicate validation error Using the ModelSerializer with a model containing a GenericIPAddressField produces duplicated validation error messages. --- tests/test_model_serializer.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index 00c6319eae..7a6c71c25e 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -344,6 +344,22 @@ class Meta: self.assertEqual(unicode_repr(TestSerializer()), expected) +class TestGenericIPAddressFieldValidation(TestCase): + def test_ip_address_validation(self): + class IPAddressFieldModel(models.Model): + address = models.GenericIPAddressField() + + class TestSerializer(serializers.ModelSerializer): + class Meta: + model = IPAddressFieldModel + + s = TestSerializer(data={'address': 'not an ip address'}) + self.assertFalse(s.is_valid()) + self.assertEquals(1, len(s.errors['address']), + 'Unexpected number of validation errors: ' + '{0}'.format(s.errors)) + + # Tests for relational field mappings. # ------------------------------------