diff options
| author | Tom Christie | 2013-03-18 21:35:06 +0000 | 
|---|---|---|
| committer | Tom Christie | 2013-03-18 21:35:06 +0000 | 
| commit | deb5e653e441bf31f3b183b575f72e6b4cf537ea (patch) | |
| tree | 649492418d198e31f29d4d23db2320e460033e59 /rest_framework | |
| parent | ad3ffe20f0c61f04893a411c741d6343b6494ad1 (diff) | |
| download | django-rest-framework-deb5e653e441bf31f3b183b575f72e6b4cf537ea.tar.bz2 | |
Added bulk create tests
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/tests/serializer_bulk_update.py | 73 | 
1 files changed, 73 insertions, 0 deletions
diff --git a/rest_framework/tests/serializer_bulk_update.py b/rest_framework/tests/serializer_bulk_update.py new file mode 100644 index 00000000..3ecb23ed --- /dev/null +++ b/rest_framework/tests/serializer_bulk_update.py @@ -0,0 +1,73 @@ +""" +Tests to cover bulk create and update using serializers. +""" +from __future__ import unicode_literals +from django.test import TestCase +from rest_framework import serializers + + +class BulkCreateSerializerTests(TestCase): + +    def setUp(self): +        class BookSerializer(serializers.Serializer): +            id = serializers.IntegerField() +            title = serializers.CharField(max_length=100) +            author = serializers.CharField(max_length=100) + +        self.BookSerializer = BookSerializer + +    def test_bulk_create_success(self): +        """ +        Correct bulk update serialization should return the input data. +        """ + +        data = [ +            { +                'id': 0, +                'title': 'The electric kool-aid acid test', +                'author': 'Tom Wolfe' +            }, { +                'id': 1, +                'title': 'If this is a man', +                'author': 'Primo Levi' +            }, { +                'id': 2, +                'title': 'The wind-up bird chronicle', +                'author': 'Haruki Murakami' +            } +        ] + +        serializer = self.BookSerializer(data=data, many=True) +        self.assertEqual(serializer.is_valid(), True) +        self.assertEqual(serializer.object, data) + +    def test_bulk_create_errors(self): +        """ +        Correct bulk update serialization should return the input data. +        """ + +        data = [ +            { +                'id': 0, +                'title': 'The electric kool-aid acid test', +                'author': 'Tom Wolfe' +            }, { +                'id': 1, +                'title': 'If this is a man', +                'author': 'Primo Levi' +            }, { +                'id': 'foo', +                'title': 'The wind-up bird chronicle', +                'author': 'Haruki Murakami' +            } +        ] +        expected_errors = [ +            {}, +            {}, +            {'id': ['Enter a whole number.']} +        ] + +        serializer = self.BookSerializer(data=data, many=True) +        self.assertEqual(serializer.is_valid(), False) +        self.assertEqual(serializer.errors, expected_errors) +  | 
