MCPcopy Create free account
hub / github.com/pallets/flask / test_context_processing

Function test_context_processing

tests/test_blueprints.py:634–672  ·  view source on GitHub ↗
(app, client)

Source from the content-addressed store, hash-verified

632
633
634def test_context_processing(app, client):
635 answer_bp = flask.Blueprint("answer_bp", __name__)
636
637 def template_string():
638 return flask.render_template_string(
639 "{% if notanswer %}{{ notanswer }} is not the answer. {% endif %}"
640 "{% if answer %}{{ answer }} is the answer.{% endif %}"
641 )
642
643 # App global context processor
644 @answer_bp.app_context_processor
645 def not_answer_context_processor():
646 return {"notanswer": 43}
647
648 # Blueprint local context processor
649 @answer_bp.context_processor
650 def answer_context_processor():
651 return {"answer": 42}
652
653 # Setup endpoints for testing
654 @answer_bp.route("/bp")
655 def bp_page():
656 return template_string()
657
658 @app.route("/")
659 def app_page():
660 return template_string()
661
662 # Register the blueprint
663 app.register_blueprint(answer_bp)
664
665 app_page_bytes = client.get("/").data
666 answer_page_bytes = client.get("/bp").data
667
668 assert b"43" in app_page_bytes
669 assert b"42" not in app_page_bytes
670
671 assert b"42" in answer_page_bytes
672 assert b"43" in answer_page_bytes
673
674
675def test_template_global(app):

Callers

nothing calls this directly

Calls 2

register_blueprintMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected