mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Py3 compat fix
This commit is contained in:
parent
d13c807616
commit
54d82f59ed
|
@ -12,9 +12,9 @@ from __future__ import unicode_literals
|
|||
from django.conf import settings
|
||||
from django.http import QueryDict
|
||||
from django.http.multipartparser import parse_header
|
||||
from django.utils import six
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.datastructures import MergeDict as DjangoMergeDict
|
||||
from django.utils.six import BytesIO
|
||||
from rest_framework import HTTP_HEADER_ENCODING
|
||||
from rest_framework import exceptions
|
||||
from rest_framework.settings import api_settings
|
||||
|
@ -363,7 +363,7 @@ class Request(object):
|
|||
elif hasattr(self._request, 'read'):
|
||||
self._stream = self._request
|
||||
else:
|
||||
self._stream = BytesIO(self.raw_post_data)
|
||||
self._stream = six.BytesIO(self.raw_post_data)
|
||||
|
||||
def _perform_form_overloading(self):
|
||||
"""
|
||||
|
@ -405,7 +405,7 @@ class Request(object):
|
|||
self._CONTENTTYPE_PARAM in self._data
|
||||
):
|
||||
self._content_type = self._data[self._CONTENTTYPE_PARAM]
|
||||
self._stream = BytesIO(self._data[self._CONTENT_PARAM].encode(self.parser_context['encoding']))
|
||||
self._stream = six.BytesIO(self._data[self._CONTENT_PARAM].encode(self.parser_context['encoding']))
|
||||
self._data, self._files, self._full_data = (Empty, Empty, Empty)
|
||||
|
||||
def _parse(self):
|
||||
|
@ -498,4 +498,4 @@ class Request(object):
|
|||
try:
|
||||
return getattr(self._request, attr)
|
||||
except AttributeError:
|
||||
raise info[0], info[1], info[2].tb_next
|
||||
six.reraise(info[0], info[1], info[2].tb_next)
|
||||
|
|
|
@ -249,6 +249,26 @@ class TestUserSetter(TestCase):
|
|||
login(self.request, self.user)
|
||||
self.assertEqual(self.wrapped_request.user, self.user)
|
||||
|
||||
def test_calling_user_fails_when_attribute_error_is_raised(self):
|
||||
"""
|
||||
This proves that when an AttributeError is raised inside of the request.user
|
||||
property, that we can handle this and report the true, underlying error.
|
||||
"""
|
||||
class AuthRaisesAttributeError(object):
|
||||
def authenticate(self, request):
|
||||
import rest_framework
|
||||
rest_framework.MISSPELLED_NAME_THAT_DOESNT_EXIST
|
||||
|
||||
self.request = Request(factory.get('/'), authenticators=(AuthRaisesAttributeError(),))
|
||||
SessionMiddleware().process_request(self.request)
|
||||
|
||||
login(self.request, self.user)
|
||||
try:
|
||||
self.request.user
|
||||
except AttributeError as error:
|
||||
self.assertEqual(str(error), "'module' object has no attribute 'MISSPELLED_NAME_THAT_DOESNT_EXIST'")
|
||||
else:
|
||||
assert False, 'AttributeError not raised'
|
||||
|
||||
class TestAuthSetter(TestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user