Merge pull request #2456 from brandoncazander/version-3.1

Fix AttributeError on BrowsableAPI when checking for API version
This commit is contained in:
Tom Christie 2015-01-27 09:09:59 +00:00
commit 107198af94
3 changed files with 18 additions and 0 deletions

View File

@ -107,6 +107,8 @@ def clone_request(request, method):
ret.accepted_renderer = request.accepted_renderer
if hasattr(request, 'accepted_media_type'):
ret.accepted_media_type = request.accepted_media_type
if hasattr(request, 'version'):
ret.version = request.version
return ret

View File

@ -3,6 +3,7 @@ from django.conf.urls import patterns, url, include
from .views import MockView
urlpatterns = patterns(
'',
(r'^$', MockView.as_view()),

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals
from rest_framework import exceptions, serializers, status, views
from rest_framework.request import Request
from rest_framework.renderers import BrowsableAPIRenderer
from rest_framework.test import APIRequestFactory
request = Request(APIRequestFactory().options('/'))
@ -168,3 +169,17 @@ class TestMetadata:
response = view(request=request)
assert response.status_code == status.HTTP_200_OK
assert list(response.data['actions'].keys()) == ['POST']
def test_bug_2455_clone_request(self):
class ExampleView(views.APIView):
renderer_classes = (BrowsableAPIRenderer,)
def post(self, request):
pass
def get_serializer(self):
assert hasattr(self.request, 'version')
return serializers.Serializer()
view = ExampleView.as_view()
view(request=request)