88
99@pytest .fixture
1010def get_connection ():
11- return firebolt_connector .
connect (
'[email protected] ' ,
'Apurva111' ,
'Sigmoid_Alchemy' )
11+ return firebolt_connector .
connect (
'localhost' , 8123 , ' [email protected] ',
'Apurva111' ,
'Sigmoid_Alchemy' )
1212
1313
1414class TestConnect :
@@ -17,27 +17,33 @@ def test_connect_success(self):
17171818 password = "Apurva111"
1919 db_name = "Sigmoid_Alchemy"
20- connection = firebolt_connector .connect (user_email , password , db_name )
20+ host = "localhost"
21+ port = "8123"
22+ connection = firebolt_connector .connect (host , port , user_email , password , db_name )
2123 assert connection .access_token
2224 assert connection .engine_url
2325
2426 def test_connect_invalid_credentials (self ):
25272628 password = "wrongpassword"
2729 db_name = "Sigmoid_Alchemy"
30+ host = "localhost"
31+ port = "8123"
2832 with pytest .raises (exceptions .InvalidCredentialsError ):
29- firebolt_connector .connect (user_email , password , db_name )
33+ firebolt_connector .connect (host , port , user_email , password , db_name )
3034
3135 def test_connect_invalid_database (self ):
32363337 password = "Apurva111"
3438 db_name = "wrongdatabase"
39+ host = "localhost"
40+ port = "8123"
3541 with pytest .raises (exceptions .SchemaNotFoundError ):
36- firebolt_connector .connect (user_email , password , db_name )
42+ firebolt_connector .connect (host , port , user_email , password , db_name )
3743
3844
3945def test_get_description_from_row_valid_rows ():
40- row = {'id' : 1 , 'name' : 'John' , 'is_eligible' : True }
46+ row = {'id' : 1 , 'name' : 'John' , 'is_eligible' : True , 'some_array' : [ 2 , 4 ] }
4147 result = firebolt_connector .get_description_from_row (row )
4248 assert result [0 ][0 ] == 'id'
4349 assert result [0 ][1 ] == firebolt_connector .Type .NUMBER
@@ -48,10 +54,13 @@ def test_get_description_from_row_valid_rows():
4854 assert result [2 ][0 ] == 'is_eligible'
4955 assert result [2 ][1 ] == firebolt_connector .Type .BOOLEAN
5056 assert not result [2 ][6 ]
57+ assert result [3 ][0 ] == 'some_array'
58+ assert result [3 ][1 ] == firebolt_connector .Type .ARRAY
59+ assert not result [3 ][6 ]
5160
5261
5362def test_get_description_from_row_invalid_rows ():
54- row = {'id' : [] }
63+ row = {'id' : {} }
5564 with pytest .raises (Exception ):
5665 firebolt_connector .get_description_from_row (row )
5766
@@ -68,8 +77,13 @@ def test_get_type():
6877 assert firebolt_connector .get_type (value_2_2 ) == 2
6978 assert firebolt_connector .get_type (value_3_1 ) == 3
7079 assert firebolt_connector .get_type (value_3_2 ) == 3
80+ assert firebolt_connector .get_type (value_4 ) == 4
81+
82+
83+ def test_get_type_invalid_type ():
84+ value = {}
7185 with pytest .raises (Exception ):
72- firebolt_connector .get_type (value_4 )
86+ firebolt_connector .get_type (value )
7387
7488
7589class TestConnection :
@@ -81,11 +95,11 @@ def test_cursor(self, get_connection):
8195 assert len (connection .cursors ) > 0
8296 assert type (cursor ) == firebolt_connector .Cursor
8397
84- def test_execute (self , get_connection ):
85- connection = get_connection
86- query = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.DATABASES"
87- cursor = connection .execute (query )
88- assert type (cursor ._results ) == itertools .chain
98+ # def test_execute(self, get_connection):
99+ # connection = get_connection
100+ # query = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.DATABASES"
101+ # cursor = connection.execute(query)
102+ # assert type(cursor._results) == itertools.chain
89103
90104 def test_commit (self ):
91105 pass
@@ -106,25 +120,54 @@ def test_rowcount(self, get_connection):
106120 cursor = connection .cursor ().execute (query )
107121 assert cursor .rowcount == 10
108122
123+ def test_close (self , get_connection ):
124+ connection = get_connection
125+ cursor = connection .cursor ()
126+ if not cursor .closed :
127+ cursor .close ()
128+ assert cursor .closed
109129
110- def test_close (self ):
111- pass
112-
113- def test_execute (self ):
114- pass
115-
116- def test_stream_query (self ):
117- pass
118-
119- def test_fetchone (self ):
120- pass
130+ def test_execute (self , get_connection ):
131+ query = 'select * from lineitem ' \
132+ 'where l_orderkey=3184321 and l_partkey=65945'
133+ connection = get_connection
134+ cursor = connection .cursor ()
135+ assert not cursor ._results
136+ cursor .execute (query )
137+ assert cursor .rowcount == 1
121138
122- def test_fetchmany (self ):
123- pass
139+ def test_executemany (self , get_connection ):
140+ query = "select * from lineitem limit 10"
141+ connection = get_connection
142+ cursor = connection .cursor ()
143+ with pytest .raises (exceptions .NotSupportedError ):
144+ cursor .executemany (query )
124145
125- def test_fetchall (self ):
126- pass
146+ def test_fetchone (self , get_connection ):
147+ query = "select * from lineitem limit 10"
148+ connection = get_connection
149+ cursor = connection .cursor ()
150+ assert not cursor ._results
151+ cursor .execute (query )
152+ result = cursor .fetchone ()
153+ assert isinstance (result , tuple )
127154
155+ def test_fetchmany (self , get_connection ):
156+ query = "select * from lineitem limit 10"
157+ connection = get_connection
158+ cursor = connection .cursor ()
159+ assert not cursor ._results
160+ cursor .execute (query )
161+ result = cursor .fetchmany (3 )
162+ assert isinstance (result , list )
163+ assert len (result ) == 3
128164
129- def test_rows_from_chunks ():
130- pass
165+ def test_fetchall (self , get_connection ):
166+ query = "select * from lineitem limit 10"
167+ connection = get_connection
168+ cursor = connection .cursor ()
169+ assert not cursor ._results
170+ cursor .execute (query )
171+ result = cursor .fetchall ()
172+ assert isinstance (result , list )
173+ assert len (result ) == 10
0 commit comments