Skip to content
Myr

Add coverage for Blueprints.(app_)context_processor

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

Test both context_processor and app_context_processor functions. Two context parameters are added into the context: one added to the blueprint locally; another added to the app globally. The test asserts the behaviors in both blueprint scope and the app scope. The coverage for flask.blueprints is increased by 3%.

authored by Randy Liou · committed by Randy Liou · parent f962720 · Browse files · 1 file+42 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+42 added−0 removed

  • tests:+42 added−0 removed

1 file+42 added−0 removed

modified:tests/test_blueprints.py+42 added
589 unmodified lines
590 def index():591 return flask.render_template('template_test.html', value=False)592 rv = app.test_client().get('/')593 assert b'Success!' in rv.data594595def test_context_processing():596 app = flask.Flask(__name__)597 answer_bp = flask.Blueprint('answer_bp', __name__)598599 template_string = lambda: flask.render_template_string(600 '{% if notanswer %}{{ notanswer }} is not the answer. {% endif %}'601 '{% if answer %}{{ answer }} is the answer.{% endif %}'602 )603604 # App global context processor605 @answer_bp.app_context_processor606 def not_answer_context_processor():607 return {'notanswer': 43}608609 # Blueprint local context processor610 @answer_bp.context_processor611 def answer_context_processor():612 return {'answer': 42}613614 # Setup endpoints for testing615 @answer_bp.route('/bp')616 def bp_page():617 return template_string()618619 @app.route('/')620 def app_page():621 return template_string()622623 # Register the blueprint624 app.register_blueprint(answer_bp)625626 c = app.test_client()627628 app_page_bytes = c.get('/').data629 answer_page_bytes = c.get('/bp').data630631 assert b'43' in app_page_bytes632 assert b'42' not in app_page_bytes633634 assert b'42' in answer_page_bytes635 assert b'43' in answer_page_bytes