[Add]: CustomValidationTests.test_partial_update

This test is to make sure that validate_<attrname> is not called when
partial=True and <attrname> is not found in .data.
This commit is contained in:
Colin Huang 2013-09-15 21:56:43 -07:00
parent e8c6cd5622
commit b74c5235c5

View File

@ -496,6 +496,33 @@ class CustomValidationTests(TestCase):
self.assertFalse(serializer.is_valid())
self.assertEqual(serializer.errors, {'email': ['Enter a valid email address.']})
def test_partial_update(self):
"""
Make sure that validate_email isn't called when partial=True and email
isn't found in data.
"""
initial_data = {
'email': 'tom@example.com',
'content': 'A test comment',
'created': datetime.datetime(2012, 1, 1)
}
serializer = self.CommentSerializerWithFieldValidator(data=initial_data)
self.assertEqual(serializer.is_valid(), True)
instance = serializer.object
new_content = 'An *updated* test comment'
partial_data = {
'content': new_content
}
serializer = self.CommentSerializerWithFieldValidator(instance=instance,
data=partial_data,
partial=True)
self.assertEqual(serializer.is_valid(), True)
instance = serializer.object
self.assertEqual(instance.content, new_content)
class PositiveIntegerAsChoiceTests(TestCase):
def test_positive_integer_in_json_is_correctly_parsed(self):