|
@@ -12,11 +12,7 @@ from reflex.vars import Var
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
"type_,expected",
|
|
|
- [
|
|
|
- (str, True),
|
|
|
- (dict, True),
|
|
|
- (Dict[int, int], True),
|
|
|
- ],
|
|
|
+ [(str, True), (dict, True), (Dict[int, int], True), (Enum, True)],
|
|
|
)
|
|
|
def test_has_serializer(type_: Type, expected: bool):
|
|
|
"""Test that has_serializer returns the correct value.
|
|
@@ -46,6 +42,7 @@ def test_has_serializer(type_: Type, expected: bool):
|
|
|
(int, serializers.serialize_primitive),
|
|
|
(float, serializers.serialize_primitive),
|
|
|
(bool, serializers.serialize_primitive),
|
|
|
+ (Enum, serializers.serialize_enum),
|
|
|
],
|
|
|
)
|
|
|
def test_get_serializer(type_: Type, expected: serializers.Serializer):
|
|
@@ -103,6 +100,13 @@ class StrEnum(str, Enum):
|
|
|
BAR = "bar"
|
|
|
|
|
|
|
|
|
+class TestEnum(Enum):
|
|
|
+ """A lone enum class."""
|
|
|
+
|
|
|
+ FOO = "foo"
|
|
|
+ BAR = "bar"
|
|
|
+
|
|
|
+
|
|
|
class EnumWithPrefix(Enum):
|
|
|
"""An enum with a serializer adding a prefix."""
|
|
|
|
|
@@ -145,6 +149,12 @@ class BaseSubclass(Base):
|
|
|
{"key1": EnumWithPrefix.FOO, "key2": EnumWithPrefix.BAR},
|
|
|
'{"key1": "prefix_foo", "key2": "prefix_bar"}',
|
|
|
),
|
|
|
+ (TestEnum.FOO, "foo"),
|
|
|
+ ([TestEnum.FOO, TestEnum.BAR], '["foo", "bar"]'),
|
|
|
+ (
|
|
|
+ {"key1": TestEnum.FOO, "key2": TestEnum.BAR},
|
|
|
+ '{"key1": "foo", "key2": "bar"}',
|
|
|
+ ),
|
|
|
(
|
|
|
BaseSubclass(ts=datetime.timedelta(1, 1, 1)),
|
|
|
'{"ts": "1 day, 0:00:01.000001"}',
|