File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 23
23
from google .genai import types
24
24
25
25
from .invocation_context import InvocationContext
26
+ from ..auth .credential_service .base_credential_service import BaseCredentialService
26
27
27
28
28
29
class ReadonlyContext :
@@ -52,3 +53,8 @@ def agent_name(self) -> str:
52
53
def state (self ) -> MappingProxyType [str , Any ]:
53
54
"""The state of the current session. READONLY field."""
54
55
return MappingProxyType (self ._invocation_context .session .state )
56
+
57
+ @property
58
+ def credential_service (self ) -> Optional [BaseCredentialService ]:
59
+ """The credential service for the current invocation."""
60
+ return self ._invocation_context .credential_service
Original file line number Diff line number Diff line change 2
2
from unittest .mock import MagicMock
3
3
4
4
from google .adk .agents .readonly_context import ReadonlyContext
5
+ from google .adk .auth .credential_service .base_credential_service import BaseCredentialService
5
6
import pytest
6
7
7
8
9
+ class DummyCredentialService (BaseCredentialService ):
10
+ async def load_credential (self ,auth_config , tool_context ):
11
+ pass
12
+
13
+ async def save_credential (self ,auth_config , tool_context ):
14
+ pass
15
+
16
+
8
17
@pytest .fixture
9
18
def mock_invocation_context ():
10
19
mock_context = MagicMock ()
11
20
mock_context .invocation_id = "test-invocation-id"
12
21
mock_context .agent .name = "test-agent-name"
13
22
mock_context .session .state = {"key1" : "value1" , "key2" : "value2" }
23
+ mock_context .credential_service = DummyCredentialService ()
14
24
15
25
return mock_context
16
26
@@ -32,3 +42,9 @@ def test_state_content(mock_invocation_context):
32
42
assert isinstance (state , MappingProxyType )
33
43
assert state ["key1" ] == "value1"
34
44
assert state ["key2" ] == "value2"
45
+
46
+
47
+ def test_credential_service (mock_invocation_context ):
48
+ readonly_context = ReadonlyContext (mock_invocation_context )
49
+ assert readonly_context .credential_service is not None
50
+ assert isinstance (readonly_context .credential_service , BaseCredentialService )
You can’t perform that action at this time.
0 commit comments