You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a reason that the Flask application preprocess_request() methods aren't currently called in the TestCase _pre_setup() method?
Use case: I want to test whether OAuth2 authorization is occurring correctly, and I want to be able to examine the state of the OAuth2 session in a test case. For the Google OAuth2Blueprint, however, this is loaded as follows (found in Flask-Dance, /contrib/google.py):
This registers a function in the main Flask application that loads in the OAuth session upon each new request.
With a regular client, this yields no issues, as seen in the Flask application method (found in Flask, app.py)
deffull_dispatch_request(self):
"""Dispatches the request and on top of that performs request pre and postprocessing as well as HTTP exception catching and error handling. .. versionadded:: 0.7 """self.try_trigger_before_first_request_functions()
try:
request_started.send(self)
rv=self.preprocess_request()
ifrvisNone:
rv=self.dispatch_request()
exceptExceptionase:
rv=self.handle_user_exception(e)
returnself.finalize_request(rv)
As the self.preprocess_request() line loads the session into the context.
However, if you save the application as an instance variable, and manually call the function preprocess_request(), it succeeds.
I'm new at this, so I'm not sure of the wider implications of this, or whether this is a correct solution. In general, though, would calling preprocess_request() in _pre_setup() potentially induce negative side effects?
The text was updated successfully, but these errors were encountered:
Is there a reason that the Flask application preprocess_request() methods aren't currently called in the TestCase _pre_setup() method?
Use case: I want to test whether OAuth2 authorization is occurring correctly, and I want to be able to examine the state of the OAuth2 session in a test case. For the Google OAuth2Blueprint, however, this is loaded as follows (found in Flask-Dance, /contrib/google.py):
This registers a function in the main Flask application that loads in the OAuth session upon each new request.
With a regular client, this yields no issues, as seen in the Flask application method (found in Flask, app.py)
As the self.preprocess_request() line loads the session into the context.
_pre_setup() currently reads, however:
Which yields a RequestContext object, but does not wrap it with preprocessing.
Therefore, within a test case, if you try and print the imported session, you receive the error:
However, if you save the application as an instance variable, and manually call the function preprocess_request(), it succeeds.
I'm new at this, so I'm not sure of the wider implications of this, or whether this is a correct solution. In general, though, would calling preprocess_request() in _pre_setup() potentially induce negative side effects?
The text was updated successfully, but these errors were encountered: