Test and fix for #1210. World's lowest hanging fruit.

This commit is contained in:
Carlton Gibson 2014-02-11 19:52:32 +01:00
parent 9a767c21a3
commit f1016441f5
2 changed files with 10 additions and 2 deletions

View File

@ -477,6 +477,7 @@ class URLField(CharField):
type_label = 'url'
def __init__(self, **kwargs):
if not 'validators' in kwargs:
kwargs['validators'] = [validators.URLValidator()]
super(URLField, self).__init__(**kwargs)

View File

@ -860,7 +860,9 @@ class SlugFieldTests(TestCase):
class URLFieldTests(TestCase):
"""
Tests for URLField attribute values
Tests for URLField attribute values.
(Includes test for #1210, checking that validators can be overridden.)
"""
class URLFieldModel(RESTFrameworkModel):
@ -902,6 +904,11 @@ class URLFieldTests(TestCase):
self.assertEqual(getattr(serializer.fields['url_field'],
'max_length'), 20)
def test_validators_can_be_overridden(self):
url_field = serializers.URLField(validators=[])
validators = url_field.validators
self.assertEqual([], validators, 'Passing `validators` kwarg should have overridden default validators')
class FieldMetadata(TestCase):
def setUp(self):