@@ -80,93 +80,6 @@ class ClientTestSuite(unittest.TestCase):
8080 "access_token" : "tok" ,
8181 }
8282
83- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
84- def test_close_uses_the_correct_session_id (self , mock_client_class ):
85- instance = mock_client_class .return_value
86-
87- mock_open_session_resp = MagicMock (spec = TOpenSessionResp )()
88- mock_open_session_resp .sessionHandle .sessionId = b"\x22 "
89- instance .open_session .return_value = mock_open_session_resp
90-
91- connection = databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS )
92- connection .close ()
93-
94- # Check the close session request has an id of x22
95- close_session_id = instance .close_session .call_args [0 ][0 ].sessionId
96- self .assertEqual (close_session_id , b"\x22 " )
97-
98- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
99- def test_auth_args (self , mock_client_class ):
100- # Test that the following auth args work:
101- # token = foo,
102- # token = None, _tls_client_cert_file = something, _use_cert_as_auth = True
103- connection_args = [
104- {
105- "server_hostname" : "foo" ,
106- "http_path" : None ,
107- "access_token" : "tok" ,
108- },
109- {
110- "server_hostname" : "foo" ,
111- "http_path" : None ,
112- "_tls_client_cert_file" : "something" ,
113- "_use_cert_as_auth" : True ,
114- "access_token" : None ,
115- },
116- ]
117-
118- for args in connection_args :
119- connection = databricks .sql .connect (** args )
120- host , port , http_path , * _ = mock_client_class .call_args [0 ]
121- self .assertEqual (args ["server_hostname" ], host )
122- self .assertEqual (args ["http_path" ], http_path )
123- connection .close ()
124-
125- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
126- def test_http_header_passthrough (self , mock_client_class ):
127- http_headers = [("foo" , "bar" )]
128- databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS , http_headers = http_headers )
129-
130- call_args = mock_client_class .call_args [0 ][3 ]
131- self .assertIn (("foo" , "bar" ), call_args )
132-
133- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
134- def test_tls_arg_passthrough (self , mock_client_class ):
135- databricks .sql .connect (
136- ** self .DUMMY_CONNECTION_ARGS ,
137- _tls_verify_hostname = "hostname" ,
138- _tls_trusted_ca_file = "trusted ca file" ,
139- _tls_client_cert_key_file = "trusted client cert" ,
140- _tls_client_cert_key_password = "key password" ,
141- )
142-
143- kwargs = mock_client_class .call_args [1 ]
144- self .assertEqual (kwargs ["_tls_verify_hostname" ], "hostname" )
145- self .assertEqual (kwargs ["_tls_trusted_ca_file" ], "trusted ca file" )
146- self .assertEqual (kwargs ["_tls_client_cert_key_file" ], "trusted client cert" )
147- self .assertEqual (kwargs ["_tls_client_cert_key_password" ], "key password" )
148-
149- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
150- def test_useragent_header (self , mock_client_class ):
151- databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS )
152-
153- http_headers = mock_client_class .call_args [0 ][3 ]
154- user_agent_header = (
155- "User-Agent" ,
156- "{}/{}" .format (databricks .sql .USER_AGENT_NAME , databricks .sql .__version__ ),
157- )
158- self .assertIn (user_agent_header , http_headers )
159-
160- databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS , user_agent_entry = "foobar" )
161- user_agent_header_with_entry = (
162- "User-Agent" ,
163- "{}/{} ({})" .format (
164- databricks .sql .USER_AGENT_NAME , databricks .sql .__version__ , "foobar"
165- ),
166- )
167- http_headers = mock_client_class .call_args [0 ][3 ]
168- self .assertIn (user_agent_header_with_entry , http_headers )
169-
17083 @patch ("%s.session.ThriftBackend" % PACKAGE_NAME , ThriftBackendMockFactory .new ())
17184 @patch ("%s.client.ResultSet" % PACKAGE_NAME )
17285 def test_closing_connection_closes_commands (self , mock_result_set_class ):
@@ -290,21 +203,6 @@ def test_context_manager_closes_cursor(self):
290203 cursor .close = mock_close
291204 mock_close .assert_called_once_with ()
292205
293- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
294- def test_context_manager_closes_connection (self , mock_client_class ):
295- instance = mock_client_class .return_value
296-
297- mock_open_session_resp = MagicMock (spec = TOpenSessionResp )()
298- mock_open_session_resp .sessionHandle .sessionId = b"\x22 "
299- instance .open_session .return_value = mock_open_session_resp
300-
301- with databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS ) as connection :
302- pass
303-
304- # Check the close session request has an id of x22
305- close_session_id = instance .close_session .call_args [0 ][0 ].sessionId
306- self .assertEqual (close_session_id , b"\x22 " )
307-
308206 def dict_product (self , dicts ):
309207 """
310208 Generate cartesion product of values in input dictionary, outputting a dictionary
@@ -403,21 +301,6 @@ def test_cancel_command_will_issue_warning_for_cancel_with_no_executing_command(
403301 self .assertTrue (logger_instance .warning .called )
404302 self .assertFalse (mock_thrift_backend .cancel_command .called )
405303
406- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
407- def test_max_number_of_retries_passthrough (self , mock_client_class ):
408- databricks .sql .connect (
409- _retry_stop_after_attempts_count = 54 , ** self .DUMMY_CONNECTION_ARGS
410- )
411-
412- self .assertEqual (
413- mock_client_class .call_args [1 ]["_retry_stop_after_attempts_count" ], 54
414- )
415-
416- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
417- def test_socket_timeout_passthrough (self , mock_client_class ):
418- databricks .sql .connect (_socket_timeout = 234 , ** self .DUMMY_CONNECTION_ARGS )
419- self .assertEqual (mock_client_class .call_args [1 ]["_socket_timeout" ], 234 )
420-
421304 def test_version_is_canonical (self ):
422305 version = databricks .sql .__version__
423306 canonical_version_re = (
@@ -426,33 +309,6 @@ def test_version_is_canonical(self):
426309 )
427310 self .assertIsNotNone (re .match (canonical_version_re , version ))
428311
429- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
430- def test_configuration_passthrough (self , mock_client_class ):
431- mock_session_config = Mock ()
432- databricks .sql .connect (
433- session_configuration = mock_session_config , ** self .DUMMY_CONNECTION_ARGS
434- )
435-
436- self .assertEqual (
437- mock_client_class .return_value .open_session .call_args [0 ][0 ],
438- mock_session_config ,
439- )
440-
441- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
442- def test_initial_namespace_passthrough (self , mock_client_class ):
443- mock_cat = Mock ()
444- mock_schem = Mock ()
445-
446- databricks .sql .connect (
447- ** self .DUMMY_CONNECTION_ARGS , catalog = mock_cat , schema = mock_schem
448- )
449- self .assertEqual (
450- mock_client_class .return_value .open_session .call_args [0 ][1 ], mock_cat
451- )
452- self .assertEqual (
453- mock_client_class .return_value .open_session .call_args [0 ][2 ], mock_schem
454- )
455-
456312 def test_execute_parameter_passthrough (self ):
457313 mock_thrift_backend = ThriftBackendMockFactory .new ()
458314 cursor = client .Cursor (Mock (), mock_thrift_backend )
@@ -610,23 +466,6 @@ def test_column_name_api(self):
610466 },
611467 )
612468
613- @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
614- def test_finalizer_closes_abandoned_connection (self , mock_client_class ):
615- instance = mock_client_class .return_value
616-
617- mock_open_session_resp = MagicMock (spec = TOpenSessionResp )()
618- mock_open_session_resp .sessionHandle .sessionId = b"\x22 "
619- instance .open_session .return_value = mock_open_session_resp
620-
621- databricks .sql .connect (** self .DUMMY_CONNECTION_ARGS )
622-
623- # not strictly necessary as the refcount is 0, but just to be sure
624- gc .collect ()
625-
626- # Check the close session request has an id of x22
627- close_session_id = instance .close_session .call_args [0 ][0 ].sessionId
628- self .assertEqual (close_session_id , b"\x22 " )
629-
630469 @patch ("%s.session.ThriftBackend" % PACKAGE_NAME )
631470 def test_cursor_keeps_connection_alive (self , mock_client_class ):
632471 instance = mock_client_class .return_value
0 commit comments