forked from orbit-oss/flask
add tests for template_filter using a real template
This commit is contained in:
parent
5c9ef2c44d
commit
4395e9493c
2 changed files with 24 additions and 0 deletions
|
|
@ -329,6 +329,29 @@ class TemplatingTestCase(unittest.TestCase):
|
|||
assert app.jinja_env.filters['strrev'] == my_reverse
|
||||
assert app.jinja_env.filters['strrev']('abcd') == 'dcba'
|
||||
|
||||
def test_template_filter_with_template(self):
|
||||
app = flask.Flask(__name__)
|
||||
@app.template_filter()
|
||||
def super_reverse(s):
|
||||
return s[::-1]
|
||||
@app.route('/')
|
||||
def index():
|
||||
return flask.render_template('template_filter.html', value='abcd')
|
||||
rv = app.test_client().get('/')
|
||||
assert rv.data == 'dcba'
|
||||
|
||||
def test_template_filter_with_name_and_template(self):
|
||||
app = flask.Flask(__name__)
|
||||
@app.template_filter('super_reverse')
|
||||
def my_reverse(s):
|
||||
return s[::-1]
|
||||
@app.route('/')
|
||||
def index():
|
||||
return flask.render_template('template_filter.html', value='abcd')
|
||||
rv = app.test_client().get('/')
|
||||
assert rv.data == 'dcba'
|
||||
|
||||
|
||||
def suite():
|
||||
from minitwit_tests import MiniTwitTestCase
|
||||
from flaskr_tests import FlaskrTestCase
|
||||
|
|
|
|||
1
tests/templates/template_filter.html
Normal file
1
tests/templates/template_filter.html
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{ value|super_reverse }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue