mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Merge pull request #2456 from brandoncazander/version-3.1
Fix AttributeError on BrowsableAPI when checking for API version
This commit is contained in:
commit
107198af94
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ from django.conf.urls import patterns, url, include
|
|||
|
||||
from .views import MockView
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
(r'^$', MockView.as_view()),
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user