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
8bd5e7e6
Commit
8bd5e7e6
authored
Apr 10, 2014
by
Carlton Gibson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1515 from carltongibson/#1408
Added test for #1408 — Already Passes
parents
b0ba8d61
a73498d7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
rest_framework/relations.py
+2
-0
rest_framework/tests/test_relations.py
+24
-0
No files found.
rest_framework/relations.py
View file @
8bd5e7e6
...
...
@@ -59,6 +59,8 @@ class RelatedField(WritableField):
super
(
RelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
if
not
self
.
required
:
# Accessed in ModelChoiceIterator django/forms/models.py:1034
# If set adds empty choice.
self
.
empty_label
=
BLANK_CHOICE_DASH
[
0
][
1
]
self
.
queryset
=
queryset
...
...
rest_framework/tests/test_relations.py
View file @
8bd5e7e6
...
...
@@ -2,8 +2,10 @@
General tests for relational fields.
"""
from
__future__
import
unicode_literals
from
django
import
get_version
from
django.db
import
models
from
django.test
import
TestCase
from
django.utils
import
unittest
from
rest_framework
import
serializers
from
rest_framework.tests.models
import
BlogPost
...
...
@@ -118,3 +120,25 @@ class RelatedFieldSourceTests(TestCase):
(
serializers
.
ModelSerializer
,),
attrs
)
with
self
.
assertRaises
(
AttributeError
):
TestSerializer
(
data
=
{
'name'
:
'foo'
})
@unittest.skipIf
(
get_version
()
<
'1.6.0'
,
'Upstream behaviour changed in v1.6'
)
class
RelatedFieldChoicesTests
(
TestCase
):
"""
Tests for #1408 "Web browseable API doesn't have blank option on drop down list box"
https://github.com/tomchristie/django-rest-framework/issues/1408
"""
def
test_blank_option_is_added_to_choice_if_required_equals_false
(
self
):
"""
"""
post
=
BlogPost
(
title
=
"Checking blank option is added"
)
post
.
save
()
queryset
=
BlogPost
.
objects
.
all
()
field
=
serializers
.
RelatedField
(
required
=
False
,
queryset
=
queryset
)
choice_count
=
BlogPost
.
objects
.
count
()
widget_count
=
len
(
field
.
widget
.
choices
)
self
.
assertEqual
(
widget_count
,
choice_count
+
1
,
'BLANK_CHOICE_DASH option should have been added'
)
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