<s> from __future__ import absolute_import , unicode_literals <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import AnonymousUser <EOL> from django . template import engines <EOL> from django . test import TestCase <EOL> from wagtail . wagtailcore . models import PAGE_TEMPLATE_VAR , Page , Site <EOL> class TestCoreJinja ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . engine = engines [ '<STR_LIT>' ] <EOL> self . user = get_user_model ( ) . objects . create_superuser ( <EOL> username = '<STR_LIT:test>' , <EOL> email = '<STR_LIT>' , <EOL> password = '<STR_LIT:password>' <EOL> ) <EOL> self . homepage = Page . objects . get ( id = <NUM_LIT:2> ) <EOL> def render ( self , string , context = None , request_context = True ) : <EOL> if context is None : <EOL> context = { } <EOL> template = self . engine . from_string ( string ) <EOL> return template . render ( context ) <EOL> def dummy_request ( self , user = None ) : <EOL> site = Site . objects . get ( is_default_site = True ) <EOL> request = self . client . get ( '<STR_LIT:/>' ) <EOL> request . site = site <EOL> request . user = user or AnonymousUser ( ) <EOL> return request <EOL> def test_userbar ( self ) : <EOL> content = self . render ( '<STR_LIT>' , { <EOL> PAGE_TEMPLATE_VAR : self . homepage , <EOL> '<STR_LIT>' : self . dummy_request ( self . user ) } ) <EOL> self . assertIn ( "<STR_LIT>" , content ) <EOL> def test_userbar_anonymous_user ( self ) : <EOL> content = self . render ( '<STR_LIT>' , { <EOL> PAGE_TEMPLATE_VAR : self . homepage , <EOL> '<STR_LIT>' : self . dummy_request ( ) } ) <EOL> self . assertEqual ( content , '<STR_LIT>' ) </s>
