Regression test for #532 - values overriden by "default" setting

This commit is contained in:
Yuri Prezument 2012-12-25 18:50:00 +02:00
parent ed09d26fb8
commit 36e1987f59
2 changed files with 16 additions and 1 deletions

View File

@ -71,6 +71,7 @@ class SlugBasedModel(RESTFrameworkModel):
class DefaultValueModel(RESTFrameworkModel):
text = models.CharField(default='foobar', max_length=100)
extra = models.CharField(blank=True, null=True, max_length=100)
class CallableDefaultValueModel(RESTFrameworkModel):

View File

@ -340,7 +340,6 @@ class ModelValidationTests(TestCase):
self.assertTrue(photo_serializer.save())
class RegexValidationTest(TestCase):
def test_create_failed(self):
serializer = BookSerializer(data={'isbn': '1234567890'})
@ -551,6 +550,21 @@ class DefaultValueTests(TestCase):
self.assertEquals(instance.pk, 1)
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):
def setUp(self):