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
a704d5a2
Commit
a704d5a2
authored
May 16, 2014
by
Xavier Ordoquy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed tests for python 3.4
parent
b370fb40
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
rest_framework/tests/test_views.py
+11
-5
No files found.
rest_framework/tests/test_views.py
View file @
a704d5a2
from
__future__
import
unicode_literals
import
sys
import
copy
from
django.test
import
TestCase
from
rest_framework
import
status
...
...
@@ -11,6 +12,11 @@ from rest_framework.views import APIView
factory
=
APIRequestFactory
()
if
sys
.
version_info
[:
2
]
>=
(
3
,
4
):
JSON_ERROR
=
'JSON parse error - Expecting value:'
else
:
JSON_ERROR
=
'JSON parse error - No JSON object could be decoded'
class
BasicView
(
APIView
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -48,7 +54,7 @@ def sanitise_json_error(error_dict):
of json.
"""
ret
=
copy
.
copy
(
error_dict
)
chop
=
len
(
'JSON parse error - No JSON object could be decoded'
)
chop
=
len
(
JSON_ERROR
)
ret
[
'detail'
]
=
ret
[
'detail'
][:
chop
]
return
ret
...
...
@@ -61,7 +67,7 @@ class ClassBasedViewIntegrationTests(TestCase):
request
=
factory
.
post
(
'/'
,
'f00bar'
,
content_type
=
'application/json'
)
response
=
self
.
view
(
request
)
expected
=
{
'detail'
:
'JSON parse error - No JSON object could be decoded'
'detail'
:
JSON_ERROR
}
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
sanitise_json_error
(
response
.
data
),
expected
)
...
...
@@ -76,7 +82,7 @@ class ClassBasedViewIntegrationTests(TestCase):
request
=
factory
.
post
(
'/'
,
form_data
)
response
=
self
.
view
(
request
)
expected
=
{
'detail'
:
'JSON parse error - No JSON object could be decoded'
'detail'
:
JSON_ERROR
}
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
sanitise_json_error
(
response
.
data
),
expected
)
...
...
@@ -90,7 +96,7 @@ class FunctionBasedViewIntegrationTests(TestCase):
request
=
factory
.
post
(
'/'
,
'f00bar'
,
content_type
=
'application/json'
)
response
=
self
.
view
(
request
)
expected
=
{
'detail'
:
'JSON parse error - No JSON object could be decoded'
'detail'
:
JSON_ERROR
}
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
sanitise_json_error
(
response
.
data
),
expected
)
...
...
@@ -105,7 +111,7 @@ class FunctionBasedViewIntegrationTests(TestCase):
request
=
factory
.
post
(
'/'
,
form_data
)
response
=
self
.
view
(
request
)
expected
=
{
'detail'
:
'JSON parse error - No JSON object could be decoded'
'detail'
:
JSON_ERROR
}
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
sanitise_json_error
(
response
.
data
),
expected
)
...
...
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