Decorators that accepts kwargs from URL test#36
Open
shuhaowu wants to merge 1 commit into
Open
Conversation
Test will fail with saying multiple id keyword. In reality, kwargs will have `id` and the actually `id` is passed with `self`, an instance of DecoratedView
Owner
|
Hi @shuhaowu I'm sorry it's taken me so long to get to this. Can you give me some more background on this issue or what decorators you've come across in the wild that cause this same problem? |
|
Hi @apiguy When combining flask-classy with http://pythonhosted.org/Flask-OAuth/ (and flask-oauthlib) we experience the same issue. class LoginView(FlaskView):
route_base = '/'
@oauth.authorized_handler
@route('/oauth2callback')
def oauth2callback(self, data):
access_token = data['access_token']
# snipped
return redirect('/')data and self are switched around. This is because inside the decorator data is passed in as the first argument. def authorized_handler(self, f):
"""Injects additional authorization functionality into the function.
The function will be passed the response object as first argument
if the request was allowed, or `None` if access was denied. When the
authorized handler is called, the temporary issued tokens are already
destroyed.
"""
@wraps(f)
def decorated(*args, **kwargs):
if 'oauth_verifier' in request.args:
data = self.handle_oauth1_response()
elif 'code' in request.args:
data = self.handle_oauth2_response()
else:
data = self.handle_unknown_response()
self.free_request_token()
return f(*((data,) + args), **kwargs)
return decoratedNot sure how you would go about addressing this. |
|
Actually, to fix it I just had to do this: class LoginView(FlaskView):
route_base = '/'
@route('/oauth2callback')
def oauth2callback(self):
@oauth.authorized_handler
def save_access_token(data):
access_token = data['access_token']
# snipp
save_access_token()
return redirect('/')which seems to work. Looks a bit dirty though. |
fbarresi
pushed a commit
to fbarresi/flask-classy
that referenced
this pull request
Jan 14, 2017
fix flake8 errors except for complexity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test will fail with saying multiple id keyword. In reality, kwargs will
have
idand the actuallyidis passed withself, an instance ofDecoratedViewTest case for #35