diff options
| author | Colin Huang | 2013-09-15 21:56:43 -0700 |
|---|---|---|
| committer | Colin Huang | 2013-09-15 22:22:52 -0700 |
| commit | b74c5235c509738c7afea0be0dd8283bb8339ebe (patch) | |
| tree | eeca417c77c1c7627c41705971758a4f97a48d63 /rest_framework/tests | |
| parent | e8c6cd5622f62fcf2d4cf2b28b504fe5ff5228f9 (diff) | |
| download | django-rest-framework-b74c5235c509738c7afea0be0dd8283bb8339ebe.tar.bz2 | |
[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.
Diffstat (limited to 'rest_framework/tests')
| -rw-r--r-- | rest_framework/tests/test_serializer.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/rest_framework/tests/test_serializer.py b/rest_framework/tests/test_serializer.py index c2497660..9792685e 100644 --- a/rest_framework/tests/test_serializer.py +++ b/rest_framework/tests/test_serializer.py @@ -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): |
