File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ from unittest import TestCase
2+
3+ from piccolo .columns .column_types import Integer , JSON , JSONB
4+ from piccolo .table import Table
5+ from piccolo .utils .sql_values import convert_to_sql_value
6+
7+
8+ class TestConvertToSQLValue (TestCase ):
9+ def test_convert_json (self ):
10+ """
11+ Make sure Python objects are serialised correctly to JSON strings.
12+ """
13+ self .assertEqual (
14+ convert_to_sql_value (value = {"a" : 123 }, column = JSON ()).replace (
15+ " " , ""
16+ ),
17+ '{"a":123}' ,
18+ )
19+
20+ self .assertEqual (
21+ convert_to_sql_value (value = {"a" : 123 }, column = JSONB ()).replace (
22+ " " , ""
23+ ),
24+ '{"a":123}' ,
25+ )
26+
27+ def test_convert_table_instance (self ):
28+ """
29+ Make sure Table instances are converted to integers.
30+ """
31+
32+ class MyTable (Table ):
33+ pass
34+
35+ instance = MyTable (id = 1 )
36+
37+ self .assertEqual (
38+ convert_to_sql_value (value = instance , column = MyTable .id ), 1
39+ )
40+
41+ def test_other (self ):
42+ """
43+ Make sure simple Python values are returned correctly.
44+ """
45+ self .assertEqual (
46+ convert_to_sql_value (value = 1 , column = Integer ()), 1 ,
47+ )
48+
You can’t perform that action at this time.
0 commit comments