@@ -145,7 +145,9 @@ def test_get_python_sql_connector_auth_provider_access_token(self):
145
145
hostname = "moderakh-test.cloud.databricks.com"
146
146
kwargs = {"access_token" : "dpi123" }
147
147
mock_http_client = MagicMock ()
148
- auth_provider = get_python_sql_connector_auth_provider (hostname , mock_http_client , ** kwargs )
148
+ auth_provider = get_python_sql_connector_auth_provider (
149
+ hostname , mock_http_client , ** kwargs
150
+ )
149
151
self .assertTrue (type (auth_provider ).__name__ , "AccessTokenAuthProvider" )
150
152
151
153
headers = {}
@@ -163,7 +165,9 @@ def __call__(self, *args, **kwargs) -> HeaderFactory:
163
165
hostname = "moderakh-test.cloud.databricks.com"
164
166
kwargs = {"credentials_provider" : MyProvider ()}
165
167
mock_http_client = MagicMock ()
166
- auth_provider = get_python_sql_connector_auth_provider (hostname , mock_http_client , ** kwargs )
168
+ auth_provider = get_python_sql_connector_auth_provider (
169
+ hostname , mock_http_client , ** kwargs
170
+ )
167
171
self .assertTrue (type (auth_provider ).__name__ , "ExternalAuthProvider" )
168
172
169
173
headers = {}
@@ -179,7 +183,9 @@ def test_get_python_sql_connector_auth_provider_noop(self):
179
183
"_use_cert_as_auth" : use_cert_as_auth ,
180
184
}
181
185
mock_http_client = MagicMock ()
182
- auth_provider = get_python_sql_connector_auth_provider (hostname , mock_http_client , ** kwargs )
186
+ auth_provider = get_python_sql_connector_auth_provider (
187
+ hostname , mock_http_client , ** kwargs
188
+ )
183
189
self .assertTrue (type (auth_provider ).__name__ , "CredentialProvider" )
184
190
185
191
def test_get_python_sql_connector_basic_auth (self ):
@@ -189,7 +195,9 @@ def test_get_python_sql_connector_basic_auth(self):
189
195
}
190
196
mock_http_client = MagicMock ()
191
197
with self .assertRaises (ValueError ) as e :
192
- get_python_sql_connector_auth_provider ("foo.cloud.databricks.com" , mock_http_client , ** kwargs )
198
+ get_python_sql_connector_auth_provider (
199
+ "foo.cloud.databricks.com" , mock_http_client , ** kwargs
200
+ )
193
201
self .assertIn (
194
202
"Username/password authentication is no longer supported" , str (e .exception )
195
203
)
@@ -198,7 +206,9 @@ def test_get_python_sql_connector_basic_auth(self):
198
206
def test_get_python_sql_connector_default_auth (self , mock__initial_get_token ):
199
207
hostname = "foo.cloud.databricks.com"
200
208
mock_http_client = MagicMock ()
201
- auth_provider = get_python_sql_connector_auth_provider (hostname , mock_http_client )
209
+ auth_provider = get_python_sql_connector_auth_provider (
210
+ hostname , mock_http_client
211
+ )
202
212
self .assertTrue (type (auth_provider ).__name__ , "DatabricksOAuthProvider" )
203
213
self .assertTrue (auth_provider ._client_id , PYSQL_OAUTH_CLIENT_ID )
204
214
@@ -259,16 +269,16 @@ def test_no_token_refresh__when_token_is_not_expired(
259
269
260
270
def test_get_token_success (self , token_source , http_response ):
261
271
mock_http_client = MagicMock ()
262
-
272
+
263
273
with patch .object (token_source , "_http_client" , mock_http_client ):
264
274
# Create a mock response with the expected format
265
275
mock_response = MagicMock ()
266
276
mock_response .status = 200
267
277
mock_response .data .decode .return_value = '{"access_token": "abc123", "token_type": "Bearer", "refresh_token": null}'
268
-
278
+
269
279
# Mock the request method to return the response directly
270
280
mock_http_client .request .return_value = mock_response
271
-
281
+
272
282
token = token_source .get_token ()
273
283
274
284
# Assert
@@ -279,16 +289,16 @@ def test_get_token_success(self, token_source, http_response):
279
289
280
290
def test_get_token_failure (self , token_source , http_response ):
281
291
mock_http_client = MagicMock ()
282
-
292
+
283
293
with patch .object (token_source , "_http_client" , mock_http_client ):
284
294
# Create a mock response with error
285
295
mock_response = MagicMock ()
286
296
mock_response .status = 400
287
297
mock_response .data .decode .return_value = "Bad Request"
288
-
298
+
289
299
# Mock the request method to return the response directly
290
300
mock_http_client .request .return_value = mock_response
291
-
301
+
292
302
with pytest .raises (Exception ) as e :
293
303
token_source .get_token ()
294
304
assert "Failed to get token: 400" in str (e .value )
0 commit comments