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
f1f5f92d
Commit
f1f5f92d
authored
May 19, 2013
by
Oscar Vilaplana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests, cleaned up imports
parent
400fd6be
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
17 deletions
+18
-17
rest_framework/tests/fields.py
+10
-8
rest_framework/tests/views.py
+3
-0
rest_framework/views.py
+5
-9
No files found.
rest_framework/tests/fields.py
View file @
f1f5f92d
...
@@ -2,21 +2,23 @@
...
@@ -2,21 +2,23 @@
General serializer field tests.
General serializer field tests.
"""
"""
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.utils.datastructures
import
SortedDict
from
collections
import
namedtuple
from
decimal
import
Decimal
from
uuid
import
uuid4
import
datetime
import
datetime
from
rest_framework.fields
import
(
humanize_field
,
humanize_field_type
,
humanize_form_fields
)
from
django
import
forms
from
django
import
forms
from
d
ecimal
import
Decimal
from
d
jango.core
import
validators
from
django.db
import
models
from
django.db
import
models
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.core
import
validators
from
django.utils.datastructures
import
SortedDict
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
rest_framework.fields
import
(
humanize_field
,
humanize_field_type
,
humanize_form_fields
,
Field
)
from
rest_framework.serializers
import
Serializer
from
rest_framework.serializers
import
Serializer
from
rest_framework.tests.models
import
RESTFrameworkModel
from
rest_framework.tests.models
import
RESTFrameworkModel
from
rest_framework.fields
import
Field
from
collections
import
namedtuple
from
uuid
import
uuid4
class
TimestampedModel
(
models
.
Model
):
class
TimestampedModel
(
models
.
Model
):
...
...
rest_framework/tests/views.py
View file @
f1f5f92d
...
@@ -6,6 +6,8 @@ from rest_framework.decorators import api_view
...
@@ -6,6 +6,8 @@ from rest_framework.decorators import api_view
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework
import
exceptions
from
rest_framework
import
serializers
import
copy
import
copy
factory
=
RequestFactory
()
factory
=
RequestFactory
()
...
@@ -98,3 +100,4 @@ class FunctionBasedViewIntegrationTests(TestCase):
...
@@ -98,3 +100,4 @@ class FunctionBasedViewIntegrationTests(TestCase):
}
}
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
sanitise_json_error
(
response
.
data
),
expected
)
self
.
assertEqual
(
sanitise_json_error
(
response
.
data
),
expected
)
rest_framework/views.py
View file @
f1f5f92d
...
@@ -2,13 +2,16 @@
...
@@ -2,13 +2,16 @@
Provides an APIView class that is the base of all views in REST framework.
Provides an APIView class that is the base of all views in REST framework.
"""
"""
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
from
django.http
import
Http404
,
HttpResponse
from
django.http
import
Http404
,
HttpResponse
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
from
rest_framework
import
status
,
exceptions
from
rest_framework
import
status
,
exceptions
from
rest_framework.compat
import
View
from
rest_framework.compat
import
View
from
rest_framework.
response
import
Response
from
rest_framework.
fields
import
humanize_form_fields
from
rest_framework.request
import
clone_request
,
Request
from
rest_framework.request
import
clone_request
,
Request
from
rest_framework.response
import
Response
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
from
rest_framework.utils.formatting
import
get_view_name
,
get_view_description
from
rest_framework.utils.formatting
import
get_view_name
,
get_view_description
...
@@ -69,7 +72,6 @@ class APIView(View):
...
@@ -69,7 +72,6 @@ class APIView(View):
Helper for generating the fields metadata for allowed and permitted methods.
Helper for generating the fields metadata for allowed and permitted methods.
'''
'''
actions
=
{}
actions
=
{}
for
method
in
self
.
allowed_methods
:
for
method
in
self
.
allowed_methods
:
# skip HEAD and OPTIONS
# skip HEAD and OPTIONS
if
method
in
(
'HEAD'
,
'OPTIONS'
):
if
method
in
(
'HEAD'
,
'OPTIONS'
):
...
@@ -84,17 +86,11 @@ class APIView(View):
...
@@ -84,17 +86,11 @@ class APIView(View):
actions
[
method
]
=
{}
actions
[
method
]
=
{}
continue
continue
# TODO: find right placement - APIView does not have get_serializer
if
not
hasattr
(
self
,
'get_serializer'
):
if
not
hasattr
(
self
,
'get_serializer'
):
continue
continue
serializer
=
self
.
get_serializer
()
serializer
=
self
.
get_serializer
()
if
serializer
is
not
None
:
if
serializer
is
not
None
:
field_name_types
=
{}
actions
[
method
]
=
humanize_form_fields
(
serializer
)
for
name
,
field
in
serializer
.
fields
.
iteritems
():
from
rest_framework.fields
import
humanize_field
field_name_types
[
name
]
=
humanize_field
(
field
)
actions
[
method
]
=
field_name_types
except
exceptions
.
PermissionDenied
:
except
exceptions
.
PermissionDenied
:
# don't add this method
# don't add this method
pass
pass
...
...
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