Merge branch 'callorico-master'

This commit is contained in:
Tom Christie 2015-08-20 12:39:25 +01:00
commit 490f0c9f34
2 changed files with 23 additions and 0 deletions

View File

@ -185,6 +185,13 @@ def get_field_kwargs(field_name, model_field):
if validator is not validators.validate_slug
]
# IPAddressField do not need to include the 'validate_ipv46_address' argument,
if isinstance(model_field, models.GenericIPAddressField):
validator_kwarg = [
validator for validator in validator_kwarg
if validator is not validators.validate_ipv46_address
]
if getattr(model_field, 'unique', False):
validator = UniqueValidator(queryset=model_field.model._default_manager)
validator_kwarg.append(validator)

View File

@ -344,6 +344,22 @@ class TestDurationFieldMapping(TestCase):
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.
# ------------------------------------