Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
e61eab43
Commit
e61eab43
authored
Dec 20, 2012
by
Andrew Hankinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust PATCH test cases to use the new DRFRequestFactory
parent
2b5deefe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
27 deletions
+30
-27
rest_framework/tests/decorators.py
+14
-12
rest_framework/tests/generics.py
+16
-15
No files found.
rest_framework/tests/decorators.py
View file @
e61eab43
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
=
DRF
RequestFactory
()
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
):
...
...
rest_framework/tests/generics.py
View file @
e61eab43
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
=
DRF
RequestFactory
()
class
RootView
(
generics
.
ListCreateAPIView
):
...
...
@@ -15,7 +15,7 @@ class RootView(generics.ListCreateAPIView):
model
=
BasicModel
class
InstanceView
(
generics
.
RetrieveUpdateDestroyAPIView
):
class
InstanceView
(
generics
.
Retrieve
Partial
UpdateDestroyAPIView
):
"""
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
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment