#NEWLINE# def test_render_placeholder( self ) : #NEWLINE# #INDENT# '\n        The ``render_placeholder`` tag should render objects by reference.\n        ' #NEWLINE# page2 = PlaceholderFieldTestPage . objects . create ( ) #NEWLINE# placeholder1 = Placeholder . objects . create_for_object ( page2 , 'field_slot1' ) #NEWLINE# item1 = RawHtmlTestItem . objects . create_for_placeholder ( placeholder1 , html = '<b>Item1!</b>' , sort_order = 1 ) #NEWLINE# item2 = RawHtmlTestItem . objects . create_for_placeholder ( placeholder1 , html = '<b>Item2!</b>' , sort_order = 2 ) #NEWLINE# appsettings . FLUENT_CONTENTS_CACHE_OUTPUT = False #NEWLINE# cache . clear ( ) #NEWLINE# with self . assertNumQueries ( 2 ) as ctx : #NEWLINE# #INDENT# html = self . _render ( '{% load fluent_contents_tags %}{% render_placeholder placeholder1 %}' , { #NEWLINE# #INDENT# 'placeholder1' : placeholder1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( ctx , '<b>Item1!</b><b>Item2!</b>' ) #NEWLINE# #UNINDENT# with self . assertNumQueries ( 3 ) as ctx : #NEWLINE# #INDENT# html = self . _render ( '{% load fluent_contents_tags %}{% render_placeholder page2.contents %}' , { #NEWLINE# #INDENT# 'page2' : page2 , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( html , '<b>Item1!</b><b>Item2!</b>' ) #NEWLINE# #UNINDENT# with self . assertNumQueries ( 3 ) as ctx : #NEWLINE# #INDENT# html = self . _render ( '{% load fluent_contents_tags %}{% render_placeholder page2.placeholder_set %}' , { #NEWLINE# #INDENT# 'page2' : page2 , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( html , '<b>Item1!</b><b>Item2!</b>' ) #NEWLINE# #UNINDENT# with self . assertNumQueries ( 0 ) as ctx : #NEWLINE# #INDENT# html = self . _render ( '{% load fluent_contents_tags %}{% render_placeholder none_object %}' , { #NEWLINE# #INDENT# 'none_object' : None , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( html , '<!-- placeholder object is None -->' ) #NEWLINE# #UNINDENT# self . assertRaises ( ValueError , ( lambda : self . _render ( '{% load fluent_contents_tags %}{% render_placeholder 123 %}' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) ) #NEWLINE# self . assertRaises ( ValueError , ( lambda : self . _render ( '{% load fluent_contents_tags %}{% render_placeholder int_object %}' , { #NEWLINE# #INDENT# 'int_object' : 456 , #NEWLINE# #UNINDENT# } ) ) ) #NEWLINE# self . assertRaises ( TemplateSyntaxError , ( lambda : Template ( '{% load fluent_contents_tags %}{% render_placeholder %}' ) ) ) #NEWLINE# self . assertRaises ( TemplateSyntaxError , ( lambda : Template ( '{% load fluent_contents_tags %}{% render_placeholder arg1 arg2 %}' ) ) )