11import datetime
2-
2+ import pytz
33from helpers .data_source_test_helper import DataSourceTestHelper
44from soda_core .common .data_source_impl import DataSourceImpl
55from soda_core .common .data_source_results import QueryResult
@@ -36,6 +36,8 @@ def test_full_create_insert_drop_ast(data_source_test_helper: DataSourceTestHelp
3636 CREATE_TABLE_COLUMN (name = "name" , type = DBDataType .TEXT , length = 255 , nullable = True ),
3737 CREATE_TABLE_COLUMN (name = "small_text" , type = DBDataType .TEXT , length = 3 , nullable = True ),
3838 CREATE_TABLE_COLUMN (name = "my_date" , type = DBDataType .DATE , nullable = True ),
39+ CREATE_TABLE_COLUMN (name = "my_timestamp" , type = DBDataType .TIMESTAMP , nullable = True ),
40+ CREATE_TABLE_COLUMN (name = "my_timestamp_tz" , type = DBDataType .TIMESTAMP_TZ , nullable = True ),
3941 ]
4042
4143 standard_columns = [column .convert_to_standard_column () for column in create_table_columns ]
@@ -66,8 +68,26 @@ def test_full_create_insert_drop_ast(data_source_test_helper: DataSourceTestHelp
6668 INSERT_INTO (
6769 fully_qualified_table_name = my_table_name ,
6870 values = [
69- VALUES_ROW ([LITERAL (1 ), LITERAL ("John" ), LITERAL ("a" ), LITERAL (datetime .date (2021 , 1 , 1 ))]),
70- VALUES_ROW ([LITERAL (2 ), LITERAL ("Jane" ), LITERAL ("b" ), LITERAL (datetime .date (2021 , 1 , 2 ))]),
71+ VALUES_ROW (
72+ [
73+ LITERAL (1 ),
74+ LITERAL ("John" ),
75+ LITERAL ("a" ),
76+ LITERAL (datetime .date (2021 , 1 , 1 )),
77+ LITERAL (datetime .datetime (2021 , 1 , 1 , 12 , 10 , 0 )),
78+ LITERAL (datetime .datetime (2021 , 1 , 1 , 12 , 10 , 0 , tzinfo = datetime .timezone .utc )),
79+ ]
80+ ),
81+ VALUES_ROW (
82+ [
83+ LITERAL (2 ),
84+ LITERAL ("Jane" ),
85+ LITERAL ("b" ),
86+ LITERAL (datetime .date (2021 , 1 , 2 )),
87+ LITERAL (datetime .datetime (2021 , 1 , 2 , 12 , 10 , 0 )),
88+ LITERAL (datetime .datetime (2021 , 1 , 2 , 12 , 10 , 0 , tzinfo = pytz .timezone ("America/New_York" ))),
89+ ]
90+ ),
7191 ],
7292 columns = standard_columns ,
7393 )
@@ -94,6 +114,8 @@ def test_full_create_insert_drop_ast(data_source_test_helper: DataSourceTestHelp
94114 COLUMN ("name" ),
95115 COLUMN ("small_text" ),
96116 COLUMN ("my_date" ),
117+ COLUMN ("my_timestamp" ),
118+ COLUMN ("my_timestamp_tz" ),
97119 ]
98120 ),
99121 FROM (my_table_name [1 :- 1 ]),
@@ -116,6 +138,14 @@ def test_full_create_insert_drop_ast(data_source_test_helper: DataSourceTestHelp
116138 assert result .rows [1 ][3 ] in [datetime .date (2021 , 1 , 2 ), datetime .datetime (2021 , 1 , 2 , 0 , 0 , 0 )]
117139 assert result .rows [2 ][3 ] is None
118140
141+ assert result .rows [0 ][4 ] == datetime .datetime (2021 , 1 , 1 , 12 , 10 , 0 )
142+ assert result .rows [1 ][4 ] == datetime .datetime (2021 , 1 , 2 , 12 , 10 , 0 )
143+ assert result .rows [2 ][4 ] is None
144+
145+ assert result .rows [0 ][5 ] == datetime .datetime (2021 , 1 , 1 , 12 , 10 , 0 , tzinfo = datetime .timezone .utc )
146+ assert result .rows [1 ][5 ] == datetime .datetime (2021 , 1 , 2 , 12 , 10 , 0 , tzinfo = pytz .timezone ("America/New_York" ))
147+ assert result .rows [2 ][5 ] is None
148+
119149 finally :
120150 # Then drop the table to clean up
121151 # We explicitly do not use the "if exists" variant, because the table should exist at this point.
0 commit comments