#NEWLINE# def test_rendering_nested_fields_with_none_value( self ) : #NEWLINE# #INDENT# from rest_framework.renderers import HTMLFormRenderer #NEWLINE# class Nested1 ( serializers . Serializer ) : #NEWLINE# #INDENT# text_field = serializers . CharField ( ) #NEWLINE# #UNINDENT# class Nested2 ( serializers . Serializer ) : #NEWLINE# #INDENT# nested1 = Nested1 ( allow_null = True ) #NEWLINE# text_field = serializers . CharField ( ) #NEWLINE# #UNINDENT# class ExampleSerializer ( serializers . Serializer ) : #NEWLINE# #INDENT# nested2 = Nested2 ( ) #NEWLINE# #UNINDENT# serializer = ExampleSerializer ( data = { #NEWLINE# #INDENT# 'nested2' : { #NEWLINE# #INDENT# 'nested1' : None , #NEWLINE# 'text_field' : 'test' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert serializer . is_valid ( ) #NEWLINE# renderer = HTMLFormRenderer ( ) #NEWLINE# for field in expected_packed : #NEWLINE# #INDENT# rendered = renderer . render_field ( field , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# expected_packed = '<fieldset><legend>Nested2</legend><fieldset><legend>Nested1</legend><divclass="form-group"><label>Textfield</label><inputname="nested2.nested1.text_field"class="form-control"type="text"></div></fieldset><divclass="form-group"><label>Textfield</label><inputname="nested2.text_field"class="form-control"type="text"value="test"></div></fieldset>' #NEWLINE# rendered_packed = '' . join ( rendered . split ( ) ) #NEWLINE# assert ( rendered_packed == expected_packed )