Skip to content

Commit 2cc2066

Browse files
committed
fix tests
1 parent 5974383 commit 2cc2066

4 files changed

Lines changed: 16 additions & 49 deletions

File tree

generated/provider_dependencies.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@
555555
"apache-airflow-providers-common-compat>=1.14.1",
556556
"apache-airflow-providers-standard>=1.12.1",
557557
"apache-airflow>=3.0.0",
558-
"pydantic-ai-slim>=1.71.0"
558+
"pydantic-ai-slim>=1.96.0"
559559
],
560560
"devel-deps": [
561561
"langchain>=1.0.0",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
86e39c620f3926c99e1c702a496d6161032e1a3ac69eba7da10214a2c4ba24f1
1+
507d80ebe713a42b294363cf05e50b01c0727a7e384056e4b8b23d5102bd11b5

providers/common/ai/src/airflow/providers/common/ai/toolsets/sql.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ def _is_table_allowed(self, name: str) -> bool:
183183
def id(self) -> str:
184184
return f"sql-{self._db_conn_id}"
185185

186-
187186
# ------------------------------------------------------------------
188187
# Lazy hook resolution
189188
# ------------------------------------------------------------------

providers/common/ai/tests/unit/common/ai/toolsets/test_sql.py

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,15 @@ def test_list_tables_spans_multiple_schemas(self):
367367
}
368368
)
369369

370-
result = json.loads(asyncio.run(ts.call_tool("list_tables", {}, ctx=MagicMock(), tool=MagicMock())))
370+
result = json.loads(ts._list_tables())
371371
assert result == ["MODEL_ASTRO.DEPLOYMENT_IMAGE_DETAILS", "MODEL_CRM.SF_ASTRO_ORGS"]
372372

373373
def test_list_tables_never_introspects_none_schema_when_all_qualified(self):
374374
"""Regression for the 'SHOW TABLES IN SCHEMA "DB"."None"' failure."""
375375
ts = SQLToolset("sf", allowed_tables=["MODEL_ASTRO.X", "MODEL_CRM.Y"])
376376
ts._hook = self._schema_aware_hook({"MODEL_ASTRO": ["X"], "MODEL_CRM": ["Y"]})
377377

378-
asyncio.run(ts.call_tool("list_tables", {}, ctx=MagicMock(), tool=MagicMock()))
378+
ts._list_tables()
379379

380380
called_schemas = {c.kwargs.get("schema") for c in ts._hook.inspector.get_table_names.call_args_list}
381381
assert called_schemas == {"MODEL_ASTRO", "MODEL_CRM"}
@@ -385,46 +385,31 @@ def test_list_tables_mixed_qualified_and_default(self):
385385
ts = SQLToolset("pg", allowed_tables=["users", "MODEL_ASTRO.X"], schema="public")
386386
ts._hook = self._schema_aware_hook({"public": ["users", "orders"], "MODEL_ASTRO": ["X", "Z"]})
387387

388-
result = json.loads(asyncio.run(ts.call_tool("list_tables", {}, ctx=MagicMock(), tool=MagicMock())))
388+
result = json.loads(ts._list_tables())
389389
# Qualified schemas listed first (sorted), then the default schema.
390390
assert result == ["MODEL_ASTRO.X", "users"]
391391

392392
def test_get_schema_routes_to_qualified_schema(self):
393393
ts = SQLToolset("sf", allowed_tables=["MODEL_ASTRO.DEPLOYMENT_IMAGE_DETAILS"])
394394
ts._hook = self._schema_aware_hook({"MODEL_ASTRO": ["DEPLOYMENT_IMAGE_DETAILS"]})
395395

396-
result = json.loads(
397-
asyncio.run(
398-
ts.call_tool(
399-
"get_schema",
400-
{"table_name": "MODEL_ASTRO.DEPLOYMENT_IMAGE_DETAILS"},
401-
ctx=MagicMock(),
402-
tool=MagicMock(),
403-
)
404-
)
405-
)
396+
result = json.loads(ts._get_schema("MODEL_ASTRO.DEPLOYMENT_IMAGE_DETAILS"))
406397
assert result == [{"name": "id", "type": "INTEGER"}]
407398
ts._hook.get_table_schema.assert_called_once_with("DEPLOYMENT_IMAGE_DETAILS", schema="MODEL_ASTRO")
408399

409400
def test_get_schema_blocks_table_outside_allowed_schema(self):
410401
ts = SQLToolset("sf", allowed_tables=["MODEL_ASTRO.X"])
411402
ts._hook = self._schema_aware_hook({"MODEL_ASTRO": ["X"]})
412403

413-
result = json.loads(
414-
asyncio.run(
415-
ts.call_tool(
416-
"get_schema", {"table_name": "SECRETS.PASSWORDS"}, ctx=MagicMock(), tool=MagicMock()
417-
)
418-
)
419-
)
404+
result = json.loads(ts._get_schema("SECRETS.PASSWORDS"))
420405
assert "error" in result
421406
ts._hook.get_table_schema.assert_not_called()
422407

423408
def test_get_schema_unqualified_uses_default_schema(self):
424409
ts = SQLToolset("pg", schema="public")
425410
ts._hook = self._schema_aware_hook({"public": ["users"]})
426411

427-
asyncio.run(ts.call_tool("get_schema", {"table_name": "users"}, ctx=MagicMock(), tool=MagicMock()))
412+
ts._get_schema("users")
428413
ts._hook.get_table_schema.assert_called_once_with("users", schema="public")
429414

430415
def test_list_tables_matches_case_insensitively(self):
@@ -440,23 +425,14 @@ def test_list_tables_matches_case_insensitively(self):
440425
}
441426
)
442427

443-
result = json.loads(asyncio.run(ts.call_tool("list_tables", {}, ctx=MagicMock(), tool=MagicMock())))
428+
result = json.loads(ts._list_tables())
444429
assert result == ["MODEL_ASTRO.deployment_image_details", "MODEL_CRM.sf_astro_orgs"]
445430

446431
def test_get_schema_matches_case_insensitively(self):
447432
ts = SQLToolset("sf", allowed_tables=["MODEL_ASTRO.DEPLOYMENT_IMAGE_DETAILS"])
448433
ts._hook = self._schema_aware_hook({"MODEL_ASTRO": ["deployment_image_details"]})
449434

450-
result = json.loads(
451-
asyncio.run(
452-
ts.call_tool(
453-
"get_schema",
454-
{"table_name": "MODEL_ASTRO.deployment_image_details"},
455-
ctx=MagicMock(),
456-
tool=MagicMock(),
457-
)
458-
)
459-
)
435+
result = json.loads(ts._get_schema("MODEL_ASTRO.deployment_image_details"))
460436
assert "error" not in result
461437
ts._hook.get_table_schema.assert_called_once_with("deployment_image_details", schema="MODEL_ASTRO")
462438

@@ -465,7 +441,7 @@ def test_list_tables_deduplicates_same_table(self):
465441
ts = SQLToolset("pg", allowed_tables=["public.users", "users"], schema="public")
466442
ts._hook = self._schema_aware_hook({"public": ["users"]})
467443

468-
result = json.loads(asyncio.run(ts.call_tool("list_tables", {}, ctx=MagicMock(), tool=MagicMock())))
444+
result = json.loads(ts._list_tables())
469445
assert result == ["public.users"]
470446

471447

@@ -480,10 +456,7 @@ def test_describe_allowed_through_query(self):
480456
last_description=[("column_name",), ("data_type",)],
481457
)
482458

483-
result = asyncio.run(
484-
ts.call_tool("query", {"sql": "DESCRIBE TABLE users"}, ctx=MagicMock(), tool=MagicMock())
485-
)
486-
data = json.loads(result)
459+
data = json.loads(ts._query("DESCRIBE TABLE users"))
487460
assert "rows" in data
488461
ts._hook.get_records.assert_called_once_with("DESCRIBE TABLE users")
489462

@@ -493,8 +466,7 @@ def test_show_allowed_with_snowflake_dialect(self):
493466
ts._hook = _make_mock_db_hook(records=[("USERS",)], last_description=[("name",)])
494467
ts._hook.dialect_name = "snowflake"
495468

496-
result = asyncio.run(ts.call_tool("query", {"sql": "SHOW TABLES"}, ctx=MagicMock(), tool=MagicMock()))
497-
data = json.loads(result)
469+
data = json.loads(ts._query("SHOW TABLES"))
498470
assert "rows" in data
499471
ts._hook.get_records.assert_called_once_with("SHOW TABLES")
500472

@@ -510,22 +482,18 @@ def test_query_blocks_disallowed_statements(self, sql):
510482
ts._hook.dialect_name = "postgresql"
511483

512484
with pytest.raises(SQLSafetyError, match="not allowed"):
513-
asyncio.run(ts.call_tool("query", {"sql": sql}, ctx=MagicMock(), tool=MagicMock()))
485+
ts._query(sql)
514486

515487
def test_check_query_accepts_describe(self):
516488
ts = SQLToolset("pg_default")
517489
ts._hook = _make_mock_db_hook()
518490

519-
result = asyncio.run(
520-
ts.call_tool("check_query", {"sql": "DESCRIBE TABLE users"}, ctx=MagicMock(), tool=MagicMock())
521-
)
491+
result = ts._check_query("DESCRIBE TABLE users")
522492
assert json.loads(result)["valid"] is True
523493

524494
def test_check_query_handles_unresolvable_connection(self):
525495
"""check_query stays usable (dialect-agnostic) when the connection can't be resolved."""
526496
ts = SQLToolset("missing_conn")
527497
with patch.object(ts, "_get_db_hook", side_effect=RuntimeError("no such connection")):
528-
result = asyncio.run(
529-
ts.call_tool("check_query", {"sql": "SELECT 1"}, ctx=MagicMock(), tool=MagicMock())
530-
)
498+
result = ts._check_query("SELECT 1")
531499
assert json.loads(result)["valid"] is True

0 commit comments

Comments
 (0)