-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
JSON support for test client and response object #1416
Conversation
Not ready for review yet. |
getter = getattr(req, 'get_data', None) | ||
if getter is not None: | ||
return getter(cache=cache) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@untitaker I suggest to close #1408 and move the conversation to this pull request, since it incorporates both changes including documentation. |
This is quite a bunch to review. I'll take a look at it sometime, but I don't have the time ATM and I'd apprechiate if somebody else looked over it too. |
email = 'john@example.com' | ||
password = 'secret' | ||
resp = c.post('/api/auth', json={'email': email, 'password': password}) | ||
assert verify_token(email, resp.json['token']) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Thanks @ThiefMaster |
if cache: | ||
self._cached_json = rv | ||
return rv | ||
|
||
def on_json_loading_failed(self, e): | ||
"""Called if decoding of the JSON data failed. The return value of | ||
this method is used by :meth:`get_json` when an error occurred. The |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@untitaker @ThiefMaster Thanks a lot for the review, I've gone through all your comments, so please take one more look. One thing that's not clear to me is what is the reason for deprecating the I understand that there is some computation and caching hidden under the hood, but most people working with JSON APIs won't have to worry about that, and the rest can use the getters directly if they want to. |
I think you are supposed to use something like |
I think the general idea was to make resource management more explicit. IIRC there was a Werkzeug or Flask issue where somebody expected to be able to read from the |
But it's the same for e.g. |
I'm not sure where I stand either, but I think |
I use |
Regarding API breakage in general: To be fair, you have a lot of time to upgrade as Flask releases are really rare. |
I think changing |
Hmm, I think we should move this discussion somewhere else, perhaps a new issue. I'll keep this PR unmerged and will properly review it |
Sure, let's track this separately, and I'm happy to stay involved. You know where I stand, even when this becomes deprecated I will still use |
Just to clarify, this should be ready for the final review regardless of the result of that discussion. |
@untitaker Gentle ping. |
@adambyrtek Could you check whether the new attrs for response show up correctly in the docs? |
@untitaker You mean the API docs? Now is does, it never showed up for |
@untitaker What do you think? |
@untitaker I prefer to keep the history for the record (unless it contains something obviously unnecessary or erroneous) so feel free to merge when you're ready to do so. |
I pinged @mitsuhiko about this again in IRC. |
Just to be sure you remember, you said "Will merge. Could you rebase?" some time ago (see #1416 (comment)). Anyway, I'm happy to wait for the blessing. While we're at this, it would be great to get @mitsuhiko opinion on #1421 |
Argh. Sorry. I don't know what to do. I can't reach him. |
@untitaker Maybe you should just make a judgement call? I don't think this PR introduces anything revolutionary. It simply adds JSON capabilities to the response object, mostly for testing purposes. |
Yes, and @mitsuhiko has been known to oppose decisions that seemed straightforward to anybody else. Apparently that means that no real progress can be made, but it's not my decision to judge whether that's a good outcome -- it's still Armin's project after all. |
Fair enough, I didn't know that he is the sole maintainer. |
@@ -20,7 +21,7 @@ | |||
from urlparse import urlsplit as url_parse | |||
|
|||
|
|||
def make_test_environ_builder(app, path='/', base_url=None, *args, **kwargs): | |||
def make_test_environ_builder(app, path='/', base_url=None, json=None, *args, **kwargs): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@mitsuhiko I've seen your recent comment on another JSON-related issue. Would you mind taking a look at this one? |
return self.get_json() | ||
|
||
def _get_data_for_json(self, cache): | ||
getter = getattr(self, 'get_data', None) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Thanks for the comments. I'm happy to do the changes but only if this has a chance of moving forward. |
That is totally understandable, and thank you for all your work. I personally On Fri, Apr 22, 2016 at 09:36:16AM -0700, Adam Byrtek wrote:
|
I think it generally looks reasonable. I don't have any arguments for not merging it. |
Excellent. @adambyrtek do you have time? |
@adambyrtek So this didn't make it in time. Are you still interested in updating this? |
pallets/werkzeug#948 addresses the Response side of this issue. It needs a review if anyone wants to jump on it. |
I'm picking this up at #1984 |
Common code has been refactored into a mixin shared between request and response classes. This is a continuation of #1408.