2727class TestVeIdentityFunctionToolInit :
2828 """Tests for VeIdentityFunctionTool initialization."""
2929
30- @patch (' veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
30+ @patch (" veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
3131 def test_init_with_api_key_auth (self , mock_identity_client ):
3232 """Test initializing with API key auth config."""
33+
3334 async def test_func (api_key : str ):
3435 return f"Called with { api_key } "
3536
@@ -41,26 +42,24 @@ async def test_func(api_key: str):
4142 assert tool ._auth_config == config
4243 assert tool ._into == "api_key"
4344
44- @patch (' veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
45+ @patch (" veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
4546 def test_init_with_oauth2_auth (self , mock_identity_client ):
4647 """Test initializing with OAuth2 auth config."""
48+
4749 async def test_func (access_token : str ):
4850 return f"Called with { access_token } "
4951
50- config = oauth2_auth (
51- provider_name = "github" ,
52- scopes = ["repo" ],
53- auth_flow = "M2M"
54- )
52+ config = oauth2_auth (provider_name = "github" , scopes = ["repo" ], auth_flow = "M2M" )
5553 tool = VeIdentityFunctionTool (func = test_func , auth_config = config )
5654
5755 assert tool .func == test_func
5856 assert tool ._auth_config == config
5957 assert tool ._into == "access_token"
6058
61- @patch (' veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
59+ @patch (" veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
6260 def test_init_with_workload_auth (self , mock_identity_client ):
6361 """Test initializing with workload auth config."""
62+
6463 async def test_func (access_token : str ):
6564 return f"Called with { access_token } "
6665
@@ -71,23 +70,23 @@ async def test_func(access_token: str):
7170 assert tool ._auth_config == config
7271 assert tool ._into == "access_token"
7372
74- @patch (' veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
73+ @patch (" veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
7574 def test_init_with_custom_into_parameter (self , mock_identity_client ):
7675 """Test initializing with custom 'into' parameter."""
76+
7777 async def test_func (custom_token : str ):
7878 return f"Called with { custom_token } "
7979
8080 config = api_key_auth ("test-provider" )
8181 tool = VeIdentityFunctionTool (
82- func = test_func ,
83- auth_config = config ,
84- into = "custom_token"
82+ func = test_func , auth_config = config , into = "custom_token"
8583 )
8684
8785 assert tool ._into == "custom_token"
8886
8987 def test_init_with_unsupported_auth_config (self ):
9088 """Test that unsupported auth config raises ValueError."""
89+
9190 async def test_func (token : str ):
9291 return f"Called with { token } "
9392
@@ -103,9 +102,10 @@ class TestVeIdentityFunctionToolRunAsync:
103102 """Tests for VeIdentityFunctionTool.run_async method."""
104103
105104 @pytest .mark .asyncio
106- @patch (' veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
105+ @patch (" veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
107106 async def test_run_async_with_api_key (self , mock_identity_client ):
108107 """Test run_async with API key authentication."""
108+
109109 async def test_func (api_key : str ):
110110 return f"Result: { api_key } "
111111
@@ -122,17 +122,14 @@ async def test_func(api_key: str):
122122 tool .run_with_identity_auth .assert_called_once ()
123123
124124 @pytest .mark .asyncio
125- @patch (' veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
125+ @patch (" veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
126126 async def test_run_async_with_oauth2 (self , mock_identity_client ):
127127 """Test run_async with OAuth2 authentication."""
128+
128129 async def test_func (access_token : str ):
129130 return f"Result: { access_token } "
130131
131- config = oauth2_auth (
132- provider_name = "github" ,
133- scopes = ["repo" ],
134- auth_flow = "M2M"
135- )
132+ config = oauth2_auth (provider_name = "github" , scopes = ["repo" ], auth_flow = "M2M" )
136133 tool = VeIdentityFunctionTool (func = test_func , auth_config = config )
137134
138135 # Mock the run_with_identity_auth method
@@ -145,18 +142,18 @@ async def test_func(access_token: str):
145142 tool .run_with_identity_auth .assert_called_once ()
146143
147144 @pytest .mark .asyncio
148- @patch ('veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
149- async def test_run_async_handles_auth_required_exception (self , mock_identity_client ):
145+ @patch ("veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
146+ async def test_run_async_handles_auth_required_exception (
147+ self , mock_identity_client
148+ ):
150149 """Test that run_async handles AuthRequiredException."""
151150 from veadk .integrations .ve_identity .auth_mixins import AuthRequiredException
152151
153152 async def test_func (access_token : str ):
154153 return f"Result: { access_token } "
155154
156155 config = oauth2_auth (
157- provider_name = "github" ,
158- scopes = ["repo" ],
159- auth_flow = "USER_FEDERATION"
156+ provider_name = "github" , scopes = ["repo" ], auth_flow = "USER_FEDERATION"
160157 )
161158 tool = VeIdentityFunctionTool (func = test_func , auth_config = config )
162159
@@ -174,9 +171,10 @@ class TestVeIdentityFunctionToolExecuteWithCredential:
174171 """Tests for VeIdentityFunctionTool._execute_with_credential method."""
175172
176173 @pytest .mark .asyncio
177- @patch (' veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
174+ @patch (" veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
178175 async def test_execute_with_credential_injects_api_key (self , mock_identity_client ):
179176 """Test that _execute_with_credential injects API key."""
177+
180178 async def test_func (api_key : str ):
181179 return f"Result: { api_key } "
182180
@@ -188,32 +186,31 @@ async def test_func(api_key: str):
188186 credential .api_key = "test-api-key"
189187
190188 # Mock parent's run_async
191- with patch .object (tool .__class__ .__bases__ [1 ], 'run_async' , new_callable = AsyncMock ) as mock_run :
189+ with patch .object (
190+ tool .__class__ .__bases__ [1 ], "run_async" , new_callable = AsyncMock
191+ ) as mock_run :
192192 mock_run .return_value = "Result: test-api-key"
193193
194194 tool_context = Mock ()
195- result = await tool ._execute_with_credential (
196- args = {},
197- tool_context = tool_context ,
198- credential = credential
195+ await tool ._execute_with_credential (
196+ args = {}, tool_context = tool_context , credential = credential
199197 )
200198
201199 # Verify that run_async was called with injected api_key
202200 call_args = mock_run .call_args
203- assert call_args [1 ][' args' ][ ' api_key' ] == "test-api-key"
201+ assert call_args [1 ][" args" ][ " api_key" ] == "test-api-key"
204202
205203 @pytest .mark .asyncio
206- @patch ('veadk.integrations.ve_identity.auth_mixins.IdentityClient' )
207- async def test_execute_with_credential_injects_oauth2_token (self , mock_identity_client ):
204+ @patch ("veadk.integrations.ve_identity.auth_mixins.IdentityClient" )
205+ async def test_execute_with_credential_injects_oauth2_token (
206+ self , mock_identity_client
207+ ):
208208 """Test that _execute_with_credential injects OAuth2 access token."""
209+
209210 async def test_func (access_token : str ):
210211 return f"Result: { access_token } "
211212
212- config = oauth2_auth (
213- provider_name = "github" ,
214- scopes = ["repo" ],
215- auth_flow = "M2M"
216- )
213+ config = oauth2_auth (provider_name = "github" , scopes = ["repo" ], auth_flow = "M2M" )
217214 tool = VeIdentityFunctionTool (func = test_func , auth_config = config )
218215
219216 # Mock credential
@@ -222,17 +219,16 @@ async def test_func(access_token: str):
222219 credential .oauth2 .access_token = "test-oauth2-token"
223220
224221 # Mock parent's run_async
225- with patch .object (tool .__class__ .__bases__ [1 ], 'run_async' , new_callable = AsyncMock ) as mock_run :
222+ with patch .object (
223+ tool .__class__ .__bases__ [1 ], "run_async" , new_callable = AsyncMock
224+ ) as mock_run :
226225 mock_run .return_value = "Result: test-oauth2-token"
227226
228227 tool_context = Mock ()
229- result = await tool ._execute_with_credential (
230- args = {},
231- tool_context = tool_context ,
232- credential = credential
228+ await tool ._execute_with_credential (
229+ args = {}, tool_context = tool_context , credential = credential
233230 )
234231
235232 # Verify that run_async was called with injected access_token
236233 call_args = mock_run .call_args
237- assert call_args [1 ]['args' ]['access_token' ] == "test-oauth2-token"
238-
234+ assert call_args [1 ]["args" ]["access_token" ] == "test-oauth2-token"
0 commit comments