mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-14 18:43:22 +03:00
Merge branch 'callorico-master'
This commit is contained in:
commit
490f0c9f34
|
@ -185,6 +185,13 @@ def get_field_kwargs(field_name, model_field):
|
||||||
if validator is not validators.validate_slug
|
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):
|
if getattr(model_field, 'unique', False):
|
||||||
validator = UniqueValidator(queryset=model_field.model._default_manager)
|
validator = UniqueValidator(queryset=model_field.model._default_manager)
|
||||||
validator_kwarg.append(validator)
|
validator_kwarg.append(validator)
|
||||||
|
|
|
@ -344,6 +344,22 @@ class TestDurationFieldMapping(TestCase):
|
||||||
self.assertEqual(unicode_repr(TestSerializer()), expected)
|
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.
|
# Tests for relational field mappings.
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user