From 18338a37d356faebb0f59bd57b2ba876d66e6b73 Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Sun, 16 Dec 2012 14:49:18 -0500 Subject: Adding PATCH support to Django REST Framework --- rest_framework/tests/generics.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'rest_framework/tests/generics.py') diff --git a/rest_framework/tests/generics.py b/rest_framework/tests/generics.py index a8279ef2..1b55a3a5 100644 --- a/rest_framework/tests/generics.py +++ b/rest_framework/tests/generics.py @@ -180,6 +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_delete_instance_view(self): """ DELETE requests to RetrieveUpdateDestroyAPIView should delete an object. -- cgit v1.2.3 From e61eab43f46dd100cf3efe9262474046678951a3 Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Thu, 20 Dec 2012 00:28:01 -0500 Subject: Adjust PATCH test cases to use the new DRFRequestFactory --- rest_framework/tests/generics.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'rest_framework/tests/generics.py') diff --git a/rest_framework/tests/generics.py b/rest_framework/tests/generics.py index 1b55a3a5..a5432d11 100644 --- a/rest_framework/tests/generics.py +++ b/rest_framework/tests/generics.py @@ -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): """ -- cgit v1.2.3 From df1880185c87733a82a41392898e67fe02c769aa Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Sun, 30 Dec 2012 13:57:43 -0400 Subject: Renaming DRFRequestFactory to RequestFactory Updated tests to reflect the new name. --- rest_framework/tests/generics.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'rest_framework/tests/generics.py') diff --git a/rest_framework/tests/generics.py b/rest_framework/tests/generics.py index a5432d11..33ac4b32 100644 --- a/rest_framework/tests/generics.py +++ b/rest_framework/tests/generics.py @@ -1,11 +1,11 @@ from django.test import TestCase 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.utils import RequestFactory from rest_framework.tests.models import BasicModel, Comment, SlugBasedModel -factory = DRFRequestFactory() +factory = RequestFactory() class RootView(generics.ListCreateAPIView): @@ -15,7 +15,7 @@ class RootView(generics.ListCreateAPIView): model = BasicModel -class InstanceView(generics.RetrievePartialUpdateDestroyAPIView): +class InstanceView(generics.RetrieveUpdateDestroyAPIView): """ Example description for OPTIONS. """ -- cgit v1.2.3