def test_default(self): field = ChoiceField(required=True, choices=self.TUPLE_CHOICES, default='three') field.validate() self.assertEqual(field.to_python(), 3) self.assertEqual(field.to_native(), 'three')
def test_choices_tuple(self): field = ChoiceField(required=True, choices=self.TUPLE_CHOICES) field.set_value('two') field.validate() self.assertEqual(field.to_python(), 2) self.assertEqual(field.to_native(), 'two') field = ChoiceField(required=True, choices=self.TUPLE_CHOICES) field.set_value(2) field.validate() self.assertEqual(field.to_python(), 2) self.assertEqual(field.to_native(), 'two')
def test_choices_list(self): field = ChoiceField(required=True, choices=self.LIST_CHOICES) field.set_value('one') field.validate() self.assertEqual(field.to_python(), 'one') self.assertEqual(field.to_native(), 'one')
def test_upper_to_python(self): field = ChoiceField(required=True, upper=True, choices=self.TUPLE_CHOICES) field.set_value('TWO') field.validate() self.assertEqual(field.to_python(), 2) self.assertEqual(field.to_native(), 'TWO')