Skip to content

Commit

Permalink
Fix error related to throttling ResendConfirmationEmail
Browse files Browse the repository at this point in the history
By duplicating the request as we are accessing request.DATA twice. To get the
request DATA, `djangorestframework` `read` the `POST` request (a stream)
without rewinding the stream.
This was producing an `Assertion` error happenign only in a test where
we were calling the `view` with the same `request` twices returning:
{'detail': 'JSON parse error - No JSON object could be decoded'}`
https://github.com/tomchristie/django-rest-framework/blob/650a91ac24cbd3e5b4ad5d7d7c6706fdf6160a78/rest_framework/parsers.py#L60-L64
  • Loading branch information
Kevin Etienne committed Apr 17, 2015
1 parent 678c974 commit 4a26535
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions user_management/api/tests/test_throttling.py
Expand Up @@ -135,6 +135,15 @@ def test_post_rate_limit(self):
response = view(request)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

# Duplicate the request here as we are accessing request.DATA twice. To
# get the `request.DATA`, `djangorestframework` `read` the `POST` request
# (a stream) without rewinding the stream.
# This was producing an `Assertion` error only happening in test where
# calling the `view` with the same `request` twice is returning:
# {'detail': 'JSON parse error - No JSON object could be decoded'}`
# https://github.com/tomchristie/django-rest-framework/blob/650a91ac24cbd3e5b4ad5d7d7c6706fdf6160a78/rest_framework/parsers.py#L60-L64
request = self.create_request('post', data=data, auth=False)
view = self.view_class.as_view()
response = view(request)
self.assertEqual(
response.status_code,
Expand Down

0 comments on commit 4a26535

Please sign in to comment.