@@ -80,7 +80,7 @@ class ClientTestSuite(unittest.TestCase):
80
80
"access_token" : "tok" ,
81
81
}
82
82
83
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
83
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
84
84
def test_close_uses_the_correct_session_id (self , mock_client_class ):
85
85
instance = mock_client_class .return_value
86
86
@@ -95,7 +95,7 @@ def test_close_uses_the_correct_session_id(self, mock_client_class):
95
95
close_session_id = instance .close_session .call_args [0 ][0 ].sessionId
96
96
self .assertEqual (close_session_id , b"\x22 " )
97
97
98
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
98
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
99
99
def test_auth_args (self , mock_client_class ):
100
100
# Test that the following auth args work:
101
101
# token = foo,
@@ -122,15 +122,15 @@ def test_auth_args(self, mock_client_class):
122
122
self .assertEqual (args ["http_path" ], http_path )
123
123
connection .close ()
124
124
125
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
125
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
126
126
def test_http_header_passthrough (self , mock_client_class ):
127
127
http_headers = [("foo" , "bar" )]
128
128
databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS , http_headers = http_headers )
129
129
130
130
call_args = mock_client_class .call_args [0 ][3 ]
131
131
self .assertIn (("foo" , "bar" ), call_args )
132
132
133
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
133
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
134
134
def test_tls_arg_passthrough (self , mock_client_class ):
135
135
databricks .sql .connect (
136
136
** self .DUMMY_CONNECTION_ARGS ,
@@ -146,7 +146,7 @@ def test_tls_arg_passthrough(self, mock_client_class):
146
146
self .assertEqual (kwargs ["_tls_client_cert_key_file" ], "trusted client cert" )
147
147
self .assertEqual (kwargs ["_tls_client_cert_key_password" ], "key password" )
148
148
149
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
149
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
150
150
def test_useragent_header (self , mock_client_class ):
151
151
databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS )
152
152
@@ -167,7 +167,7 @@ def test_useragent_header(self, mock_client_class):
167
167
http_headers = mock_client_class .call_args [0 ][3 ]
168
168
self .assertIn (user_agent_header_with_entry , http_headers )
169
169
170
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME , ThriftBackendMockFactory .new ())
170
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME , ThriftBackendMockFactory .new ())
171
171
@patch ("%s.client.ResultSet" % PACKAGE_NAME )
172
172
def test_closing_connection_closes_commands (self , mock_result_set_class ):
173
173
# Test once with has_been_closed_server side, once without
@@ -184,7 +184,7 @@ def test_closing_connection_closes_commands(self, mock_result_set_class):
184
184
)
185
185
mock_result_set_class .return_value .close .assert_called_once_with ()
186
186
187
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
187
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
188
188
def test_cant_open_cursor_on_closed_connection (self , mock_client_class ):
189
189
connection = databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS )
190
190
self .assertTrue (connection .open )
@@ -194,7 +194,7 @@ def test_cant_open_cursor_on_closed_connection(self, mock_client_class):
194
194
connection .cursor ()
195
195
self .assertIn ("closed" , str (cm .exception ))
196
196
197
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
197
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
198
198
@patch ("%s.client.Cursor" % PACKAGE_NAME )
199
199
def test_arraysize_buffer_size_passthrough (
200
200
self , mock_cursor_class , mock_client_class
@@ -214,7 +214,10 @@ def test_closing_result_set_with_closed_connection_soft_closes_commands(self):
214
214
thrift_backend = mock_backend ,
215
215
execute_response = Mock (),
216
216
)
217
- mock_connection .open = False
217
+ # Setup session mock on the mock_connection
218
+ mock_session = Mock ()
219
+ mock_session .open = False
220
+ type(mock_connection ).session = PropertyMock (return_value = mock_session )
218
221
219
222
result_set .close ()
220
223
@@ -226,7 +229,11 @@ def test_closing_result_set_hard_closes_commands(self):
226
229
mock_results_response .has_been_closed_server_side = False
227
230
mock_connection = Mock ()
228
231
mock_thrift_backend = Mock ()
229
- mock_connection .open = True
232
+ # Setup session mock on the mock_connection
233
+ mock_session = Mock ()
234
+ mock_session .open = True
235
+ type(mock_connection ).session = PropertyMock (return_value = mock_session )
236
+
230
237
result_set = client .ResultSet (
231
238
mock_connection , mock_results_response , mock_thrift_backend
232
239
)
@@ -283,7 +290,7 @@ def test_context_manager_closes_cursor(self):
283
290
cursor .close = mock_close
284
291
mock_close .assert_called_once_with ()
285
292
286
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
293
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
287
294
def test_context_manager_closes_connection (self , mock_client_class ):
288
295
instance = mock_client_class .return_value
289
296
@@ -396,7 +403,7 @@ def test_cancel_command_will_issue_warning_for_cancel_with_no_executing_command(
396
403
self .assertTrue (logger_instance .warning .called )
397
404
self .assertFalse (mock_thrift_backend .cancel_command .called )
398
405
399
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
406
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
400
407
def test_max_number_of_retries_passthrough (self , mock_client_class ):
401
408
databricks .sql .connect (
402
409
_retry_stop_after_attempts_count = 54 , ** self .DUMMY_CONNECTION_ARGS
@@ -406,7 +413,7 @@ def test_max_number_of_retries_passthrough(self, mock_client_class):
406
413
mock_client_class .call_args [1 ]["_retry_stop_after_attempts_count" ], 54
407
414
)
408
415
409
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
416
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
410
417
def test_socket_timeout_passthrough (self , mock_client_class ):
411
418
databricks .sql .connect (_socket_timeout = 234 , ** self .DUMMY_CONNECTION_ARGS )
412
419
self .assertEqual (mock_client_class .call_args [1 ]["_socket_timeout" ], 234 )
@@ -419,7 +426,7 @@ def test_version_is_canonical(self):
419
426
)
420
427
self .assertIsNotNone (re .match (canonical_version_re , version ))
421
428
422
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
429
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
423
430
def test_configuration_passthrough (self , mock_client_class ):
424
431
mock_session_config = Mock ()
425
432
databricks .sql .connect (
@@ -431,7 +438,7 @@ def test_configuration_passthrough(self, mock_client_class):
431
438
mock_session_config ,
432
439
)
433
440
434
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
441
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
435
442
def test_initial_namespace_passthrough (self , mock_client_class ):
436
443
mock_cat = Mock ()
437
444
mock_schem = Mock ()
@@ -505,7 +512,7 @@ def test_executemany_parameter_passhthrough_and_uses_last_result_set(
505
512
"last operation" ,
506
513
)
507
514
508
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
515
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
509
516
def test_commit_a_noop (self , mock_thrift_backend_class ):
510
517
c = databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS )
511
518
c .commit ()
@@ -518,7 +525,7 @@ def test_setoutputsizes_a_noop(self):
518
525
cursor = client .Cursor (Mock (), Mock ())
519
526
cursor .setoutputsize (1 )
520
527
521
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
528
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
522
529
def test_rollback_not_supported (self , mock_thrift_backend_class ):
523
530
c = databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS )
524
531
with self .assertRaises (NotSupportedError ):
@@ -603,7 +610,7 @@ def test_column_name_api(self):
603
610
},
604
611
)
605
612
606
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
613
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
607
614
def test_finalizer_closes_abandoned_connection (self , mock_client_class ):
608
615
instance = mock_client_class .return_value
609
616
@@ -620,7 +627,7 @@ def test_finalizer_closes_abandoned_connection(self, mock_client_class):
620
627
close_session_id = instance .close_session .call_args [0 ][0 ].sessionId
621
628
self .assertEqual (close_session_id , b"\x22 " )
622
629
623
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
630
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
624
631
def test_cursor_keeps_connection_alive (self , mock_client_class ):
625
632
instance = mock_client_class .return_value
626
633
@@ -639,7 +646,7 @@ def test_cursor_keeps_connection_alive(self, mock_client_class):
639
646
640
647
@patch ("%s.utils.ExecuteResponse" % PACKAGE_NAME , autospec = True )
641
648
@patch ("%s.client.Cursor._handle_staging_operation" % PACKAGE_NAME )
642
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME )
649
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME )
643
650
def test_staging_operation_response_is_handled (
644
651
self , mock_client_class , mock_handle_staging_operation , mock_execute_response
645
652
):
@@ -658,7 +665,7 @@ def test_staging_operation_response_is_handled(
658
665
659
666
mock_handle_staging_operation .call_count == 1
660
667
661
- @patch ("%s.client .ThriftBackend" % PACKAGE_NAME , ThriftBackendMockFactory .new ())
668
+ @patch ("%s.session .ThriftBackend" % PACKAGE_NAME , ThriftBackendMockFactory .new ())
662
669
def test_access_current_query_id (self ):
663
670
operation_id = "EE6A8778-21FC-438B-92D8-96AC51EE3821"
664
671
0 commit comments