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