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
9094f93d
Commit
9094f93d
authored
Oct 11, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sanitise JSON error messages
parent
83f39b3d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
4 deletions
+16
-4
rest_framework/tests/views.py
+16
-4
No files found.
rest_framework/tests/views.py
View file @
9094f93d
import
copy
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
rest_framework
import
status
...
...
@@ -27,6 +28,17 @@ def basic_view(request):
return
{
'method'
:
'PUT'
,
'data'
:
request
.
DATA
}
def
sanitise_json_error
(
error_dict
):
"""
Exact contents of JSON error messages depend on the installed version
of json.
"""
ret
=
copy
.
copy
(
error_dict
)
chop
=
len
(
'JSON parse error - No JSON object could be decoded'
)
ret
[
'detail'
]
=
ret
[
'detail'
][:
chop
]
return
ret
class
ClassBasedViewIntegrationTests
(
TestCase
):
def
setUp
(
self
):
self
.
view
=
BasicView
.
as_view
()
...
...
@@ -38,7 +50,7 @@ class ClassBasedViewIntegrationTests(TestCase):
'detail'
:
u'JSON parse error - No JSON object could be decoded'
}
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEquals
(
response
.
data
,
expected
)
self
.
assertEquals
(
sanitise_json_error
(
response
.
data
)
,
expected
)
def
test_400_parse_error_tunneled_content
(
self
):
content
=
'f00bar'
...
...
@@ -53,7 +65,7 @@ class ClassBasedViewIntegrationTests(TestCase):
'detail'
:
u'JSON parse error - No JSON object could be decoded'
}
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEquals
(
response
.
data
,
expected
)
self
.
assertEquals
(
sanitise_json_error
(
response
.
data
)
,
expected
)
class
FunctionBasedViewIntegrationTests
(
TestCase
):
...
...
@@ -67,7 +79,7 @@ class FunctionBasedViewIntegrationTests(TestCase):
'detail'
:
u'JSON parse error - No JSON object could be decoded'
}
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEquals
(
response
.
data
,
expected
)
self
.
assertEquals
(
sanitise_json_error
(
response
.
data
)
,
expected
)
def
test_400_parse_error_tunneled_content
(
self
):
content
=
'f00bar'
...
...
@@ -82,4 +94,4 @@ class FunctionBasedViewIntegrationTests(TestCase):
'detail'
:
u'JSON parse error - No JSON object could be decoded'
}
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEquals
(
response
.
data
,
expected
)
self
.
assertEquals
(
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