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

Support bare wsgi request #55

Merged
merged 7 commits into from
Mar 13, 2015
Merged

Support bare wsgi request #55

merged 7 commits into from
Mar 13, 2015

Conversation

asnyatkov
Copy link
Contributor

  • Support bare wsgi environment in _build_request_data
  • Separated headers and user ip extraction methods used by Django request builder

#52

self.assertEqual(data['url'], 'http://example.com/api/test?format=json&param1=value1&param2=value2')
self.assertEqual(data['user_ip'], '127.0.0.1')
self.assertDictEqual(data['GET'], {'format': 'json', 'param1': 'value1', 'param2': 'value2'})
self.assertDictEqual(data['headers'], {'Connection': 'close', 'Host': 'example.com', 'User-Agent': 'Agent'})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing an assertion for the request method

@brianr
Copy link
Member

brianr commented Mar 6, 2015

Thanks @asnyatkov! See comments above. Generally looks good; will be happy to merge once the tests are passing.

'method': request.get('REQUEST_METHOD'),
}
if 'QUERY_STRING' in request:
request_data['GET'] = urlparse.parse_qs(request['QUERY_STRING'], keep_blank_values=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be request_data[request_data['method'].upper()] = ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's correct as-is -- the QUERY_STRING is always the "GET" params. POST data goes in the body, not the query string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use request_data['query'] to store this data. request_data['GET'] is a bit misleading IMO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed what all other request builders do. request_data['GET'] is used in _scrub_request_data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Touché. Ok. Leave it as-is since changing this will require a minor version bump.

@coryvirok
Copy link
Contributor

Thanks for the PR. I've tested and this should be good to merge after my comment about the method name.

except ValueError:
length = 0
input = request.get('wsgi.input')
if length and input and input.seekable():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting the following Exception while POSTing to a simple wsgi server:

AttributeError: '_fileobject' object has no attribute 'seekable'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add attribute check and a unit test.

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

Successfully merging this pull request may close these issues.

3 participants