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
b64f8066
Commit
b64f8066
authored
Jul 07, 2017
by
Ryan P Kilby
Committed by
Carlton Gibson
Sep 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add json util wrapper, failing JSONField test
parent
f6c19e5e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
1 deletions
+56
-1
rest_framework/utils/encoders.py
+1
-1
rest_framework/utils/json.py
+33
-0
tests/test_fields.py
+1
-0
tests/test_utils.py
+21
-0
No files found.
rest_framework/utils/encoders.py
View file @
b64f8066
"""
Helper classes for parsers.
"""
from
__future__
import
unicode_literals
from
__future__
import
absolute_import
,
unicode_literals
import
datetime
import
decimal
...
...
rest_framework/utils/json.py
0 → 100644
View file @
b64f8066
from
__future__
import
absolute_import
import
functools
import
json
def
strict_constant
(
o
):
raise
ValueError
(
'Out of range float values are not JSON compliant: '
+
repr
(
o
))
@functools.wraps
(
json
.
dump
)
def
dump
(
*
args
,
**
kwargs
):
kwargs
.
setdefault
(
'allow_nan'
,
False
)
return
json
.
dump
(
*
args
,
**
kwargs
)
@functools.wraps
(
json
.
dumps
)
def
dumps
(
*
args
,
**
kwargs
):
kwargs
.
setdefault
(
'allow_nan'
,
False
)
return
json
.
dumps
(
*
args
,
**
kwargs
)
@functools.wraps
(
json
.
load
)
def
load
(
*
args
,
**
kwargs
):
kwargs
.
setdefault
(
'parse_constant'
,
strict_constant
)
return
json
.
load
(
*
args
,
**
kwargs
)
@functools.wraps
(
json
.
loads
)
def
loads
(
*
args
,
**
kwargs
):
kwargs
.
setdefault
(
'parse_constant'
,
strict_constant
)
return
json
.
loads
(
*
args
,
**
kwargs
)
tests/test_fields.py
View file @
b64f8066
...
...
@@ -1896,6 +1896,7 @@ class TestJSONField(FieldValues):
]
invalid_inputs
=
[
({
'a'
:
set
()},
[
'Value must be valid JSON.'
]),
({
'a'
:
float
(
'inf'
)},
[
'Value must be valid JSON.'
]),
]
outputs
=
[
({
...
...
tests/test_utils.py
View file @
b64f8066
...
...
@@ -9,6 +9,7 @@ import rest_framework.utils.model_meta
from
rest_framework.compat
import
_resolve_model
from
rest_framework.routers
import
SimpleRouter
from
rest_framework.serializers
import
ModelSerializer
from
rest_framework.utils
import
json
from
rest_framework.utils.breadcrumbs
import
get_breadcrumbs
from
rest_framework.views
import
APIView
from
rest_framework.viewsets
import
ModelViewSet
...
...
@@ -177,3 +178,23 @@ class ResolveModelWithPatchedDjangoTests(TestCase):
def
test_blows_up_if_model_does_not_resolve
(
self
):
with
self
.
assertRaises
(
ImproperlyConfigured
):
_resolve_model
(
'tests.BasicModel'
)
class
JsonFloatTests
(
TestCase
):
"""
Internaly, wrapped json functions should adhere to strict float handling
"""
def
test_dumps
(
self
):
with
self
.
assertRaises
(
ValueError
):
json
.
dumps
(
float
(
'inf'
))
with
self
.
assertRaises
(
ValueError
):
json
.
dumps
(
float
(
'nan'
))
def
test_loads
(
self
):
with
self
.
assertRaises
(
ValueError
):
json
.
loads
(
"Infinity"
)
with
self
.
assertRaises
(
ValueError
):
json
.
loads
(
"NaN"
)
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