@@ -80,25 +80,25 @@ class TestAccessHandlerConnection(BaseAccessHandlerTest):
8080 """Test suite for Access Handler connection management."""
8181
8282 @patch ("platform.system" )
83- @patch ("pyodbc.connect " )
84- def test_connect_success (self , mock_connect , mock_platform ):
83+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
84+ def test_connect_success (self , mock_pyodbc , mock_platform ):
8585 """Test successful connection to Access database."""
8686 mock_platform .return_value = "Windows"
8787 mock_connection , _ = self .create_mock_connection_with_cursor ()
88- mock_connect .return_value = mock_connection
88+ mock_pyodbc . connect .return_value = mock_connection
8989
9090 result = self .handler .connect ()
9191
92- mock_connect .assert_called_once_with (
92+ mock_pyodbc . connect .assert_called_once_with (
9393 r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + self .TEST_DB_PATH
9494 )
9595
9696 self .assertTrue (self .handler .is_connected )
9797 self .assertEqual (result , mock_connection )
9898
9999 @patch ("platform.system" )
100- @patch ("pyodbc.connect " )
101- def test_connect_when_already_connected (self , mock_connect , mock_platform ):
100+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
101+ def test_connect_when_already_connected (self , mock_pyodbc , mock_platform ):
102102 """Test that connect returns existing connection when already connected."""
103103 mock_platform .return_value = "Windows"
104104 mock_connection , _ = self .create_mock_connection_with_cursor ()
@@ -107,16 +107,16 @@ def test_connect_when_already_connected(self, mock_connect, mock_platform):
107107
108108 result = self .handler .connect ()
109109
110- mock_connect .assert_not_called ()
110+ mock_pyodbc . connect .assert_not_called ()
111111 self .assertEqual (result , mock_connection )
112112
113113 @patch ("platform.system" )
114- @patch ("pyodbc.connect " )
115- def test_connect_failure (self , mock_connect , mock_platform ):
114+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
115+ def test_connect_failure (self , mock_pyodbc , mock_platform ):
116116 """Test connection failure handling."""
117117 mock_platform .return_value = "Windows"
118118 error_msg = "Driver not found"
119- mock_connect .side_effect = Exception (error_msg )
119+ mock_pyodbc . connect .side_effect = Exception (error_msg )
120120
121121 with self .assertRaises (Exception ) as context :
122122 self .handler .connect ()
@@ -145,12 +145,12 @@ def test_disconnect_when_not_connected(self):
145145 self .assertIsNone (result )
146146
147147 @patch ("platform.system" )
148- @patch ("pyodbc.connect " )
149- def test_check_connection_success (self , mock_connect , mock_platform ):
148+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
149+ def test_check_connection_success (self , mock_pyodbc , mock_platform ):
150150 """Test successful connection check."""
151151 mock_platform .return_value = "Windows"
152152 mock_connection , _ = self .create_mock_connection_with_cursor ()
153- mock_connect .return_value = mock_connection
153+ mock_pyodbc . connect .return_value = mock_connection
154154
155155 result = self .handler .check_connection ()
156156
@@ -159,12 +159,12 @@ def test_check_connection_success(self, mock_connect, mock_platform):
159159 self .assertFalse (self .handler .is_connected ) # Should disconnect after check
160160
161161 @patch ("platform.system" )
162- @patch ("pyodbc.connect " )
163- def test_check_connection_failure (self , mock_connect , mock_platform ):
162+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
163+ def test_check_connection_failure (self , mock_pyodbc , mock_platform ):
164164 """Test connection check failure."""
165165 mock_platform .return_value = "Windows"
166166 error_message = "Cannot open database"
167- mock_connect .side_effect = Exception (error_message )
167+ mock_pyodbc . connect .side_effect = Exception (error_message )
168168
169169 result = self .handler .check_connection ()
170170
@@ -177,12 +177,12 @@ class TestAccessHandlerQueries(BaseAccessHandlerTest):
177177 """Test suite for Access Handler query execution."""
178178
179179 @patch ("platform.system" )
180- @patch ("pyodbc.connect " )
181- def test_native_query_select_success (self , mock_connect , mock_platform ):
180+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
181+ def test_native_query_select_success (self , mock_pyodbc , mock_platform ):
182182 """Test successful SELECT query execution."""
183183 mock_platform .return_value = "Windows"
184184 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
185- mock_connect .return_value = mock_connection
185+ mock_pyodbc . connect .return_value = mock_connection
186186
187187 # Setup test data
188188 columns = ["id" , "name" , "email" ]
@@ -199,12 +199,12 @@ def test_native_query_select_success(self, mock_connect, mock_platform):
199199 mock_cursor .execute .assert_called_once_with (query )
200200
201201 @patch ("platform.system" )
202- @patch ("pyodbc.connect " )
203- def test_native_query_insert_success (self , mock_connect , mock_platform ):
202+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
203+ def test_native_query_insert_success (self , mock_pyodbc , mock_platform ):
204204 """Test successful INSERT query execution."""
205205 mock_platform .return_value = "Windows"
206206 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
207- mock_connect .return_value = mock_connection
207+ mock_pyodbc . connect .return_value = mock_connection
208208 self .setup_mock_write_query (mock_cursor )
209209
210210 query = "INSERT INTO customers (name, email) VALUES ('Test User', 'test@example.com')"
@@ -215,12 +215,12 @@ def test_native_query_insert_success(self, mock_connect, mock_platform):
215215 mock_connection .commit .assert_called_once ()
216216
217217 @patch ("platform.system" )
218- @patch ("pyodbc.connect " )
219- def test_native_query_update_success (self , mock_connect , mock_platform ):
218+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
219+ def test_native_query_update_success (self , mock_pyodbc , mock_platform ):
220220 """Test successful UPDATE query execution."""
221221 mock_platform .return_value = "Windows"
222222 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
223- mock_connect .return_value = mock_connection
223+ mock_pyodbc . connect .return_value = mock_connection
224224 self .setup_mock_write_query (mock_cursor )
225225
226226 query = "UPDATE customers SET status = 'active' WHERE id = 1"
@@ -231,12 +231,12 @@ def test_native_query_update_success(self, mock_connect, mock_platform):
231231 mock_connection .commit .assert_called_once ()
232232
233233 @patch ("platform.system" )
234- @patch ("pyodbc.connect " )
235- def test_native_query_delete_success (self , mock_connect , mock_platform ):
234+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
235+ def test_native_query_delete_success (self , mock_pyodbc , mock_platform ):
236236 """Test successful DELETE query execution."""
237237 mock_platform .return_value = "Windows"
238238 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
239- mock_connect .return_value = mock_connection
239+ mock_pyodbc . connect .return_value = mock_connection
240240 self .setup_mock_write_query (mock_cursor )
241241
242242 query = "DELETE FROM customers WHERE id = 1"
@@ -247,12 +247,12 @@ def test_native_query_delete_success(self, mock_connect, mock_platform):
247247 mock_connection .commit .assert_called_once ()
248248
249249 @patch ("platform.system" )
250- @patch ("pyodbc.connect " )
251- def test_native_query_empty_result (self , mock_connect , mock_platform ):
250+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
251+ def test_native_query_empty_result (self , mock_pyodbc , mock_platform ):
252252 """Test query with empty result set."""
253253 mock_platform .return_value = "Windows"
254254 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
255- mock_connect .return_value = mock_connection
255+ mock_pyodbc . connect .return_value = mock_connection
256256 mock_cursor .fetchall .return_value = []
257257
258258 query = "SELECT * FROM customers WHERE id = 999"
@@ -261,12 +261,12 @@ def test_native_query_empty_result(self, mock_connect, mock_platform):
261261 self .assertEqual (result .type , RESPONSE_TYPE .OK )
262262
263263 @patch ("platform.system" )
264- @patch ("pyodbc.connect " )
265- def test_native_query_failure (self , mock_connect , mock_platform ):
264+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
265+ def test_native_query_failure (self , mock_pyodbc , mock_platform ):
266266 """Test query execution failure."""
267267 mock_platform .return_value = "Windows"
268268 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
269- mock_connect .return_value = mock_connection
269+ mock_pyodbc . connect .return_value = mock_connection
270270
271271 error_message = "Syntax error in query"
272272 mock_cursor .execute .side_effect = Exception (error_message )
@@ -278,12 +278,12 @@ def test_native_query_failure(self, mock_connect, mock_platform):
278278 self .assertIn (error_message , result .error_message )
279279
280280 @patch ("platform.system" )
281- @patch ("pyodbc.connect " )
282- def test_native_query_disconnects_when_needed (self , mock_connect , mock_platform ):
281+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
282+ def test_native_query_disconnects_when_needed (self , mock_pyodbc , mock_platform ):
283283 """Test that native_query disconnects when it opened the connection."""
284284 mock_platform .return_value = "Windows"
285285 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
286- mock_connect .return_value = mock_connection
286+ mock_pyodbc . connect .return_value = mock_connection
287287 self .setup_mock_write_query (mock_cursor )
288288
289289 self .handler .is_connected = False
@@ -294,12 +294,12 @@ def test_native_query_disconnects_when_needed(self, mock_connect, mock_platform)
294294 @patch ("mindsdb.integrations.handlers.access_handler.access_handler.AccessDialect" , MagicMock ())
295295 @patch ("mindsdb.integrations.handlers.access_handler.access_handler.SqlalchemyRender" )
296296 @patch ("platform.system" )
297- @patch ("pyodbc.connect " )
298- def test_query_with_ast (self , mock_connect , mock_platform , mock_render ):
297+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
298+ def test_query_with_ast (self , mock_pyodbc , mock_platform , mock_render ):
299299 """Test query method with AST input."""
300300 mock_platform .return_value = "Windows"
301301 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
302- mock_connect .return_value = mock_connection
302+ mock_pyodbc . connect .return_value = mock_connection
303303 self .setup_mock_write_query (mock_cursor )
304304
305305 mock_renderer = MagicMock ()
@@ -316,12 +316,12 @@ def test_query_with_ast(self, mock_connect, mock_platform, mock_render):
316316 mock_renderer .get_string .assert_called_once_with (ast_query , with_failback = True )
317317
318318 @patch ("platform.system" )
319- @patch ("pyodbc.connect " )
320- def test_native_query_with_special_characters (self , mock_connect , mock_platform ):
319+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
320+ def test_native_query_with_special_characters (self , mock_pyodbc , mock_platform ):
321321 """Test query with special characters."""
322322 mock_platform .return_value = "Windows"
323323 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
324- mock_connect .return_value = mock_connection
324+ mock_pyodbc . connect .return_value = mock_connection
325325 self .setup_mock_select_query (mock_cursor , ["name" ], [("O'Brien" ,)])
326326
327327 query = "SELECT * FROM customers WHERE name = 'O''Brien'"
@@ -331,12 +331,12 @@ def test_native_query_with_special_characters(self, mock_connect, mock_platform)
331331 mock_cursor .execute .assert_called_once_with (query )
332332
333333 @patch ("platform.system" )
334- @patch ("pyodbc.connect " )
335- def test_multiple_sequential_queries (self , mock_connect , mock_platform ):
334+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
335+ def test_multiple_sequential_queries (self , mock_pyodbc , mock_platform ):
336336 """Test multiple sequential queries."""
337337 mock_platform .return_value = "Windows"
338338 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
339- mock_connect .return_value = mock_connection
339+ mock_pyodbc . connect .return_value = mock_connection
340340 self .setup_mock_write_query (mock_cursor )
341341
342342 queries = ["INSERT INTO test VALUES (1)" , "INSERT INTO test VALUES (2)" , "INSERT INTO test VALUES (3)" ]
@@ -350,12 +350,12 @@ class TestAccessHandlerMetadata(BaseAccessHandlerTest):
350350 """Test suite for Access Handler metadata operations."""
351351
352352 @patch ("platform.system" )
353- @patch ("pyodbc.connect " )
354- def test_get_tables_success (self , mock_connect , mock_platform ):
353+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
354+ def test_get_tables_success (self , mock_pyodbc , mock_platform ):
355355 """Test successful retrieval of table list."""
356356 mock_platform .return_value = "Windows"
357357 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
358- mock_connect .return_value = mock_connection
358+ mock_pyodbc . connect .return_value = mock_connection
359359
360360 table_names = ["customers" , "orders" ]
361361 self .setup_mock_tables (mock_cursor , table_names )
@@ -370,12 +370,12 @@ def test_get_tables_success(self, mock_connect, mock_platform):
370370 mock_cursor .tables .assert_called_once_with (tableType = "Table" )
371371
372372 @patch ("platform.system" )
373- @patch ("pyodbc.connect " )
374- def test_get_tables_empty (self , mock_connect , mock_platform ):
373+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
374+ def test_get_tables_empty (self , mock_pyodbc , mock_platform ):
375375 """Test get_tables with no tables."""
376376 mock_platform .return_value = "Windows"
377377 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
378- mock_connect .return_value = mock_connection
378+ mock_pyodbc . connect .return_value = mock_connection
379379 mock_cursor .tables .return_value = []
380380
381381 result = self .handler .get_tables ()
@@ -385,12 +385,12 @@ def test_get_tables_empty(self, mock_connect, mock_platform):
385385 self .assertEqual (len (result .data_frame ), 0 )
386386
387387 @patch ("platform.system" )
388- @patch ("pyodbc.connect " )
389- def test_get_columns_success (self , mock_connect , mock_platform ):
388+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
389+ def test_get_columns_success (self , mock_pyodbc , mock_platform ):
390390 """Test successful retrieval of column list."""
391391 mock_platform .return_value = "Windows"
392392 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
393- mock_connect .return_value = mock_connection
393+ mock_pyodbc . connect .return_value = mock_connection
394394
395395 columns_data = [("id" , "INTEGER" ), ("name" , "VARCHAR" ), ("email" , "VARCHAR" )]
396396 self .setup_mock_columns (mock_cursor , columns_data )
@@ -406,12 +406,12 @@ def test_get_columns_success(self, mock_connect, mock_platform):
406406 mock_cursor .columns .assert_called_once_with (table = "customers" )
407407
408408 @patch ("platform.system" )
409- @patch ("pyodbc.connect " )
410- def test_get_columns_empty (self , mock_connect , mock_platform ):
409+ @patch ("mindsdb.integrations.handlers.access_handler.access_handler.pyodbc " )
410+ def test_get_columns_empty (self , mock_pyodbc , mock_platform ):
411411 """Test get_columns with no columns."""
412412 mock_platform .return_value = "Windows"
413413 mock_connection , mock_cursor = self .create_mock_connection_with_cursor ()
414- mock_connect .return_value = mock_connection
414+ mock_pyodbc . connect .return_value = mock_connection
415415 mock_cursor .columns .return_value = []
416416
417417 result = self .handler .get_columns ("empty_table" )
0 commit comments