converters have access to session

This commit is contained in:
David Lord 2021-05-14 08:11:09 -07:00
parent 8648750997
commit a7b02b3a07
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
4 changed files with 28 additions and 16 deletions

View file

@ -2,21 +2,26 @@ import flask
from flask.sessions import SessionInterface
def test_open_session_endpoint_not_none():
# Define a session interface that breaks if request.endpoint is None
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):
def save_session(self):
def save_session(self, app, session, response):
pass
def open_session(self, _, request):
def open_session(self, app, request):
flask._request_ctx_stack.top.match_request()
assert request.endpoint is not None
def index():
return "Hello World!"
# Confirm a 200 response, indicating that request.endpoint was NOT None
app = flask.Flask(__name__)
app.route("/")(index)
app.session_interface = MySessionInterface()
response = app.test_client().open("/")
@app.get("/")
def index():
return "Hello, World!"
response = app.test_client().get("/")
assert response.status_code == 200