Commit b5454dd0 by Tom Christie

Tests and tweaks for choice fields

parent e5f0a975
......@@ -750,7 +750,7 @@ class ChoiceField(Field):
self.fail('invalid_choice', input=data)
def to_representation(self, value):
return value
return self.choice_strings_to_values[str(value)]
class MultipleChoiceField(ChoiceField):
......@@ -769,7 +769,7 @@ class MultipleChoiceField(ChoiceField):
])
def to_representation(self, value):
return value
return [self.choice_strings_to_values[str(item)] for item in value]
# File types...
......
......@@ -505,9 +505,11 @@ class TestChoiceField(FieldValues):
'good': 'good',
}
invalid_inputs = {
'awful': ['`awful` is not a valid choice.']
'amazing': ['`amazing` is not a valid choice.']
}
outputs = {
'good': 'good'
}
outputs = {}
field = fields.ChoiceField(
choices=[
('poor', 'Poor quality'),
......@@ -530,7 +532,10 @@ class TestChoiceFieldWithType(FieldValues):
5: ['`5` is not a valid choice.'],
'abc': ['`abc` is not a valid choice.']
}
outputs = {}
outputs = {
'1': 1,
1: 1
}
field = fields.ChoiceField(
choices=[
(1, 'Poor quality'),
......@@ -553,7 +558,9 @@ class TestChoiceFieldWithListChoices(FieldValues):
invalid_inputs = {
'awful': ['`awful` is not a valid choice.']
}
outputs = {}
outputs = {
'good': 'good'
}
field = fields.ChoiceField(choices=('poor', 'medium', 'good'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment