<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import flask <EOL> import unittest <EOL> from flask . testsuite import FlaskTestCase <EOL> class TemplatingTestCase ( FlaskTestCase ) : <EOL> def test_context_processing ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . context_processor <EOL> def context_processor ( ) : <EOL> return { '<STR_LIT>' : <NUM_LIT> } <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( '<STR_LIT>' , value = <NUM_LIT> ) <EOL> rv = app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> def test_original_win ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template_string ( '<STR_LIT>' , config = <NUM_LIT> ) <EOL> rv = app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> def test_standard_context ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> app . secret_key = '<STR_LIT>' <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> flask . g . foo = <NUM_LIT> <EOL> flask . session [ '<STR_LIT:test>' ] = '<STR_LIT>' <EOL> return flask . render_template_string ( '''<STR_LIT>''' ) <EOL> rv = app . test_client ( ) . get ( '<STR_LIT>' ) <EOL> self . assert_equal ( rv . data . split ( ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:False>' , '<STR_LIT>' ] ) <EOL> def test_escaping ( self ) : <EOL> text = '<STR_LIT>' <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( '<STR_LIT>' , text = text , <EOL> html = flask . Markup ( text ) ) <EOL> lines = app . test_client ( ) . get ( '<STR_LIT:/>' ) . data . splitlines ( ) <EOL> self . assert_equal ( lines , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] ) <EOL> def test_no_escaping ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> with app . test_request_context ( ) : <EOL> self . assert_equal ( flask . render_template_string ( '<STR_LIT>' , <EOL> foo = '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assert_equal ( flask . render_template ( '<STR_LIT>' , foo = '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> def test_macros ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> with app . test_request_context ( ) : <EOL> macro = flask . get_template_attribute ( '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . assert_equal ( macro ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_template_filter ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . template_filter ( ) <EOL> def my_reverse ( s ) : <EOL> return s [ : : - <NUM_LIT:1> ] <EOL> self . assert_ ( '<STR_LIT>' in app . jinja_env . filters . keys ( ) ) <EOL> self . assert_equal ( app . jinja_env . filters [ '<STR_LIT>' ] , my_reverse ) <EOL> self . assert_equal ( app . jinja_env . filters [ '<STR_LIT>' ] ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_add_template_filter ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> def my_reverse ( s ) : <EOL> return s [ : : - <NUM_LIT:1> ] <EOL> app . add_template_filter ( my_reverse ) <EOL> self . assert_ ( '<STR_LIT>' in app . jinja_env . filters . keys ( ) ) <EOL> self . assert_equal ( app . jinja_env . filters [ '<STR_LIT>' ] , my_reverse ) <EOL> self . assert_equal ( app . jinja_env . filters [ '<STR_LIT>' ] ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_template_filter_with_name ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . template_filter ( '<STR_LIT>' ) <EOL> def my_reverse ( s ) : <EOL> return s [ : : - <NUM_LIT:1> ] <EOL> self . assert_ ( '<STR_LIT>' in app . jinja_env . filters . keys ( ) ) <EOL> self . assert_equal ( app . jinja_env . filters [ '<STR_LIT>' ] , my_reverse ) <EOL> self . assert_equal ( app . jinja_env . filters [ '<STR_LIT>' ] ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_add_template_filter_with_name ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> def my_reverse ( s ) : <EOL> return s [ : : - <NUM_LIT:1> ] <EOL> app . add_template_filter ( my_reverse , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in app . jinja_env . filters . keys ( ) ) <EOL> self . assert_equal ( app . jinja_env . filters [ '<STR_LIT>' ] , my_reverse ) <EOL> self . assert_equal ( app . jinja_env . filters [ '<STR_LIT>' ] ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_template_filter_with_template ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . template_filter ( ) <EOL> def super_reverse ( s ) : <EOL> return s [ : : - <NUM_LIT:1> ] <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( '<STR_LIT>' , value = '<STR_LIT>' ) <EOL> rv = app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> def test_add_template_filter_with_template ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> def super_reverse ( s ) : <EOL> return s [ : : - <NUM_LIT:1> ] <EOL> app . add_template_filter ( super_reverse ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( '<STR_LIT>' , value = '<STR_LIT>' ) <EOL> rv = app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> def test_template_filter_with_name_and_template ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . template_filter ( '<STR_LIT>' ) <EOL> def my_reverse ( s ) : <EOL> return s [ : : - <NUM_LIT:1> ] <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( '<STR_LIT>' , value = '<STR_LIT>' ) <EOL> rv = app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> def test_add_template_filter_with_name_and_template ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> def my_reverse ( s ) : <EOL> return s [ : : - <NUM_LIT:1> ] <EOL> app . add_template_filter ( my_reverse , '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( '<STR_LIT>' , value = '<STR_LIT>' ) <EOL> rv = app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> def test_custom_template_loader ( self ) : <EOL> class MyFlask ( flask . Flask ) : <EOL> def create_global_jinja_loader ( self ) : <EOL> from jinja2 import DictLoader <EOL> return DictLoader ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> app = MyFlask ( __name__ ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( '<STR_LIT>' ) <EOL> c = app . test_client ( ) <EOL> rv = c . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> def test_iterable_loader ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> @ app . context_processor <EOL> def context_processor ( ) : <EOL> return { '<STR_LIT>' : '<STR_LIT>' } <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return flask . render_template ( <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> value = <NUM_LIT> ) <EOL> rv = app . test_client ( ) . get ( '<STR_LIT:/>' ) <EOL> self . assert_equal ( rv . data , '<STR_LIT>' ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( TemplatingTestCase ) ) <EOL> return suite </s>
