#NEWLINE# def test_plugin_context( self ) : #NEWLINE# #INDENT# wrapper_model = add_plugin ( self . placeholder , SimpleWrapperPlugin , 'en' , glossary = { #NEWLINE# #INDENT# 'tag_type' : 'naked' , #NEWLINE# #UNINDENT# } ) #NEWLINE# wrapper_plugin = wrapper_model . get_plugin_class_instance ( self . admin_site ) #NEWLINE# self . assertIsInstance ( wrapper_plugin , SimpleWrapperPlugin ) #NEWLINE# if_segment_model = add_plugin ( self . placeholder , SegmentPlugin , 'en' , target = wrapper_model , glossary = { #NEWLINE# #INDENT# 'open_tag' : 'if' , #NEWLINE# 'condition' : 'user.is_superuser' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertIsInstance ( if_segment_model . get_plugin_class_instance ( ) , SegmentPlugin ) #NEWLINE# text_model_admin = add_plugin ( self . placeholder , TextPlugin , 'en' , target = if_segment_model , body = '<p>User is admin</p>' ) #NEWLINE# self . assertIsInstance ( text_model_admin . get_plugin_class_instance ( ) , TextPlugin ) #NEWLINE# elif_segment_model = add_plugin ( self . placeholder , SegmentPlugin , 'en' , target = wrapper_model , glossary = { #NEWLINE# #INDENT# 'open_tag' : 'elif' , #NEWLINE# 'condition' : 'user.is_authenticated' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertIsInstance ( elif_segment_model . get_plugin_class_instance ( ) , SegmentPlugin ) #NEWLINE# text_model_staff = add_plugin ( self . placeholder , TextPlugin , 'en' , target = elif_segment_model , body = '<p>User is staff</p>' ) #NEWLINE# self . assertIsInstance ( text_model_staff . get_plugin_class_instance ( ) , TextPlugin ) #NEWLINE# else_segment_model = add_plugin ( self . placeholder , SegmentPlugin , 'en' , target = self , glossary = { #NEWLINE# #INDENT# 'open_tag' : 'else' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertIsInstance ( else_segment_model . get_plugin_class_instance ( ) , SegmentPlugin ) #NEWLINE# text_model_anon = add_plugin ( self . placeholder , TextPlugin , 'en' , target = else_segment_model , body = '<p>User is anonymous</p>' ) #NEWLINE# self . assertIsInstance ( text_model_anon . get_plugin_class_instance ( ) , TextPlugin ) #NEWLINE# plugin_list = [ wrapper_model , if_segment_model , text_model_admin , elif_segment_model , text_model_staff , else_segment_model , text_model_anon ] #NEWLINE# build_plugin_tree ( plugin_list ) #NEWLINE# context = get_request_context ( self . request ) #NEWLINE# html = wrapper_model . render_plugin ( context ) #NEWLINE# soup = BeautifulSoup ( html ) #NEWLINE# self . assertHTMLEqual ( soup . p . text , 'User is admin' ) #NEWLINE# self . request . user = self . get_staff_user_with_no_permissions ( ) #NEWLINE# context = get_request_context ( self . request ) #NEWLINE# html = wrapper_model . render_plugin ( context ) #NEWLINE# soup = BeautifulSoup ( html ) #NEWLINE# self . assertHTMLEqual ( soup . p . text , 'User is staff' ) #NEWLINE# self . request . user = AnonymousUser #NEWLINE# context = get_request_context ( self . request ) #NEWLINE# html = wrapper_model . render_plugin ( context ) #NEWLINE# soup = BeautifulSoup ( html ) #NEWLINE# self . assertHTMLEqual ( soup . p . text , 'User is anonymous' )