11import logging
2-
2+ from collections . abc import Awaitable , Callable
33from typing import Any
44from unittest .mock import MagicMock
55
66import pytest
7-
87from fastapi import FastAPI
98from google .protobuf import json_format
109from httpx import ASGITransport , AsyncClient
1312from a2a .server .apps .rest import fastapi_app , rest_adapter
1413from a2a .server .apps .rest .fastapi_app import A2ARESTFastAPIApplication
1514from a2a .server .apps .rest .rest_adapter import RESTAdapter
15+ from a2a .server .context import ServerCallContext
1616from a2a .server .request_handlers .request_handler import RequestHandler
1717from a2a .types import (
1818 AgentCard ,
2525 TextPart ,
2626)
2727
28-
2928logger = logging .getLogger (__name__ )
3029
3130
3231@pytest .fixture
3332async def agent_card () -> AgentCard :
3433 mock_agent_card = MagicMock (spec = AgentCard )
3534 mock_agent_card .url = 'http://mockurl.com'
36- mock_agent_card .supports_authenticated_extended_card = False
35+ mock_agent_card .supports_authenticated_extended_card = True
3736
3837 # Mock the capabilities object with streaming disabled
3938 mock_capabilities = MagicMock ()
@@ -58,6 +57,15 @@ async def streaming_agent_card() -> AgentCard:
5857 return mock_agent_card
5958
6059
60+ @pytest .fixture
61+ async def extended_card_modifier () -> Callable [
62+ [AgentCard , ServerCallContext ], Awaitable [AgentCard ]
63+ ]:
64+ return MagicMock (
65+ spec = Callable [[AgentCard , ServerCallContext ], Awaitable [AgentCard ]]
66+ )
67+
68+
6169@pytest .fixture
6270async def request_handler () -> RequestHandler :
6371 return MagicMock (spec = RequestHandler )
@@ -84,13 +92,20 @@ async def streaming_client(streaming_app: FastAPI) -> AsyncClient:
8492
8593@pytest .fixture
8694async def app (
87- agent_card : AgentCard , request_handler : RequestHandler
95+ agent_card : AgentCard ,
96+ request_handler : RequestHandler ,
97+ extended_card_modifier : Callable [
98+ [AgentCard , ServerCallContext ], Awaitable [AgentCard ]
99+ ],
88100) -> FastAPI :
89101 """Builds the FastAPI application for testing."""
90102
91- return A2ARESTFastAPIApplication (agent_card , request_handler ).build (
92- agent_card_url = '/well-known/agent.json' , rpc_url = ''
93- )
103+ return A2ARESTFastAPIApplication (
104+ agent_card ,
105+ request_handler ,
106+ extended_agent_card = agent_card ,
107+ extended_card_modifier = extended_card_modifier ,
108+ ).build (agent_card_url = '/well-known/agent.json' , rpc_url = '' )
94109
95110
96111@pytest .fixture
0 commit comments