|
33 | 33 | from google.adk.a2a.converters.event_converter import convert_event_to_a2a_events |
34 | 34 | from google.adk.a2a.converters.event_converter import convert_event_to_a2a_message |
35 | 35 | from google.adk.a2a.converters.event_converter import DEFAULT_ERROR_MESSAGE |
| 36 | +from google.adk.a2a.converters.part_converter import convert_genai_part_to_a2a_part |
36 | 37 | from google.adk.a2a.converters.utils import ADK_METADATA_KEY_PREFIX |
37 | 38 | from google.adk.agents.invocation_context import InvocationContext |
38 | 39 | from google.adk.events.event import Event |
@@ -438,6 +439,42 @@ def test_convert_event_to_a2a_events_with_custom_ids(self): |
438 | 439 | context_id, |
439 | 440 | ) |
440 | 441 |
|
| 442 | + def test_convert_event_to_a2a_events_user_role(self): |
| 443 | + """Test event to A2A events conversion with events from a user.""" |
| 444 | + # Setup message |
| 445 | + mock_message = Mock(spec=Message) |
| 446 | + mock_message.parts = [] |
| 447 | + |
| 448 | + with patch( |
| 449 | + "google.adk.a2a.converters.event_converter.convert_event_to_a2a_message" |
| 450 | + ) as mock_convert_message: |
| 451 | + mock_convert_message.return_value = mock_message |
| 452 | + |
| 453 | + with patch( |
| 454 | + "google.adk.a2a.converters.event_converter._create_status_update_event" |
| 455 | + ) as mock_create_running: |
| 456 | + mock_running_event = Mock() |
| 457 | + mock_create_running.return_value = mock_running_event |
| 458 | + self.mock_event.author = "user" |
| 459 | + |
| 460 | + task_id = "custom-task-id" |
| 461 | + context_id = "custom-context-id" |
| 462 | + |
| 463 | + result = convert_event_to_a2a_events( |
| 464 | + self.mock_event, self.mock_invocation_context, task_id, context_id |
| 465 | + ) |
| 466 | + |
| 467 | + assert len(result) == 1 |
| 468 | + assert result[0] == mock_running_event |
| 469 | + |
| 470 | + # Verify the function is called with the specific task_id and context_id |
| 471 | + mock_convert_message.assert_called_once_with( |
| 472 | + self.mock_event, |
| 473 | + self.mock_invocation_context, |
| 474 | + part_converter=convert_genai_part_to_a2a_part, |
| 475 | + role=Role.user, |
| 476 | + ) |
| 477 | + |
441 | 478 | def test_create_status_update_event_with_auth_required_state(self): |
442 | 479 | """Test creation of status update event with auth_required state.""" |
443 | 480 | from a2a.types import DataPart |
|
0 commit comments