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
95670933
Commit
95670933
authored
Feb 11, 2014
by
Carlton Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test and quick fix for #1257
parent
ac1ea5e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
+23
-7
rest_framework/serializers.py
+1
-0
rest_framework/tests/test_serializer.py
+22
-7
No files found.
rest_framework/serializers.py
View file @
95670933
...
@@ -893,6 +893,7 @@ class ModelSerializer(Serializer):
...
@@ -893,6 +893,7 @@ class ModelSerializer(Serializer):
field_name
=
field
.
source
or
field_name
field_name
=
field
.
source
or
field_name
if
field_name
in
exclusions
\
if
field_name
in
exclusions
\
and
not
field
.
read_only
\
and
not
field
.
read_only
\
and
field
.
required
\
and
not
isinstance
(
field
,
Serializer
):
and
not
isinstance
(
field
,
Serializer
):
exclusions
.
remove
(
field_name
)
exclusions
.
remove
(
field_name
)
return
exclusions
return
exclusions
...
...
rest_framework/tests/test_serializer.py
View file @
95670933
...
@@ -71,6 +71,15 @@ class ActionItemSerializer(serializers.ModelSerializer):
...
@@ -71,6 +71,15 @@ class ActionItemSerializer(serializers.ModelSerializer):
class
Meta
:
class
Meta
:
model
=
ActionItem
model
=
ActionItem
class
ActionItemSerializerOptionalFields
(
serializers
.
ModelSerializer
):
"""
Intended to test that fields with `required=False` are excluded from validation.
"""
title
=
serializers
.
CharField
(
required
=
False
)
class
Meta
:
model
=
ActionItem
fields
=
(
'title'
,)
class
ActionItemSerializerCustomRestore
(
serializers
.
ModelSerializer
):
class
ActionItemSerializerCustomRestore
(
serializers
.
ModelSerializer
):
...
@@ -288,7 +297,13 @@ class BasicTests(TestCase):
...
@@ -288,7 +297,13 @@ class BasicTests(TestCase):
serializer
.
save
()
serializer
.
save
()
self
.
assertIsNotNone
(
serializer
.
data
.
get
(
'id'
,
None
),
'Model is saved. `id` should be set.'
)
self
.
assertIsNotNone
(
serializer
.
data
.
get
(
'id'
,
None
),
'Model is saved. `id` should be set.'
)
def
test_fields_marked_as_not_required_are_excluded_from_validation
(
self
):
"""
Check that fields with `required=False` are included in list of exclusions.
"""
serializer
=
ActionItemSerializerOptionalFields
(
self
.
actionitem
)
exclusions
=
serializer
.
get_validation_exclusions
()
self
.
assertTrue
(
'title'
in
exclusions
,
'`title` field was marked `required=False` and should be excluded'
)
class
DictStyleSerializer
(
serializers
.
Serializer
):
class
DictStyleSerializer
(
serializers
.
Serializer
):
...
@@ -1808,14 +1823,14 @@ class SerializerDefaultTrueBoolean(TestCase):
...
@@ -1808,14 +1823,14 @@ class SerializerDefaultTrueBoolean(TestCase):
self
.
assertEqual
(
serializer
.
data
[
'cat'
],
False
)
self
.
assertEqual
(
serializer
.
data
[
'cat'
],
False
)
self
.
assertEqual
(
serializer
.
data
[
'dog'
],
False
)
self
.
assertEqual
(
serializer
.
data
[
'dog'
],
False
)
class
BoolenFieldTypeTest
(
TestCase
):
class
BoolenFieldTypeTest
(
TestCase
):
'''
'''
Ensure the various Boolean based model fields are rendered as the proper
Ensure the various Boolean based model fields are rendered as the proper
field type
field type
'''
'''
def
setUp
(
self
):
def
setUp
(
self
):
'''
'''
Setup an ActionItemSerializer for BooleanTesting
Setup an ActionItemSerializer for BooleanTesting
...
@@ -1831,11 +1846,11 @@ class BoolenFieldTypeTest(TestCase):
...
@@ -1831,11 +1846,11 @@ class BoolenFieldTypeTest(TestCase):
'''
'''
bfield
=
self
.
serializer
.
get_fields
()[
'done'
]
bfield
=
self
.
serializer
.
get_fields
()[
'done'
]
self
.
assertEqual
(
type
(
bfield
),
fields
.
BooleanField
)
self
.
assertEqual
(
type
(
bfield
),
fields
.
BooleanField
)
def
test_nullbooleanfield_type
(
self
):
def
test_nullbooleanfield_type
(
self
):
'''
'''
Test that BooleanField is infered from models.NullBooleanField
Test that BooleanField is infered from models.NullBooleanField
https://groups.google.com/forum/#!topic/django-rest-framework/D9mXEftpuQ8
https://groups.google.com/forum/#!topic/django-rest-framework/D9mXEftpuQ8
'''
'''
bfield
=
self
.
serializer
.
get_fields
()[
'started'
]
bfield
=
self
.
serializer
.
get_fields
()[
'started'
]
...
...
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