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
Add get_request_kwargs to check before requesting #339
Conversation
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.
Hi, and thanks for your contribution to MechanicalSoup!
In principle, I think this is a fine change. I've recommended one small spelling error and identified a corner case that probably needs to be addressed. Once those are fixed, I will be ready to approve this. Then if the other maintainer approves as well we can merge it in. :)
The group of jobs in travisci are listed as Queued, but when I click on Details to check, it looks like all the jobs are successful. |
@hemberger Is there anything else I should do? :) |
Commits should be squashed and the typo should be fixed in the commits summary (I just fixed it in the PR title). We keep a clean history hence a PR should include several commits only if the change needs to be split into several commits, not as leftover of previous mistakes. |
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.
On overall, this looks good, but a few more nits to be fixed before this can be merged.
mechanicalsoup/browser.py
Outdated
def _request(self, form, url=None, **kwargs): | ||
"""Extract input data from the form to pass to a Requests session.""" | ||
@classmethod | ||
def _get_request_kwargs(cls, method, url, **kwargs): |
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.
cls
is unused here, right? Why not use @staticmethod
instead of @classmethod
then?
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 good point. I'll use @staticmethod
to avoid making cls
useless.
mechanicalsoup/browser.py
Outdated
@classmethod | ||
def _get_request_kwargs(cls, method, url, **kwargs): | ||
# This method exists to raise a TypeError when a method or url is | ||
# specified in the kwargs. |
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.
Shouldn't this comment be a docstring?
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.
Actually, this is my first time writing a docstring.
I'll be referring to other methods to write docstrings. Please let me know if you have any concerns.
tests/test_browser.py
Outdated
try: | ||
browser.get_request_kwargs(form, page.url, **kwargs) | ||
except TypeError: | ||
type_error_raised = True |
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.
Please use pytest.raises to assert that an exception is raised.
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, I'll rewrite it using pytest.raises.
tests/test_browser.py
Outdated
# pylint: disable=redundant-keyword-arg | ||
browser.get_request_kwargs(form, page.url, **kwargs) | ||
except TypeError: | ||
type_error_raised = True |
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.
Likewise.
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, I'll rewrite it using pytest.raises.
Originally, this pull request was intended to implement Therefore, please let me change the title of the Pull Request. |
I squashed the commits to one. ✨ |
On overall this looks good to me. The commit message would deserve a bit more love I think (explain why the change is needed and good). |
Let me make the commit log more understandable and lovely. I don't plan to make any changes to the code at this time. |
@hemberger @moy Let me know if there's anything else I need to do to get the pull request merged. |
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.
Overall, the changes look great. I've identified one simple change I'd like to see, but then I think this is ready to be merged. Thanks!
Previously, users had no way to check what request data is sent to the server before submitting a form. By calling get_request_kwargs(), the user can see the request data without having to send to.
Thanks again for your contribution! |
Thank you for merging. 😄 By the way, it occurs to me that this was the first time in my life that I've ever had my code reviewed. For me, all of the points you @hemberger @moy have given me are excellent. ✨ Again, thank you for the series of responses and for merging my request. 👍 |
Thanks for the feedback. In another life, I'm a teacher, and that's what I try to explain my students: code review is not "I went through it and it doesn't look too bad", but can be much more picky and constructive than that ;-). |
Previously, users had no way to check what request data is sent to the server before submitting a form. By calling get_request_kwargs(), the user can see the request data without having to send to.
When we use mechanicalsoup, we sometimes want to verify a request before submitting it.
If you merge this pull request, the package will be able to provide a way for the package's users to review the request.
This is my first pull request for this project. Please let me know if I'm missing anything.