@@ -26,9 +26,9 @@ def create_sample_task(task_id='task123', status_state=TaskState.completed):
2626
2727
2828def create_sample_push_config (
29- url = 'http://example.com/callback' , config_id = 'cfg1'
29+ url = 'http://example.com/callback' , config_id = 'cfg1' , token = None
3030):
31- return PushNotificationConfig (id = config_id , url = url )
31+ return PushNotificationConfig (id = config_id , url = url , token = token )
3232
3333
3434class TestInMemoryPushNotifier (unittest .IsolatedAsyncioTestCase ):
@@ -158,6 +158,35 @@ async def test_send_notification_success(self):
158158 ) # auth is not passed by current implementation
159159 mock_response .raise_for_status .assert_called_once ()
160160
161+ async def test_send_notification_with_token_success (self ):
162+ task_id = 'task_send_success'
163+ task_data = create_sample_task (task_id = task_id )
164+ config = create_sample_push_config (url = 'http://notify.me/here' , token = 'unique_token' )
165+ await self .config_store .set_info (task_id , config )
166+
167+ # Mock the post call to simulate success
168+ mock_response = AsyncMock (spec = httpx .Response )
169+ mock_response .status_code = 200
170+ self .mock_httpx_client .post .return_value = mock_response
171+
172+ await self .notifier .send_notification (task_data ) # Pass only task_data
173+
174+ self .mock_httpx_client .post .assert_awaited_once ()
175+ called_args , called_kwargs = self .mock_httpx_client .post .call_args
176+ self .assertEqual (called_args [0 ], config .url )
177+ self .assertEqual (
178+ called_kwargs ['json' ],
179+ task_data .model_dump (mode = 'json' , exclude_none = True ),
180+ )
181+ self .assertEqual (
182+ called_kwargs ['headers' ],
183+ {"X-A2A-Notification-Token" : "unique_token" },
184+ )
185+ self .assertNotIn (
186+ 'auth' , called_kwargs
187+ ) # auth is not passed by current implementation
188+ mock_response .raise_for_status .assert_called_once ()
189+
161190 async def test_send_notification_no_config (self ):
162191 task_id = 'task_send_no_config'
163192 task_data = create_sample_task (task_id = task_id )
0 commit comments