flask/tests/test_session_interface.py

29 lines
784 B
Python
Raw Normal View History

import flask
2025-09-13 05:52:03 +08:00
from flask.globals import app_ctx
from flask.sessions import SessionInterface
2021-05-14 23:11:09 +08:00
def test_open_session_with_endpoint():
"""If request.endpoint (or other URL matching behavior) is needed
while loading the session, RequestContext.match_request() can be
called manually.
"""
class MySessionInterface(SessionInterface):
2021-05-14 23:11:09 +08:00
def save_session(self, app, session, response):
pass
2021-05-14 23:11:09 +08:00
def open_session(self, app, request):
2025-09-13 05:52:03 +08:00
app_ctx.match_request()
assert request.endpoint is not None
app = flask.Flask(__name__)
app.session_interface = MySessionInterface()
2021-05-14 23:11:09 +08:00
@app.get("/")
def index():
return "Hello, World!"
response = app.test_client().get("/")
assert response.status_code == 200