Skip to content
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 json argument to test.Client.post() #848

Closed
jwg4 opened this issue Jan 12, 2016 · 5 comments · Fixed by #1404
Closed

Add json argument to test.Client.post() #848

jwg4 opened this issue Jan 12, 2016 · 5 comments · Fixed by #1404
Milestone

Comments

@jwg4
Copy link
Contributor

jwg4 commented Jan 12, 2016

Hi there. I wondered if it would be useful to have an argument json for the method test.Client.post(). The idea would be that you can pass in a request body in the form of a data structure which gets serialized to JSON.
You would not be able to set both data and json, it would simply be a convenience rather than serialize to JSON and then pass in as data.
This argument is present in requests.post() and one reason it might be nice to have it is that makes it possible to keep testing with the Werkzeug client and live testing/monitoring against a production server using Requests closer together.
I am happy to submit a PR for this, but I wanted to check first in case it is seen as bloaty or not a good idea for some other reason. Thanks!

@DoWhileGeek
Copy link

I heavily agree with this idea. I was actually skimming issues to see if theres any talk about a json attribute or method planned for the Response object, I'm probably going to end up creating an issue for this like you did.

@jeffwidman
Copy link
Contributor

Related: pallets/flask#1416

@coilysiren
Copy link

coilysiren commented Jun 17, 2018

To expand on the spec above, currently I do

    response = app.post(
        '/snippets',
        data=json.dumps({'text': 'example'}),
        content_type='application/json',
    )

whereas I would like to do

    response = app.post(
        '/snippets',
        json={'text': 'example'},
    )

@coilysiren
Copy link

Looks like #950 was on the way to getting this done, just needs someone with capacity to finish it!

@coilysiren
Copy link

( last comment I promise !!! )

Looks like this is in already! http://flask.pocoo.org/docs/1.0/testing/#testing-json-apis

@davidism davidism added this to the 0.15 milestone Nov 25, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants