Skip to content

Commit 65e5909

Browse files
committed
Address comments
1 parent d890972 commit 65e5909

File tree

1 file changed

+117
-18
lines changed

1 file changed

+117
-18
lines changed

tests/server/request_handlers/test_default_request_handler.py

Lines changed: 117 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ async def test_get_task_push_notification_config_info_not_found():
10431043
"""Test on_get_task_push_notification_config when push_config_store.get_info returns None."""
10441044
mock_task_store = AsyncMock(spec=TaskStore)
10451045

1046-
sample_task = create_sample_task(task_id='task_info_not_found')
1046+
sample_task = create_sample_task(task_id='non_existent_task')
10471047
mock_task_store.get.return_value = sample_task
10481048

10491049
mock_push_store = AsyncMock(spec=PushNotificationConfigStore)
@@ -1054,7 +1054,7 @@ async def test_get_task_push_notification_config_info_not_found():
10541054
task_store=mock_task_store,
10551055
push_config_store=mock_push_store,
10561056
)
1057-
params = GetTaskPushNotificationConfigParams(id='task_info_not_found')
1057+
params = GetTaskPushNotificationConfigParams(id='non_existent_task')
10581058
from a2a.utils.errors import ServerError # Local import
10591059

10601060
with pytest.raises(ServerError) as exc_info:
@@ -1065,8 +1065,90 @@ async def test_get_task_push_notification_config_info_not_found():
10651065
assert isinstance(
10661066
exc_info.value.error, InternalError
10671067
) # Current code raises InternalError
1068-
mock_task_store.get.assert_awaited_once_with('task_info_not_found')
1069-
mock_push_store.get_info.assert_awaited_once_with('task_info_not_found')
1068+
mock_task_store.get.assert_awaited_once_with('non_existent_task')
1069+
mock_push_store.get_info.assert_awaited_once_with('non_existent_task')
1070+
1071+
1072+
@pytest.mark.asyncio
1073+
async def test_get_task_push_notification_config_info_with_config():
1074+
"""Test on_get_task_push_notification_config with valid push config id"""
1075+
mock_task_store = AsyncMock(spec=TaskStore)
1076+
1077+
push_store = InMemoryPushNotificationConfigStore()
1078+
1079+
request_handler = DefaultRequestHandler(
1080+
agent_executor=DummyAgentExecutor(),
1081+
task_store=mock_task_store,
1082+
push_config_store=push_store,
1083+
)
1084+
1085+
set_config_params = TaskPushNotificationConfig(
1086+
taskId='task_1',
1087+
pushNotificationConfig=PushNotificationConfig(
1088+
id='config_id', url='http://1.example.com'
1089+
),
1090+
)
1091+
await request_handler.on_set_task_push_notification_config(
1092+
set_config_params, create_server_call_context()
1093+
)
1094+
1095+
params = GetTaskPushNotificationConfigParams(
1096+
id='task_1', pushNotificationConfigId='config_id'
1097+
)
1098+
1099+
result: TaskPushNotificationConfig = (
1100+
await request_handler.on_get_task_push_notification_config(
1101+
params, create_server_call_context()
1102+
)
1103+
)
1104+
1105+
assert result is not None
1106+
assert result.taskId == 'task_1'
1107+
assert (
1108+
result.pushNotificationConfig.url
1109+
== set_config_params.pushNotificationConfig.url
1110+
)
1111+
assert result.pushNotificationConfig.id == 'config_id'
1112+
1113+
1114+
@pytest.mark.asyncio
1115+
async def test_get_task_push_notification_config_info_with_config_no_id():
1116+
"""Test on_get_task_push_notification_config with no push config id"""
1117+
mock_task_store = AsyncMock(spec=TaskStore)
1118+
1119+
push_store = InMemoryPushNotificationConfigStore()
1120+
1121+
request_handler = DefaultRequestHandler(
1122+
agent_executor=DummyAgentExecutor(),
1123+
task_store=mock_task_store,
1124+
push_config_store=push_store,
1125+
)
1126+
1127+
set_config_params = TaskPushNotificationConfig(
1128+
taskId='task_1',
1129+
pushNotificationConfig=PushNotificationConfig(
1130+
url='http://1.example.com'
1131+
),
1132+
)
1133+
await request_handler.on_set_task_push_notification_config(
1134+
set_config_params, create_server_call_context()
1135+
)
1136+
1137+
params = TaskIdParams(id='task_1')
1138+
1139+
result: TaskPushNotificationConfig = (
1140+
await request_handler.on_get_task_push_notification_config(
1141+
params, create_server_call_context()
1142+
)
1143+
)
1144+
1145+
assert result is not None
1146+
assert result.taskId == 'task_1'
1147+
assert (
1148+
result.pushNotificationConfig.url
1149+
== set_config_params.pushNotificationConfig.url
1150+
)
1151+
assert result.pushNotificationConfig.id == 'task_1'
10701152

10711153

10721154
@pytest.mark.asyncio
@@ -1210,7 +1292,7 @@ async def test_list_no_task_push_notification_config_info():
12101292
"""Test on_get_task_push_notification_config when push_config_store.get_info returns []"""
12111293
mock_task_store = AsyncMock(spec=TaskStore)
12121294

1213-
sample_task = create_sample_task(task_id='task_info_not_found')
1295+
sample_task = create_sample_task(task_id='non_existent_task')
12141296
mock_task_store.get.return_value = sample_task
12151297

12161298
push_store = InMemoryPushNotificationConfigStore()
@@ -1220,7 +1302,7 @@ async def test_list_no_task_push_notification_config_info():
12201302
task_store=mock_task_store,
12211303
push_config_store=push_store,
12221304
)
1223-
params = ListTaskPushNotificationConfigParams(id='task_info_not_found')
1305+
params = ListTaskPushNotificationConfigParams(id='non_existent_task')
12241306

12251307
result = await request_handler.on_list_task_push_notification_config(
12261308
params, create_server_call_context()
@@ -1233,7 +1315,7 @@ async def test_list_task_push_notification_config_info_with_config():
12331315
"""Test on_list_task_push_notification_config with push config+id"""
12341316
mock_task_store = AsyncMock(spec=TaskStore)
12351317

1236-
sample_task = create_sample_task(task_id='task_info_not_found')
1318+
sample_task = create_sample_task(task_id='non_existent_task')
12371319
mock_task_store.get.return_value = sample_task
12381320

12391321
push_config1 = PushNotificationConfig(
@@ -1272,21 +1354,35 @@ async def test_list_task_push_notification_config_info_with_config_and_no_id():
12721354
"""Test on_list_task_push_notification_config with no push config id"""
12731355
mock_task_store = AsyncMock(spec=TaskStore)
12741356

1275-
sample_task = create_sample_task(task_id='task_info_not_found')
1276-
mock_task_store.get.return_value = sample_task
1277-
1278-
push_config = PushNotificationConfig(url='http://example.com')
1279-
1280-
# insertion without id should replace the existing config
12811357
push_store = InMemoryPushNotificationConfigStore()
1282-
await push_store.set_info('task_1', push_config)
1283-
await push_store.set_info('task_1', push_config)
12841358

12851359
request_handler = DefaultRequestHandler(
12861360
agent_executor=DummyAgentExecutor(),
12871361
task_store=mock_task_store,
12881362
push_config_store=push_store,
12891363
)
1364+
1365+
# multiple calls without config id should replace the existing
1366+
set_config_params1 = TaskPushNotificationConfig(
1367+
taskId='task_1',
1368+
pushNotificationConfig=PushNotificationConfig(
1369+
url='http://1.example.com'
1370+
),
1371+
)
1372+
await request_handler.on_set_task_push_notification_config(
1373+
set_config_params1, create_server_call_context()
1374+
)
1375+
1376+
set_config_params2 = TaskPushNotificationConfig(
1377+
taskId='task_1',
1378+
pushNotificationConfig=PushNotificationConfig(
1379+
url='http://2.example.com'
1380+
),
1381+
)
1382+
await request_handler.on_set_task_push_notification_config(
1383+
set_config_params2, create_server_call_context()
1384+
)
1385+
12901386
params = ListTaskPushNotificationConfigParams(id='task_1')
12911387

12921388
result: list[
@@ -1297,7 +1393,10 @@ async def test_list_task_push_notification_config_info_with_config_and_no_id():
12971393

12981394
assert len(result) == 1
12991395
assert result[0].taskId == 'task_1'
1300-
assert result[0].pushNotificationConfig.url == push_config.url
1396+
assert (
1397+
result[0].pushNotificationConfig.url
1398+
== set_config_params2.pushNotificationConfig.url
1399+
)
13011400
assert result[0].pushNotificationConfig.id == 'task_1'
13021401

13031402

@@ -1391,7 +1490,7 @@ async def test_delete_task_push_notification_config_info_with_config():
13911490
"""Test on_list_task_push_notification_config with push config+id"""
13921491
mock_task_store = AsyncMock(spec=TaskStore)
13931492

1394-
sample_task = create_sample_task(task_id='task_info_not_found')
1493+
sample_task = create_sample_task(task_id='non_existent_task')
13951494
mock_task_store.get.return_value = sample_task
13961495

13971496
push_config1 = PushNotificationConfig(
@@ -1436,7 +1535,7 @@ async def test_delete_task_push_notification_config_info_with_config_and_no_id()
14361535
"""Test on_list_task_push_notification_config with no push config id"""
14371536
mock_task_store = AsyncMock(spec=TaskStore)
14381537

1439-
sample_task = create_sample_task(task_id='task_info_not_found')
1538+
sample_task = create_sample_task(task_id='non_existent_task')
14401539
mock_task_store.get.return_value = sample_task
14411540

14421541
push_config = PushNotificationConfig(url='http://example.com')

0 commit comments

Comments
 (0)