#NEWLINE# def test_foreign_key_create_with_valid_null( self ) : #NEWLINE# #INDENT# data = { #NEWLINE# #INDENT# 'id' : 4 , #NEWLINE# 'name' : 'source-4' , #NEWLINE# 'target' : None , #NEWLINE# #UNINDENT# } #NEWLINE# serializer = NullableForeignKeySourceSerializer ( data = data ) #NEWLINE# self . assertTrue ( serializer . is_valid ( ) ) #NEWLINE# obj = serializer . save ( ) #NEWLINE# self . assertEqual ( serializer . data , self ) #NEWLINE# self . assertEqual ( obj . name , 'source-4' ) #NEWLINE# queryset = NullableForeignKeySource . objects . all ( ) #NEWLINE# serializer = NullableForeignKeySourceSerializer ( queryset , many = True ) #NEWLINE# expected = [ { #NEWLINE# #INDENT# 'id' : 1 , #NEWLINE# 'name' : 'source-1' , #NEWLINE# 'target' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'id' : 2 , #NEWLINE# 'name' : 'source-2' , #NEWLINE# 'target' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'id' : 3 , #NEWLINE# 'name' : 'source-3' , #NEWLINE# 'target' : None , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'id' : 4 , #NEWLINE# 'name' : 'source-4' , #NEWLINE# 'target' : None , #NEWLINE# #UNINDENT# } ] #NEWLINE# self . assertEqual ( serializer . data , expected )