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

Allow developers to define TestRequest URL params and body separately #94

Open
eric-optimizely opened this issue Dec 16, 2013 · 3 comments

Comments

@eric-optimizely
Copy link

Webtest seems to confuse URL parameters and body content when creating JSON requests.

For example:

# Test GET /api/photos?id=10
response = self.testapp.get('/api/photos/', {'id': 10})

# If I want to test PUT /api/photos?id=10 I have to do this:
response = self.testapp.put_json('/api/photos?id=10', {'title': 'Different title'})
# Because the following will PUT to /api/photos and will serialize id=10 in the JSON body.
response = self.testapp.put_json('/api/photos', {'id': 10, 'title': 'Different title'})

In my request handlers, request.get and request.json.get are not equivalent. Example:

def put(self):
  # Get the id from the URL params.
  id_param = self.request.get('id')
  # Get the id from the JSON body.
  id_val = self.request.json.get('id')

It'd be fantastic if webtest supported both as separate options.

response = self.testapp.put_json(url, params, body, headers, *args, **kwargs)
@eric-optimizely
Copy link
Author

It looks like I may have confused myself about the expectations of parameters in GET vs POST requests. WebOb also offers Request.params which is a combination of the query string and request body. This seems like confusing behavior to me since there's potential for overlap, but I'm willing to admit that I misunderstood it.

@gawel
Copy link
Member

gawel commented Apr 16, 2014

This will be hard to do without breaking a lot of code. And I don't think that it's really RESTful compliant..

@merwok
Copy link

merwok commented Feb 28, 2017

I agree that /things/?id=10 doesn’t follow common best practices that would recomment /things/10. But I also think that HTTP lets you have both a query string in the URI and a request body.

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

3 participants