Skip to content
Myr

Add coverage for Blueprint.add_app_template_global

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This tests the Blueprint.add_app_template_global mothod, which internally calls the Blueprint.app_template_global method. The methods are used to registering a function to the jinja template environment. This PR increases the test coverage for module flask.blueprint by 4%.

authored by Randy Liou · committed by Randy Liou · parent e706b5e · Browse files · 1 file+19 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−0 removed

  • tests:+19 added−0 removed

1 file+19 added−0 removed

modified:tests/test_blueprints.py+19 added
658 unmodified lines
659 assert b'42' not in app_page_bytes660661 assert b'42' in answer_page_bytes662 assert b'43' in answer_page_bytes663664def test_template_global():665 app = flask.Flask(__name__)666 bp = flask.Blueprint('bp', __name__)667 @bp.app_template_global()668 def get_answer():669 return 42670 # Make sure the function is not in the jinja_env already671 assert 'get_answer' not in app.jinja_env.globals.keys()672 app.register_blueprint(bp)673674 # Tests675 assert 'get_answer' in app.jinja_env.globals.keys()676 assert app.jinja_env.globals['get_answer'] is get_answer677 assert app.jinja_env.globals['get_answer']() == 42678679 with app.app_context():680 rv = flask.render_template_string('{{ get_answer() }}')681 assert rv == '42'