(app, client)
| 632 | |
| 633 | |
| 634 | def 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 | |
| 675 | def test_template_global(app): |
nothing calls this directly
no test coverage detected