adk-python/tests/unittests/agents/test_readonly_context.py
Thiago Neves ac97fc638f fix(tests): use mock GCS client in artifact service tests to avoid real credentials
Copybara import of the project:

--
ade1d98e030a966183f56cb5c9c1b04cf51f5337 by Thiago Neves <thiagohneves@gmail.com>:

fix(tests): use mock GCS client in artifact service tests to avoid real credentials

--
becd2925feebf60196129b029a0ab8d490f7b19e by Thiago Neves <thiagohneves@gmail.com>:

test(agents): add unit tests for live_request_queue, readonly_context, and run_config

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/641 from thiagoneves:feature/increase-test-coverage 0f7a9fc55d97902e190a394f099324fbeb1541af
PiperOrigin-RevId: 756798390
2025-05-09 09:33:40 -07:00

34 lines
1022 B
Python

import pytest
from unittest.mock import MagicMock
from types import MappingProxyType
from google.adk.agents.readonly_context import ReadonlyContext
@pytest.fixture
def mock_invocation_context():
mock_context = MagicMock()
mock_context.invocation_id = "test-invocation-id"
mock_context.agent.name = "test-agent-name"
mock_context.session.state = {"key1": "value1", "key2": "value2"}
return mock_context
def test_invocation_id(mock_invocation_context):
readonly_context = ReadonlyContext(mock_invocation_context)
assert readonly_context.invocation_id == "test-invocation-id"
def test_agent_name(mock_invocation_context):
readonly_context = ReadonlyContext(mock_invocation_context)
assert readonly_context.agent_name == "test-agent-name"
def test_state_content(mock_invocation_context):
readonly_context = ReadonlyContext(mock_invocation_context)
state = readonly_context.state
assert isinstance(state, MappingProxyType)
assert state["key1"] == "value1"
assert state["key2"] == "value2"