Skip to content
Myr

Merge pull request #2298 from dawran6/test-bp-context

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

Add coverage for Blueprints.(app_)context_processor

authored by David Lord · committed by GitHub · parents a0e38a8, 136dbf7 · 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
616 unmodified lines
617 def index():618 return flask.render_template('template_test.html', value=False)619 rv = app.test_client().get('/')620 assert b'Success!' in rv.data621622def test_context_processing():623 app = flask.Flask(__name__)624 answer_bp = flask.Blueprint('answer_bp', __name__)625626 template_string = lambda: flask.render_template_string(627 '{% if notanswer %}{{ notanswer }} is not the answer. {% endif %}'628 '{% if answer %}{{ answer }} is the answer.{% endif %}'629 )630631 # App global context processor632 @answer_bp.app_context_processor633 def not_answer_context_processor():634 return {'notanswer': 43}635636 # Blueprint local context processor637 @answer_bp.context_processor638 def answer_context_processor():639 return {'answer': 42}640641 # Setup endpoints for testing642 @answer_bp.route('/bp')643 def bp_page():644 return template_string()645646 @app.route('/')647 def app_page():648 return template_string()649650 # Register the blueprint651 app.register_blueprint(answer_bp)652653 c = app.test_client()654655 app_page_bytes = c.get('/').data656 answer_page_bytes = c.get('/bp').data657658 assert b'43' in app_page_bytes659 assert b'42' not in app_page_bytes660661 assert b'42' in answer_page_bytes662 assert b'43' in answer_page_bytes