mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 10:03:57 +03:00
Regression test for #532 - values overriden by "default" setting
This commit is contained in:
parent
ed09d26fb8
commit
36e1987f59
|
@ -71,6 +71,7 @@ class SlugBasedModel(RESTFrameworkModel):
|
||||||
|
|
||||||
class DefaultValueModel(RESTFrameworkModel):
|
class DefaultValueModel(RESTFrameworkModel):
|
||||||
text = models.CharField(default='foobar', max_length=100)
|
text = models.CharField(default='foobar', max_length=100)
|
||||||
|
extra = models.CharField(blank=True, null=True, max_length=100)
|
||||||
|
|
||||||
|
|
||||||
class CallableDefaultValueModel(RESTFrameworkModel):
|
class CallableDefaultValueModel(RESTFrameworkModel):
|
||||||
|
|
|
@ -340,7 +340,6 @@ class ModelValidationTests(TestCase):
|
||||||
self.assertTrue(photo_serializer.save())
|
self.assertTrue(photo_serializer.save())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RegexValidationTest(TestCase):
|
class RegexValidationTest(TestCase):
|
||||||
def test_create_failed(self):
|
def test_create_failed(self):
|
||||||
serializer = BookSerializer(data={'isbn': '1234567890'})
|
serializer = BookSerializer(data={'isbn': '1234567890'})
|
||||||
|
@ -551,6 +550,21 @@ class DefaultValueTests(TestCase):
|
||||||
self.assertEquals(instance.pk, 1)
|
self.assertEquals(instance.pk, 1)
|
||||||
self.assertEquals(instance.text, 'overridden')
|
self.assertEquals(instance.text, 'overridden')
|
||||||
|
|
||||||
|
def test_partial_update_default(self):
|
||||||
|
""" Regression test for issue #532 """
|
||||||
|
data = {'text': 'overridden'}
|
||||||
|
serializer = self.serializer_class(data=data, partial=True)
|
||||||
|
self.assertEquals(serializer.is_valid(), True)
|
||||||
|
instance = serializer.save()
|
||||||
|
|
||||||
|
data = {'extra': 'extra_value'}
|
||||||
|
serializer = self.serializer_class(instance=instance, data=data, partial=True)
|
||||||
|
self.assertEquals(serializer.is_valid(), True)
|
||||||
|
instance = serializer.save()
|
||||||
|
|
||||||
|
self.assertEquals(instance.extra, 'extra_value')
|
||||||
|
self.assertEquals(instance.text, 'overridden')
|
||||||
|
|
||||||
|
|
||||||
class CallableDefaultValueTests(TestCase):
|
class CallableDefaultValueTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user