MCPcopy
hub / github.com/openai/openai-python / test_token_provider_refresh_sync

Function test_token_provider_refresh_sync

tests/lib/test_bedrock.py:325–344  ·  view source on GitHub ↗
(respx_mock: MockRouter)

Source from the content-addressed store, hash-verified

323
324@pytest.mark.respx()
325def test_token_provider_refresh_sync(respx_mock: MockRouter) -> None:
326 respx_mock.post("https://example.com/openai/v1/responses").mock(
327 side_effect=[
328 httpx.Response(500, json={"error": "server error"}),
329 httpx.Response(200, json=RESPONSE_BODY),
330 ]
331 )
332 tokens = iter(["first", "second"])
333 client = BedrockOpenAI(
334 base_url="https://example.com/openai/v1",
335 bedrock_token_provider=lambda: next(tokens),
336 http_client=httpx.Client(trust_env=False),
337 max_retries=1,
338 )
339
340 client.responses.create(model="gpt-4o", input="hello")
341
342 calls = cast("list[MockRequestCall]", respx_mock.calls)
343 assert calls[0].request.headers["Authorization"] == "Bearer first"
344 assert calls[1].request.headers["Authorization"] == "Bearer second"
345
346
347@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 3

BedrockOpenAIClass · 0.90
postMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected