def test_enum_field_enum_choices_with_constraint_name(self): column = fields.EnumField(choices=DummyEnum, constraint_name="dummy") self.assertIsInstance(column.type, sa.Enum) self.assertEqual(column.type.enum_class, DummyEnum) self.assertEqual(column.type.name, "dummy") form_field = meta.column_info(column).formfield() self.assertIsInstance(form_field, formfields.EnumField)
def test_enum_field_plain_choices(self): column = fields.EnumField(choices=["a", "b"]) self.assertIsInstance(column.type, sa.Enum) self.assertIsNone(column.type.enum_class) self.assertEqual(column.type.enums, ["a", "b"]) form_field = meta.column_info(column).formfield() self.assertIsInstance(form_field, djangofields.TypedChoiceField) self.assertEqual(form_field.choices, [("a", "a"), ("b", "b")])
def test_override_form_class(self): column = fields.EnumField(choices=["a", "b"], form_class=djangofields.ChoiceField) form_field = meta.column_info(column).formfield() self.assertIs(type(form_field), djangofields.ChoiceField) self.assertIsNot(type(form_field), djangofields.TypedChoiceField) column = fields.URLField(form_class=djangofields.CharField, length=100) form_field = meta.column_info(column).formfield() self.assertIs(type(form_field), djangofields.CharField) self.assertIsNot(type(form_field), djangofields.URLField)
def test_enum_field_bad_config(self): with self.assertRaises(TypeError): fields.EnumField() with self.assertRaises(TypeError): fields.EnumField(DummyEnum)
def test_enum_field_enum_choices(self): column = fields.EnumField(choices=DummyEnum) self.assertIsInstance(column.type, sa.Enum) self.assertEqual(column.type.enum_class, DummyEnum) form_field = meta.column_info(column).formfield() self.assertIsInstance(form_field, formfields.EnumField)