예제 #1
0
    def test_to_representation_handles_none(self):

        field = EnumField(enum_class=SomeEnum)

        value = field.to_representation(None)

        self.assertIsNone(value)
예제 #2
0
    def test_to_representation_works(self):

        field = EnumField(enum_class=SomeEnum)

        value = field.to_representation(SomeEnum.test1)

        self.assertEqual(value, 'test1')
예제 #3
0
    def test_to_internal_value_works(self):

        field = EnumField(enum_class=SomeEnum)

        value = field.to_internal_value('test2')

        self.assertEqual(value, SomeEnum.test2)
예제 #4
0
    def test_to_internal_value_validates(self):

        field = EnumField(enum_class=SomeEnum)

        with self.assertRaises(ValidationError):
            field.to_internal_value('test3')