Skip to content

Commit 135789d

Browse files
committed
added test for Enums and convert_to_sql_value
1 parent 87ea64e commit 135789d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/utils/test_sql_values.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from enum import Enum
12
from unittest import TestCase
23

3-
from piccolo.columns.column_types import Integer, JSON, JSONB
4+
from piccolo.columns.column_types import Integer, JSON, JSONB, Varchar
45
from piccolo.table import Table
56
from piccolo.utils.sql_values import convert_to_sql_value
67

@@ -38,11 +39,22 @@ class MyTable(Table):
3839
convert_to_sql_value(value=instance, column=MyTable.id), 1
3940
)
4041

42+
def test_convert_enum(self):
43+
"""
44+
Make sure Enum instances are converted to their values.
45+
"""
46+
47+
class Colour(Enum):
48+
red = "red"
49+
50+
self.assertEqual(
51+
convert_to_sql_value(value=Colour.red, column=Varchar()), "red"
52+
)
53+
4154
def test_other(self):
4255
"""
4356
Make sure simple Python values are returned correctly.
4457
"""
4558
self.assertEqual(
4659
convert_to_sql_value(value=1, column=Integer()), 1,
4760
)
48-

0 commit comments

Comments
 (0)