-
-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
call as_view in methodresolver #1552
call as_view in methodresolver #1552
Conversation
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
I did not really find out how to write a test for this. All tests have passed. I think this kind of functionality is currently not covered. Like there is no app created to see what the methods return. Or perhaps, I overlooked it. |
We, should probably also update the documentation on this. |
Pull Request Test Coverage Report for Build 2489119200
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bluebrown.
- The changes look good to me in general. I left one small comment on the example.
- We should indeed update the docs on this. Could you have a look?
- As mentioned in the issue, it would be good to still offer a resolver with the old behavior, but we can mark it deprecated.
- The example currently doesn't run on main since we're in the middle of a large refactoring (Move functionality into pluggable ASGI middleware stack #1489), but the resolver itself does seem to work correctly. I submitted a PR which fixes the blocking issue (Use resolver in security middleware #1553).
- The current resolver tests indeed only check the generated
operation_id
, which is unchanged. I'll have a deeper look at the tests later to see how we can best add a test for the changed behavior.
class PetsView(MethodView): | ||
""" Create Pets service | ||
""" | ||
method_decorators = [] | ||
decorators = [example_decorator] | ||
pets = {} | ||
|
||
def post(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a body
argument to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the example to use the body param in post and put
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
|
Signed-off-by: Nico Braun <rainbowstack@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @bluebrown.
I left one comment, but overall changes look great.
I still need to find the time to have a look at how we can add an additional test for the resulting behavior,
@@ -192,7 +192,8 @@ def post(self): | |||
return ... | |||
""" | |||
|
|||
def __init__(self, *args, **kwargs): | |||
def __init__(self, *args, class_arguments=None, **kwargs): | |||
self.class_arguments = class_arguments or {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we name this a bit more specific eg. view_arguments
?
It would also be good to document it here as an argument on top of the documentation you already added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think class_arguments
is more fitting because the arguments for the view function are also called class_args
and class_kwargs
. That's because these arguments are passed to the class when instantiating it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try to add a comment to the init function. I had actually one already with example usage, but the pre-commit hook didn't like it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bluebrown. I'll merge this one and submit a test as a separate PR as we need to rebase on main anyway to make it work. I'll tag you there.
Signed-off-by: Nico Braun rainbowstack@gmail.com
Fixes #1549
The primary reason for this change is to be able to use method decorators as described here: https://flask.palletsprojects.com/en/2.1.x/views/#decorating-views
Changes proposed in this pull request:
MethodResolver
to callas_view
on the classes