aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests/test_serializer.py
diff options
context:
space:
mode:
authorTom Christie2013-06-03 21:21:47 +0100
committerTom Christie2013-06-03 21:21:47 +0100
commit478f6ff94a6f4ce68bae5133def0e7a042f3c85a (patch)
treeadfdf20bc2461e36f62f7aa2d1f53a735a61344d /rest_framework/tests/test_serializer.py
parent87b8cb852437fb9c0a4d1911778ffca5f6bb336c (diff)
downloaddjango-rest-framework-478f6ff94a6f4ce68bae5133def0e7a042f3c85a.tar.bz2
Regression test for #840. Closes #840.
Diffstat (limited to 'rest_framework/tests/test_serializer.py')
-rw-r--r--rest_framework/tests/test_serializer.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/rest_framework/tests/test_serializer.py b/rest_framework/tests/test_serializer.py
index 6cc913c5..ecaa7255 100644
--- a/rest_framework/tests/test_serializer.py
+++ b/rest_framework/tests/test_serializer.py
@@ -1556,3 +1556,34 @@ class MetadataSerializerTestCase(TestCase):
}
}
self.assertEqual(expected, metadata)
+
+
+class SimpleModel(models.Model):
+ text = models.CharField(max_length=100)
+
+
+class SimpleModelSerializer(serializers.ModelSerializer):
+ text = serializers.CharField()
+ other = serializers.CharField()
+
+ class Meta:
+ model = SimpleModel
+
+ def validate_other(self, attrs, source):
+ del attrs['other']
+ return attrs
+
+class FieldValidationRemovingAttr(TestCase):
+ def test_removing_non_model_field_in_validation(self):
+ """
+ Removing an attr during field valiation should ensure that it is not
+ passed through when restoring the object.
+
+ This allows additional non-model fields to be supported.
+
+ Regression test for #840.
+ """
+ serializer = SimpleModelSerializer(data={'text': 'foo', 'other': 'bar'})
+ self.assertTrue(serializer.is_valid())
+ serializer.save()
+ self.assertEqual(serializer.object.text, 'foo')