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
b5454dd0
Commit
b5454dd0
authored
Sep 22, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests and tweaks for choice fields
parent
e5f0a975
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
6 deletions
+13
-6
rest_framework/fields.py
+2
-2
tests/test_fields.py
+11
-4
No files found.
rest_framework/fields.py
View file @
b5454dd0
...
@@ -750,7 +750,7 @@ class ChoiceField(Field):
...
@@ -750,7 +750,7 @@ class ChoiceField(Field):
self
.
fail
(
'invalid_choice'
,
input
=
data
)
self
.
fail
(
'invalid_choice'
,
input
=
data
)
def
to_representation
(
self
,
value
):
def
to_representation
(
self
,
value
):
return
value
return
self
.
choice_strings_to_values
[
str
(
value
)]
class
MultipleChoiceField
(
ChoiceField
):
class
MultipleChoiceField
(
ChoiceField
):
...
@@ -769,7 +769,7 @@ class MultipleChoiceField(ChoiceField):
...
@@ -769,7 +769,7 @@ class MultipleChoiceField(ChoiceField):
])
])
def
to_representation
(
self
,
value
):
def
to_representation
(
self
,
value
):
return
value
return
[
self
.
choice_strings_to_values
[
str
(
item
)]
for
item
in
value
]
# File types...
# File types...
...
...
tests/test_fields.py
View file @
b5454dd0
...
@@ -505,9 +505,11 @@ class TestChoiceField(FieldValues):
...
@@ -505,9 +505,11 @@ class TestChoiceField(FieldValues):
'good'
:
'good'
,
'good'
:
'good'
,
}
}
invalid_inputs
=
{
invalid_inputs
=
{
'awful'
:
[
'`awful` is not a valid choice.'
]
'amazing'
:
[
'`amazing` is not a valid choice.'
]
}
outputs
=
{
'good'
:
'good'
}
}
outputs
=
{}
field
=
fields
.
ChoiceField
(
field
=
fields
.
ChoiceField
(
choices
=
[
choices
=
[
(
'poor'
,
'Poor quality'
),
(
'poor'
,
'Poor quality'
),
...
@@ -530,7 +532,10 @@ class TestChoiceFieldWithType(FieldValues):
...
@@ -530,7 +532,10 @@ class TestChoiceFieldWithType(FieldValues):
5
:
[
'`5` is not a valid choice.'
],
5
:
[
'`5` is not a valid choice.'
],
'abc'
:
[
'`abc` is not a valid choice.'
]
'abc'
:
[
'`abc` is not a valid choice.'
]
}
}
outputs
=
{}
outputs
=
{
'1'
:
1
,
1
:
1
}
field
=
fields
.
ChoiceField
(
field
=
fields
.
ChoiceField
(
choices
=
[
choices
=
[
(
1
,
'Poor quality'
),
(
1
,
'Poor quality'
),
...
@@ -553,7 +558,9 @@ class TestChoiceFieldWithListChoices(FieldValues):
...
@@ -553,7 +558,9 @@ class TestChoiceFieldWithListChoices(FieldValues):
invalid_inputs
=
{
invalid_inputs
=
{
'awful'
:
[
'`awful` is not a valid choice.'
]
'awful'
:
[
'`awful` is not a valid choice.'
]
}
}
outputs
=
{}
outputs
=
{
'good'
:
'good'
}
field
=
fields
.
ChoiceField
(
choices
=
(
'poor'
,
'medium'
,
'good'
))
field
=
fields
.
ChoiceField
(
choices
=
(
'poor'
,
'medium'
,
'good'
))
...
...
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