File tree Expand file tree Collapse file tree
tests/unittests/tools/bigquery Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626from google .auth .transport .requests import Request
2727import google .oauth2 .credentials
2828from pydantic import BaseModel
29+ from pydantic import ConfigDict
2930from pydantic import model_validator
3031
3132from ..auth .auth_credential import AuthCredential
@@ -44,8 +45,7 @@ class BaseGoogleCredentialsConfig(BaseModel):
4445 """
4546
4647 # Configure the model to allow arbitrary types like Credentials
47- model_config = {"arbitrary_types_allowed" : True }
48-
48+ model_config = ConfigDict (arbitrary_types_allowed = True , extra = "forbid" )
4949 credentials : Optional [google .auth .credentials .Credentials ] = None
5050 """The existing auth credentials to use. If set, this credential will be used
5151 for every end user, end users don't need to be involved in the oauthflow. This
Original file line number Diff line number Diff line change 1818from typing import Optional
1919
2020from pydantic import BaseModel
21+ from pydantic import ConfigDict
2122from pydantic import field_validator
2223
2324from ...utils .feature_decorator import experimental
@@ -50,6 +51,9 @@ class WriteMode(Enum):
5051class BigQueryToolConfig (BaseModel ):
5152 """Configuration for BigQuery tools."""
5253
54+ # Forbid any fields not defined in the model
55+ model_config = ConfigDict (extra = 'forbid' )
56+
5357 write_mode : WriteMode = WriteMode .BLOCKED
5458 """Write mode for BigQuery tools.
5559
Original file line number Diff line number Diff line change 1414
1515from unittest import mock
1616
17- from google .adk .tools .bigquery . bigquery_credentials import BigQueryCredentialsConfig
17+ from google .adk .tools .bigquery import BigQueryCredentialsConfig
1818# Mock the Google OAuth and API dependencies
1919import google .auth .credentials
2020import google .oauth2 .credentials
@@ -171,3 +171,12 @@ def test_empty_configuration_raises_error(self):
171171 ),
172172 ):
173173 BigQueryCredentialsConfig ()
174+
175+ def test_invalid_property_raises_error (self ):
176+ """Test BigQueryCredentialsConfig raises exception when setting invalid property."""
177+ with pytest .raises (ValueError ):
178+ BigQueryCredentialsConfig (
179+ client_id = "test_client_id" ,
180+ client_secret = "test_client_secret" ,
181+ non_existent_field = "some value" ,
182+ )
Original file line number Diff line number Diff line change @@ -27,8 +27,16 @@ def test_bigquery_tool_config_experimental_warning():
2727 BigQueryToolConfig ()
2828
2929
30+ def test_bigquery_tool_config_invalid_property ():
31+ """Test BigQueryToolConfig raises exception when setting invalid property."""
32+ with pytest .raises (
33+ ValueError ,
34+ ):
35+ BigQueryToolConfig (non_existent_field = "some value" )
36+
37+
3038def test_bigquery_tool_config_invalid_application_name ():
31- """Test BigQueryToolConfig with invalid application name."""
39+ """Test BigQueryToolConfig raises exception with invalid application name."""
3240 with pytest .raises (
3341 ValueError ,
3442 match = "Application name should not contain spaces." ,
You can’t perform that action at this time.
0 commit comments