44from cs_types import *
55
66class EqlTest (unittest .TestCase ):
7+ def setUp (self ):
8+ self .template_dict = json .loads ('{"k": "pt", "p": "1", "i": {"t": "table", "c": "column"}, "v": 1, "q": null}' )
9+
710 def test (self ):
811 self .assertTrue (True )
912
@@ -14,94 +17,113 @@ def test_to_db_format(self):
1417 )
1518
1619 def test_from_parsed_json_uses_p_value (self ):
17- parsed = json . loads ( '{"k": "pt", "p": "1", "i": {"t": "table", "c": "column"}, "v": 1, "q": null}' )
20+ self . template_dict [ "p" ] = "1"
1821 self .assertEqual (
19- CsInt .from_parsed_json (parsed ),
22+ CsInt .from_parsed_json (self . template_dict ),
2023 1
2124 )
2225
23- def test_cs_int_prints_value (self ):
24- cs_int = CsInt (1 , "table" , "column" )
26+ def test_cs_int_to_db_format (self ):
27+ cs_int = CsInt (123 , "table" , "column" )
2528 self .assertEqual (
26- cs_int . value_in_db_format () ,
27- "1"
29+ '{"k": "pt", "p": "123", "i": {"t": "table", "c": "column"}, "v": 1, "q": null}' ,
30+ cs_int . to_db_format ()
2831 )
2932
30- def test_ces_int_makes_int (self ):
33+ def test_cs_int_from_parsed_json (self ):
34+ self .template_dict ["p" ] = "123"
3135 self .assertEqual (
32- CsInt .value_from_db_format ( "1" ),
33- 1
36+ CsInt .from_parsed_json ( self . template_dict ),
37+ 123
3438 )
3539
36- def test_cs_bool_prints_value_in_lower_case (self ):
40+ def test_cs_bool_to_db_format_true (self ):
3741 cs_bool = CsBool (True , "table" , "column" )
3842 self .assertEqual (
39- cs_bool .value_in_db_format (),
40- "true"
43+ '{"k": "pt", "p": "true", "i": {"t": "table", "c": "column"}, "v": 1, "q": null}' ,
44+ cs_bool .to_db_format ()
45+ )
46+
47+ def test_cs_bool_to_db_format_false (self ):
48+ cs_bool = CsBool (False , "table" , "column" )
49+ self .assertEqual (
50+ '{"k": "pt", "p": "false", "i": {"t": "table", "c": "column"}, "v": 1, "q": null}' ,
51+ cs_bool .to_db_format ()
4152 )
4253
43- def test_cs_bool_returns_bool (self ):
54+ def test_cs_bool_from_parsed_json_true (self ):
55+ self .template_dict ["p" ] = "true"
4456 self .assertEqual (
45- CsBool .value_from_db_format ( "true" ),
57+ CsBool .from_parsed_json ( self . template_dict ),
4658 True
4759 )
4860
49- def test_cs_date_prints_value (self ):
61+ def test_cs_bool_from_parsed_json_false (self ):
62+ self .template_dict ["p" ] = "false"
63+ self .assertEqual (
64+ CsBool .from_parsed_json (self .template_dict ),
65+ False
66+ )
67+
68+ def test_cs_date_to_db_format (self ):
5069 cs_date = CsDate (date (2024 , 11 , 1 ), "table" , "column" )
5170 self .assertEqual (
52- cs_date . value_in_db_format () ,
53- "2024-11-01"
71+ '{"k": "pt", "p": "2024-11-01", "i": {"t": "table", "c": "column"}, "v": 1, "q": null}' ,
72+ cs_date . to_db_format ()
5473 )
5574
56- def test_cs_date_returns_datetime (self ):
75+ def test_cs_date_from_parsed_json (self ):
76+ self .template_dict ["p" ] = "2024-11-01"
5777 self .assertEqual (
58- CsDate .value_from_db_format ( "2024-11-01" ),
78+ CsDate .from_parsed_json ( self . template_dict ),
5979 date (2024 , 11 , 1 )
6080 )
6181
62- def test_cs_float_prints_value (self ):
82+ def test_cs_float_to_db_format (self ):
6383 cs_float = CsFloat (1.1 , "table" , "column" )
6484 self .assertEqual (
65- cs_float . value_in_db_format () ,
66- "1.1"
85+ '{"k": "pt", "p": "1.1", "i": {"t": "table", "c": "column"}, "v": 1, "q": null}' ,
86+ cs_float . to_db_format ()
6787 )
6888
69- def test_cs_float_returns_float (self ):
89+ def test_cs_float_from_parsed_json (self ):
90+ self .template_dict ["p" ] = "1.1"
7091 self .assertEqual (
71- CsFloat .value_from_db_format ( "1.1" ),
92+ CsFloat .from_parsed_json ( self . template_dict ),
7293 1.1
7394 )
7495
75- def test_cs_text_prints_value (self ):
96+ def test_cs_text_to_db_format (self ):
7697 cs_text = CsText ("text" , "table" , "column" )
7798 self .assertEqual (
78- cs_text . value_in_db_format () ,
79- "text"
99+ '{"k": "pt", "p": "text", "i": {"t": "table", "c": "column"}, "v": 1, "q": null}' ,
100+ cs_text . to_db_format ()
80101 )
81102
82- def test_cs_text_returns_value (self ):
103+ def test_cs_text_from_parsed_json (self ):
104+ self .template_dict ["p" ] = "text"
83105 self .assertEqual (
84- CsText .value_from_db_format ( "text" ),
106+ CsText .from_parsed_json ( self . template_dict ),
85107 "text"
86108 )
87109
88110 def test_cs_jsonb_prints_json_string (self ):
89111 cs_jsonb = CsJsonb ({"a" : 1 }, "table" , "column" )
90112 self .assertEqual (
91- cs_jsonb .value_in_db_format ("ste_vec" ),
113+ cs_jsonb ._value_in_db_format ("ste_vec" ),
92114 '{"a": 1}'
93115 )
94116
95117 def test_cs_jsonb_prints_value_for_ejson_path (self ):
96118 cs_jsonb = CsJsonb ("$.a.b" , "table" , "column" )
97119 self .assertEqual (
98- cs_jsonb .value_in_db_format ("ejson_path" ),
120+ cs_jsonb ._value_in_db_format ("ejson_path" ),
99121 '$.a.b'
100122 )
101123
102124 def test_cs_jsonb_returns_value (self ):
103125 self .assertEqual (
104- CsJsonb .value_from_db_format ('{"a": 1}' ),
126+ CsJsonb ._value_from_db_format ('{"a": 1}' ),
105127 {"a" : 1 }
106128 )
107129
0 commit comments