@@ -309,3 +309,70 @@ def call_get_conn():
309
309
future .result () # This will raise OSError if get_conn isn't threadsafe
310
310
311
311
assert mock_connect .call_count == 10
312
+
313
+ @pytest .mark .parametrize (
314
+ "params,expected_uri" ,
315
+ [
316
+ # JDBC URL fallback cases
317
+ pytest .param (
318
+ {"host" : "jdbc:mysql://localhost:3306/test" },
319
+ "jdbc:mysql://localhost:3306/test" ,
320
+ id = "jdbc-mysql" ,
321
+ ),
322
+ pytest .param (
323
+ {"host" : "jdbc:postgresql://localhost:5432/test?user=user&password=pass%40word" },
324
+ "jdbc:postgresql://localhost:5432/test?user=user&password=pass%40word" ,
325
+ id = "jdbc-postgresql" ,
326
+ ),
327
+ pytest .param (
328
+ {"host" : "jdbc:oracle:thin:@localhost:1521:xe" },
329
+ "jdbc:oracle:thin:@localhost:1521:xe" ,
330
+ id = "jdbc-oracle" ,
331
+ ),
332
+ pytest .param (
333
+ {"host" : "jdbc:sqlserver://localhost:1433;databaseName=test;trustServerCertificate=true" },
334
+ "jdbc:sqlserver://localhost:1433;databaseName=test;trustServerCertificate=true" ,
335
+ id = "jdbc-sqlserver" ,
336
+ ),
337
+ # SQLAlchemy URI cases
338
+ pytest .param (
339
+ {
340
+ "conn_params" : {
341
+ "extra" : json .dumps (
342
+ {"sqlalchemy_scheme" : "mssql" , "sqlalchemy_query" : {"servicename" : "test" }}
343
+ )
344
+ }
345
+ },
346
+ "mssql://login:password@host:1234/schema?servicename=test" ,
347
+ id = "sqlalchemy-scheme-with-query" ,
348
+ ),
349
+ pytest .param (
350
+ {
351
+ "conn_params" : {
352
+ "extra" : json .dumps (
353
+ {"sqlalchemy_scheme" : "postgresql" , "sqlalchemy_driver" : "psycopg2" }
354
+ )
355
+ }
356
+ },
357
+ "postgresql+psycopg2://login:password@host:1234/schema" ,
358
+ id = "sqlalchemy-scheme-with-driver" ,
359
+ ),
360
+ pytest .param (
361
+ {
362
+ "login" : "user@domain" ,
363
+ "password" : "pass/word" ,
364
+ "schema" : "my/db" ,
365
+ "conn_params" : {"extra" : json .dumps ({"sqlalchemy_scheme" : "mysql" })},
366
+ },
367
+ "mysql://user%40domain:pass%2Fword@host:1234/my%2Fdb" ,
368
+ id = "sqlalchemy-with-encoding" ,
369
+ ),
370
+ ],
371
+ )
372
+ def test_get_uri (self , params , expected_uri ):
373
+ """Test get_uri with different configurations including JDBC URLs and SQLAlchemy URIs."""
374
+ valid_keys = {"host" , "login" , "password" , "schema" , "conn_params" }
375
+ hook_params = {key : params [key ] for key in valid_keys & params .keys ()}
376
+
377
+ jdbc_hook = get_hook (** hook_params )
378
+ assert jdbc_hook .get_uri () == expected_uri
0 commit comments