mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: Provide location config for BigQuery tools
Right now the tolls are always running against multi-region US by default. With this change the agent builder can scope the tools to data and compute in a particular BigQuery location. PiperOrigin-RevId: 806473857
This commit is contained in:
committed by
Copybara-Service
parent
b3b31a9ffb
commit
4c00b86e33
@@ -23,8 +23,8 @@ from google.auth.exceptions import DefaultCredentialsError
|
||||
from google.oauth2.credentials import Credentials
|
||||
|
||||
|
||||
def test_bigquery_client_project():
|
||||
"""Test BigQuery client project."""
|
||||
def test_bigquery_client_default():
|
||||
"""Test the default BigQuery client properties."""
|
||||
# Trigger the BigQuery client creation
|
||||
client = get_bigquery_client(
|
||||
project="test-gcp-project",
|
||||
@@ -33,6 +33,7 @@ def test_bigquery_client_project():
|
||||
|
||||
# Verify that the client has the desired project set
|
||||
assert client.project == "test-gcp-project"
|
||||
assert client.location is None
|
||||
|
||||
|
||||
def test_bigquery_client_project_set_explicit():
|
||||
@@ -153,3 +154,17 @@ def test_bigquery_client_user_agent_custom():
|
||||
}
|
||||
actual_user_agents = set(client_info_arg.user_agent.split())
|
||||
assert expected_user_agents.issubset(actual_user_agents)
|
||||
|
||||
|
||||
def test_bigquery_client_location_custom():
|
||||
"""Test BigQuery client custom location."""
|
||||
# Trigger the BigQuery client creation
|
||||
client = get_bigquery_client(
|
||||
project="test-gcp-project",
|
||||
credentials=mock.create_autospec(Credentials, instance=True),
|
||||
location="us-central1",
|
||||
)
|
||||
|
||||
# Verify that the client has the desired project set
|
||||
assert client.project == "test-gcp-project"
|
||||
assert client.location == "us-central1"
|
||||
|
||||
@@ -148,7 +148,7 @@ def test_list_dataset_ids_bq_client_creation(mock_get_bigquery_client):
|
||||
|
||||
metadata_tool.list_dataset_ids(bq_project, bq_credentials, tool_settings)
|
||||
mock_get_bigquery_client.assert_called_once()
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 3
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 4
|
||||
assert mock_get_bigquery_client.call_args.kwargs["project"] == bq_project
|
||||
assert (
|
||||
mock_get_bigquery_client.call_args.kwargs["credentials"] == bq_credentials
|
||||
@@ -174,7 +174,7 @@ def test_get_dataset_info_bq_client_creation(mock_get_bigquery_client):
|
||||
bq_project, bq_dataset, bq_credentials, tool_settings
|
||||
)
|
||||
mock_get_bigquery_client.assert_called_once()
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 3
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 4
|
||||
assert mock_get_bigquery_client.call_args.kwargs["project"] == bq_project
|
||||
assert (
|
||||
mock_get_bigquery_client.call_args.kwargs["credentials"] == bq_credentials
|
||||
@@ -200,7 +200,7 @@ def test_list_table_ids_bq_client_creation(mock_get_bigquery_client):
|
||||
bq_project, bq_dataset, bq_credentials, tool_settings
|
||||
)
|
||||
mock_get_bigquery_client.assert_called_once()
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 3
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 4
|
||||
assert mock_get_bigquery_client.call_args.kwargs["project"] == bq_project
|
||||
assert (
|
||||
mock_get_bigquery_client.call_args.kwargs["credentials"] == bq_credentials
|
||||
@@ -227,7 +227,7 @@ def test_get_table_info_bq_client_creation(mock_get_bigquery_client):
|
||||
bq_project, bq_dataset, bq_table, bq_credentials, tool_settings
|
||||
)
|
||||
mock_get_bigquery_client.assert_called_once()
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 3
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 4
|
||||
assert mock_get_bigquery_client.call_args.kwargs["project"] == bq_project
|
||||
assert (
|
||||
mock_get_bigquery_client.call_args.kwargs["credentials"] == bq_credentials
|
||||
|
||||
@@ -1000,7 +1000,7 @@ def test_execute_sql_bq_client_creation(mock_get_bigquery_client):
|
||||
|
||||
execute_sql(project, query, credentials, tool_settings, tool_context)
|
||||
mock_get_bigquery_client.assert_called_once()
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 3
|
||||
assert len(mock_get_bigquery_client.call_args.kwargs) == 4
|
||||
assert mock_get_bigquery_client.call_args.kwargs["project"] == project
|
||||
assert mock_get_bigquery_client.call_args.kwargs["credentials"] == credentials
|
||||
assert (
|
||||
|
||||
Reference in New Issue
Block a user