mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
commit
e56ba33d1b
|
@ -477,7 +477,8 @@ class URLField(CharField):
|
||||||
type_label = 'url'
|
type_label = 'url'
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
kwargs['validators'] = [validators.URLValidator()]
|
if not 'validators' in kwargs:
|
||||||
|
kwargs['validators'] = [validators.URLValidator()]
|
||||||
super(URLField, self).__init__(**kwargs)
|
super(URLField, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -860,7 +860,9 @@ class SlugFieldTests(TestCase):
|
||||||
|
|
||||||
class URLFieldTests(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):
|
class URLFieldModel(RESTFrameworkModel):
|
||||||
|
@ -902,6 +904,11 @@ class URLFieldTests(TestCase):
|
||||||
self.assertEqual(getattr(serializer.fields['url_field'],
|
self.assertEqual(getattr(serializer.fields['url_field'],
|
||||||
'max_length'), 20)
|
'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):
|
class FieldMetadata(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user