Beispiel #1
0
    def test_field_instance_creates_choices_correctly_with_custom_choice_builder(
            self):
        def choice_builder(choice):
            return 'Custom_' + choice.value, choice.value

        instance = EnumChoiceField(CharTestEnum, choice_builder=choice_builder)
        choices = instance.build_choices()

        self.assertEqual(choices, [('Custom_first', 'first'),
                                   ('Custom_second', 'second'),
                                   ('Custom_third', 'third')])
Beispiel #2
0
    def test_field_instance_creates_choices_correctly(self):
        instance = EnumChoiceField(CharTestEnum)
        choices = instance.build_choices()

        self.assertEqual(choices, [('first', 'first'), ('second', 'second'),
                                   ('third', 'third')])
 class CustomChoiceBuilderEnumForm(forms.Form):
     enumerated_field = EnumChoiceField(
         CharTestEnum, choice_builder=custom_choice_builder)
 class NonRequiredForm(forms.Form):
     enumerated_field = EnumChoiceField(CharTestEnum, required=False)
 class StandardEnumForm(forms.Form):
     enumerated_field = EnumChoiceField(CharTestEnum)