mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-03-11 07:15:51 +03:00
Adjust PATCH test cases to use the new DRFRequestFactory
This commit is contained in:
parent
2b5deefe56
commit
e61eab43f4
|
@ -1,7 +1,7 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from django.test.client import RequestFactory
|
# from django.test.client import RequestFactory
|
||||||
from rest_framework.renderers import JSONRenderer
|
from rest_framework.renderers import JSONRenderer
|
||||||
from rest_framework.parsers import JSONParser
|
from rest_framework.parsers import JSONParser
|
||||||
from rest_framework.authentication import BasicAuthentication
|
from rest_framework.authentication import BasicAuthentication
|
||||||
|
@ -17,11 +17,13 @@ from rest_framework.decorators import (
|
||||||
permission_classes,
|
permission_classes,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from rest_framework.tests.utils import DRFRequestFactory
|
||||||
|
|
||||||
|
|
||||||
class DecoratorTestCase(TestCase):
|
class DecoratorTestCase(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.factory = RequestFactory()
|
self.factory = DRFRequestFactory()
|
||||||
|
|
||||||
def _finalize_response(self, request, response, *args, **kwargs):
|
def _finalize_response(self, request, response, *args, **kwargs):
|
||||||
response.request = request
|
response.request = request
|
||||||
|
@ -63,19 +65,19 @@ class DecoratorTestCase(TestCase):
|
||||||
response = view(request)
|
response = view(request)
|
||||||
self.assertEqual(response.status_code, 405)
|
self.assertEqual(response.status_code, 405)
|
||||||
|
|
||||||
# def test_calling_patch_method(self):
|
def test_calling_patch_method(self):
|
||||||
|
|
||||||
# @api_view(['GET', 'PATCH'])
|
@api_view(['GET', 'PATCH'])
|
||||||
# def view(request):
|
def view(request):
|
||||||
# return Response({})
|
return Response({})
|
||||||
|
|
||||||
# request = self.factory.patch('/')
|
request = self.factory.patch('/')
|
||||||
# response = view(request)
|
response = view(request)
|
||||||
# self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
# request = self.factory.post('/')
|
request = self.factory.post('/')
|
||||||
# response = view(request)
|
response = view(request)
|
||||||
# self.assertEqual(response.status_code, 405)
|
self.assertEqual(response.status_code, 405)
|
||||||
|
|
||||||
def test_renderer_classes(self):
|
def test_renderer_classes(self):
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
|
||||||
from django.utils import simplejson as json
|
from django.utils import simplejson as json
|
||||||
from rest_framework import generics, serializers, status
|
from rest_framework import generics, serializers, status
|
||||||
|
from rest_framework.tests.utils import DRFRequestFactory
|
||||||
from rest_framework.tests.models import BasicModel, Comment, SlugBasedModel
|
from rest_framework.tests.models import BasicModel, Comment, SlugBasedModel
|
||||||
|
|
||||||
|
|
||||||
factory = RequestFactory()
|
factory = DRFRequestFactory()
|
||||||
|
|
||||||
|
|
||||||
class RootView(generics.ListCreateAPIView):
|
class RootView(generics.ListCreateAPIView):
|
||||||
|
@ -15,7 +15,7 @@ class RootView(generics.ListCreateAPIView):
|
||||||
model = BasicModel
|
model = BasicModel
|
||||||
|
|
||||||
|
|
||||||
class InstanceView(generics.RetrieveUpdateDestroyAPIView):
|
class InstanceView(generics.RetrievePartialUpdateDestroyAPIView):
|
||||||
"""
|
"""
|
||||||
Example description for OPTIONS.
|
Example description for OPTIONS.
|
||||||
"""
|
"""
|
||||||
|
@ -180,18 +180,19 @@ class TestInstanceView(TestCase):
|
||||||
updated = self.objects.get(id=1)
|
updated = self.objects.get(id=1)
|
||||||
self.assertEquals(updated.text, 'foobar')
|
self.assertEquals(updated.text, 'foobar')
|
||||||
|
|
||||||
# def test_patch_instance_view(self):
|
def test_patch_instance_view(self):
|
||||||
# """
|
"""
|
||||||
# PATCH requests to RetrieveUpdateDestroyAPIView should update an object.
|
PATCH requests to RetrieveUpdateDestroyAPIView should update an object.
|
||||||
# """
|
"""
|
||||||
# content = {'text': 'foobar'}
|
content = {'text': 'foobar'}
|
||||||
# request = factory.patch('/1', json.dumps(content),
|
request = factory.patch('/1', json.dumps(content),
|
||||||
# content_type='application/json')
|
content_type='application/json')
|
||||||
# response = self.view(request, pk=1).render()
|
|
||||||
# self.assertEquals(response.status_code, status.HTTP_200_OK)
|
response = self.view(request, pk=1).render()
|
||||||
# self.assertEquals(response.data, {'id': 1, 'text': 'foobar'})
|
self.assertEquals(response.status_code, status.HTTP_200_OK)
|
||||||
# updated = self.objects.get(id=1)
|
self.assertEquals(response.data, {'id': 1, 'text': 'foobar'})
|
||||||
# self.assertEquals(updated.text, 'foobar')
|
updated = self.objects.get(id=1)
|
||||||
|
self.assertEquals(updated.text, 'foobar')
|
||||||
|
|
||||||
def test_delete_instance_view(self):
|
def test_delete_instance_view(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user