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

Function test_app_request_processing

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

Source from the content-addressed store, hash-verified

725
726
727def test_app_request_processing(app, client):
728 bp = flask.Blueprint("bp", __name__)
729 evts = []
730
731 @bp.before_app_request
732 def before_app():
733 evts.append("before")
734
735 @bp.after_app_request
736 def after_app(response):
737 response.data += b"|after"
738 evts.append("after")
739 return response
740
741 @bp.teardown_app_request
742 def teardown_app(exc):
743 evts.append("teardown")
744
745 app.register_blueprint(bp)
746
747 # Setup routes for testing
748 @app.route("/")
749 def bp_endpoint():
750 return "request"
751
752 # before first request
753 assert evts == []
754
755 # first request
756 resp = client.get("/").data
757 assert resp == b"request|after"
758 assert evts == ["before", "after", "teardown"]
759
760 # second request
761 resp = client.get("/").data
762 assert resp == b"request|after"
763 assert evts == ["before", "after", "teardown"] * 2
764
765
766def test_app_url_processors(app, client):

Callers

nothing calls this directly

Calls 2

register_blueprintMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected