def test_select_field_creation_with_single_select(self): select_field = SelectField("select something", "some_code", "what do u want to select", [('opt1', 'a'), ('opt2', 'b'), ('opt3', 'c')]) select_field.value = 'a' choice_field = FormField().create(select_field) self.assertTrue(isinstance(choice_field.widget, forms.widgets.Select)) self.assertEquals(choice_field.initial, 'a') self.assertEquals([('', '--None--'), ('a', 'opt1'), ('b', 'opt2'), ('c', 'opt3')], choice_field.choices)
def _get_select_field(self, is_required, single_select_flag, label='test'): choices = [("Red", "a"), ("Green", "b"), ("Blue", "c")] expected_choices = [("a", "Red"), ("b", "Green"), ("c", "Blue")] text_field = SelectField(name=label, code=self.select_field_code, label=label, ddtype=Mock(spec=DataDictType), options=choices, single_select_flag=single_select_flag, required=is_required) text_field.value = "Red,Green,Blue" return expected_choices, text_field
def test_select_field_creation_with_multi_select(self): select_field = SelectField("select something", "some_code", "what do u want to select", [('opt1', 'a'), ('opt2', 'b'), ('opt3', 'c')], single_select_flag=False) select_field.value = 'opt1,opt2' choice_field = FormField().create(select_field) self.assertTrue( isinstance(choice_field.widget, forms.CheckboxSelectMultiple)) self.assertEquals(choice_field.initial, ['a', 'b']) self.assertEquals([('a', 'opt1'), ('b', 'opt2'), ('c', 'opt3')], choice_field.choices)