#NEWLINE# def test_bulk_create( self ) : #NEWLINE# #INDENT# class BasicModelSerializer ( serializers . ModelSerializer ) : #NEWLINE# #INDENT# class Meta ( ) : #NEWLINE# #INDENT# model = BulkCreateModel #NEWLINE# fields = ( 'name' , ) #NEWLINE# #UNINDENT# #UNINDENT# class BulkCreateSerializer ( serializers . ListSerializer ) : #NEWLINE# #INDENT# child = BasicModelSerializer ( ) #NEWLINE# #UNINDENT# data = [ { #NEWLINE# #INDENT# 'name' : 'a' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'b' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'c' , #NEWLINE# #UNINDENT# } ] #NEWLINE# serializer = BulkCreateSerializer ( data = data ) #NEWLINE# assert serializer . is_valid ( ) #NEWLINE# instances = serializer . save ( ) #NEWLINE# assert ( len ( instances ) == 3 ) #NEWLINE# assert ( [ item . name for item in instances ] == [ 'a' , 'b' , 'c' ] ) #NEWLINE# assert ( BulkCreateModel . objects . count ( ) == 3 ) #NEWLINE# assert ( list ( BulkCreateModel . objects . values_list ( 'name' , flat = True ) ) == [ 'a' , 'b' , 'c' ] ) #NEWLINE# assert ( serializer . data == data )