test: inject the SDK's own transport in the sync batch list test so it passes on OpenAI SDK 3.x

This commit is contained in:
mateo-berri 2026-10-30 20:46:46 -07:00
parent 4d4cec65b8
commit a82bc4d239

View file

@ -2053,36 +2053,39 @@ def test_openai_config_hoists_a_later_developer_message_only_for_a_model_off_ope
@pytest.mark.asyncio
async def test_sync_batch_list_given_an_async_client_returns_a_page_the_caller_can_await(
respx_mock: respx.MockRouter,
http_backend: ModuleType,
):
respx_mock.get("http://vllm-router.test/v1/batches").respond(
200,
json={
"object": "list",
"data": [
{
"id": "batch_5f8dac",
"status": "pending",
"input_file_id": "file-b73f4c",
"created_at": 1793239207,
"endpoint": "/v1/chat/completions",
"completion_window": "24h",
}
],
"first_id": "batch_5f8dac",
"last_id": "batch_5f8dac",
"has_more": False,
},
)
def respond(request: _Request) -> httpx.Response | SDKResponse:
assert str(request.url).startswith("http://vllm-router.test/v1/batches")
return http_backend.Response(
200,
json={
"object": "list",
"data": [
{
"id": "batch_5f8dac",
"status": "pending",
"input_file_id": "file-b73f4c",
"created_at": 1793239207,
"endpoint": "/v1/chat/completions",
"completion_window": "24h",
}
],
"first_id": "batch_5f8dac",
"last_id": "batch_5f8dac",
"has_more": False,
},
)
page: Final = OpenAIBatchesAPI().list_batches(
_is_async=False,
api_key="sk-test",
api_base="http://vllm-router.test/v1",
timeout=5.0,
max_retries=0,
organization=None,
client=AsyncOpenAI(api_key="sk-test", base_url="http://vllm-router.test/v1"),
)
async with http_backend.AsyncClient(transport=http_backend.MockTransport(respond)) as http_client:
page: Final = OpenAIBatchesAPI().list_batches(
_is_async=False,
api_key="sk-test",
api_base="http://vllm-router.test/v1",
timeout=5.0,
max_retries=0,
organization=None,
client=AsyncOpenAI(api_key="sk-test", base_url="http://vllm-router.test/v1", http_client=http_client),
)
assert [(batch.id, batch.status) for batch in (await page).data] == [("batch_5f8dac", "pending")]
assert [(batch.id, batch.status) for batch in (await page).data] == [("batch_5f8dac", "pending")]