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

Set 'Accept: application/json' for the TestApp.*_json requests? #151

Open
bochecha opened this issue Feb 4, 2016 · 6 comments
Open

Set 'Accept: application/json' for the TestApp.*_json requests? #151

bochecha opened this issue Feb 4, 2016 · 6 comments

Comments

@bochecha
Copy link

bochecha commented Feb 4, 2016

I'm working on a Pyramid app, which exposes a json rest api.

In the functional tests, I'm using WebTest and its TestApp.*_json() methods to send json requests.

The app looks at (among other things) the Accept header, to know what to send back to the client.

The various TestApp.*_json() methods already set the Content-Type header to application/json, to tell the server that what is sent is json.

It seems to me that they should also set the Accept header to tell the server that the answer they expect should be json.

Does that make sense?

I'd be happy to send a pull request if you agree to this change.

@gawel
Copy link
Member

gawel commented Feb 5, 2016

It make sens. I've never done that because it may be too restrictive. Also wandering if this can break some existing tests.

@bochecha
Copy link
Author

bochecha commented Feb 5, 2016

I was wondering about tests as well, especially tests using WebTest (as opposed to WebTest's own test suite). 😕

@gawel
Copy link
Member

gawel commented Feb 5, 2016

A solution is to release a new major version with "maybe" backward incompatibility. Let's go for it.

So I guess we can:

  • provide a default accept header to application/json
  • take care of an access= keyword argument
  • if accept is not NoDefault use this value in the header
  • if accept is None do not set the header

If we do that, it may be useful to add a get_json(accept=XX)

Please try to provide tests, docs and a changelog entrie

@bochecha
Copy link
Author

bochecha commented Feb 5, 2016

take care of an access= keyword argument

Did you mean accept= ?

If not, then I have no idea what access= would be.

@gawel
Copy link
Member

gawel commented Feb 5, 2016

Yep, sorry :)

post_json(..., accept='text/html')

@gawel
Copy link
Member

gawel commented Feb 5, 2016

Also maybe accept='*' can be set as Accept='*/*' ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants